Commit 96ae8252 authored by ZappeL's avatar ZappeL
Browse files

Initial commit

parents
# rpi4-aarch64-gentoo
Raspberry Pi 4 (aarch64) gentoo buildchain with SD-Card creation.
## Working live on a SD-Card
### 'setup.sh' uses SD-Card (incl. partitioning)
```bash
cd /your/prefered/location
git clone https://git.complex-co.de/armas/rpi4-aarch64-gentoo
./rpi4-aarch64-gentoo/setup.sh /dev/sdX
```
## Working on a local filesystem
### 'setup.sh' dummy-mode
```bash
cd /your/prefered/location
git clone https://git.complex-co.de/armas/rpi4-aarch64-gentoo
./rpi4-aarch64-gentoo/setup.sh -d
```
### (Experimental) Gentoo chroot
#### Requirements
Make sure that qemu was build with USE="static-user" and QEMU_USER_TARGETS="aarch64", otherwsie the qemu-aarch64 binary is not compatible with the libs inside chroot. The second thing you'll need is "app-misc/pax-utils" build inside chroot with USE="-seccomp", otherwise qemu-user will stall on syscall errors. Here is a configuration example (on host):
```bash
/etc/portage/make.conf:
QEMU_SOFTMMU_TARGETS="aarch64 [...]"
QEMU_USER_TARGETS="aarch64 [...]"
/etc/portage/package.use/qemu:
app-emulation/qemu static-user
dev-libs/glib static-libs
sys-apps/attr static-libs
dev-libs/libpcre static-libs
emerge -a app-emulation/qemu
```
#### Example
```bash
(host)$ cd /your/prefered/location
(default, using SD-Card):
(host)$ ./rpi4-aarch64-gentoo/chroot.sh /dev/sdX -e
(local filesystem, no SD-Card):
(host)$ ./rpi4-aarch64-gentoo/chroot.sh -e
inside chroot:
(chroot)$ ex_initial_setup
(chroot)$ exit
```
## Sampels
### Rebuilding/configuring the kernel
```bash
cd /your/prefered/location/
./rpi4-aarch64-gentoo/mount_sd.sh /dev/sdX
./rpi4-aarch64-gentoo/prepare_kernel.sh
./rpi4-aarch64-gentoo/mount_sd.sh /dev/sdX -u
```
### Entering chroot
```sh
cd /your/prefered/location
(default, using SD-Card):
./rpi4-aarch64-gentoo/chroot.sh /dev/sdX -e
(local filesystem, no SD-Card):
./rpi4-aarch64-gentoo/chroot.sh -e
```
### SD-Card partition layout
```sh
/dev/sdX1 - boot (type 0x0c - vfat) - contains the kernel image and firmware
/dev/sdX2 - root (type 0x83 - ext4) - root-filesystem
/dev/sdX3 - swap (type 0x82 - swap) - swap
```
#!/bin/bash
## wrapper for chroot (and eventually initial setup)
cur_dir=$(dirname `readlink -f $0`)
ins_dir="${cur_dir}/../mnt/gentoo"
if [[ ! -d "${ins_dir}" ]]; then
${cur_dir}/setup.sh -d
fi
${cur_dir}/scripts/chroot.sh $@
#!/bin/bash
### HEAD ###
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
elif [[ -z $1 ]]; then
echo -e "Sorry no build_root, giving up."
exit 3
fi
ex_name="ex_gcc_upgrade"
ex_dscr="Upgrade gcc extension."
ex_help="No Help available"
chroot_rc=$1/etc/bash/bashrc.d/chroot.sh
### MAIN ###
if [[ -f ${chroot_rc} ]]; then
echo -e "
ex_gcc_upgrade() {
echo -e \"installing gcc...\"
emerge -1O sys-devel/gcc
gcc-config -f 2
env-update && . /etc/profile
emerge -1O sys-devel/libtool
echo -e \"removing old gcc...\"
emerge --ask --depclean =sys-devel/gcc-4.9.4
}\n" >> ${chroot_rc}
fi
# hint, next should be:
# $ perl-cleaner --all (not sure about this)
# $ emerge gentoolkit
# -- upgrade python
# -- switch profile to systemd and emerge -NDua @world
# -- recompile kernel and check parameters, (cpufreq, systemd)
# -- enable wifi/bt and make camera and Co. working
### FOOT ###
echo -e "${ex_name} loaded."
#!/bin/bash
### HEAD ###
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
elif [[ -z $1 ]]; then
echo -e "Sorry no build_root, giving up."
exit 3
fi
ex_name="ex_initial_setup"
ex_dscr="Setup extension."
ex_help="No Help available"
chroot_rc=$1/etc/bash/bashrc.d/chroot.sh
### MAIN ###
if [[ -f ${chroot_rc} ]]; then
echo -e "
make_conf_data=\"Q0ZMQUdTPSItbWFyY2g9YXJtdjgtYStjcmMgLW10dW5lPWNvcnRleC1hNTMgLWZ0cmVlLXZlY3Rvcml6ZSAtTzIgLXBpcGUgLWZvbWl0LWZyYW1lLXBvaW50ZXIiDQpDWFhGTEFHUz0iJHtDRkxBR1N9Ig0KQ0hPU1Q9ImFhcmNoNjQtdW5rbm93bi1saW51eC1nbnUiDQoNCk1BS0VPUFRTPSItajUiDQoNCkxJTkdVQVM9ImRlIiANCkwxME49IiR7TDEwTn0gJHtMSU5HVUFTfSINCkFDQ0VQVF9MSUNFTlNFPSIqIg0KQUNDRVBUX0tFWVdPUkRTPSJ+YXJtNjQiDQoNClVTRT0iLXNlY2NvbXAgLVgiDQoNClBPUlRESVI9Ii91c3IvcG9ydGFnZSINCkRJU1RESVI9Ii91c3IvcG9ydGFnZS9kaXN0ZmlsZXMiDQpQS0dESVI9Ii91c3IvcG9ydGFnZS9wYWNrYWdlcyINCg0KRU1FUkdFX0RFRkFVTFRfT1BUUz0iLS1sb2FkLWF2ZXJhZ2U9MTUgLS1hdXRvdW5tYXNrPW4gLS1xdWlldC1idWlsZD15IC0tY29tcGxldGUtZ3JhcGgiDQo=\"
ex_initial_setup() {
echo -e \"fixing make.conf...\"
echo \${make_conf_data} | base64 -d > /etc/portage/make.conf
echo -e \"creating portage dirs...\"
mkdir -p /etc/portage/package.{use,mask,keywords,unmask}
echo \"sys-apps/util-linux build -udev\" > /etc/portage/package.use/util-linux
echo -e \"fixing syscall-errors (this will take about 5 minutes to complete)...\"
(emerge -1O pax-utils &>/dev/null & emerge_pid=\$! && sleep 2m && kill -9 \${emerge_pid} &>/dev/null)
if [[ -d \"/var/tmp/portage/app-misc\" ]]; then
cp -a /var/tmp/portage/app-misc/pax-utils-*/image/* /
(emerge -1O pax-utils &>/dev/null)
fi
}\n" >> ${chroot_rc}
fi
### FOOT ###
echo -e "${ex_name} loaded."
#!/bin/bash
### HEAD ###
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
elif [[ -z $1 ]]; then
echo -e "Sorry no build_root, giving up."
exit 3
fi
ex_name="ex_kernel_build"
ex_dscr="Building the kernel."
ex_help="No Help available"
chroot_rc=$1/etc/bash/bashrc.d/chroot.sh
### MAIN ###
if [[ -f ${chroot_rc} ]]; then
echo -e "
ex_kernel_build() {
cd /usr/src/linux
make -s menuconfig
make -j\`nproc\` && make modules_install
cp arch/arm64/boot/Image /boot/kernel8.img
cp arch/arm64/boot/dts/broadcom/*.dtb /boot/
cp arch/arm64/boot/dts/overlays/* /boot/overlays
}\n" >> ${chroot_rc}
fi
### FOOT ###
echo -e "${ex_name} loaded."
#!/bin/bash
### HEAD ###
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
elif [[ -z $1 ]]; then
echo -e "Sorry no build_root, giving up."
exit 3
fi
ex_name="ex_test"
ex_dscr="Testing Extension, to run. just run in chroot: ex_test"
ex_help="Example Help for the Testing extension"
chroot_rc=$1/etc/bash/bashrc.d/chroot.sh
### MAIN ###
if [[ -f ${chroot_rc} ]]; then
echo -e "ex_test() {\n\techo \"this is a TEST\"\n}\n" >> ${chroot_rc}
fi
### FOOT ###
echo -e "${ex_name} loaded."
#!/bin/bash
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
fi
build_root=$(dirname `readlink -f $0`)/../../mnt/gentoo
echo -e "Fetching latest firmware..."
if [[ ! -d ${build_root}/boot ]]; then
echo -e "Please mount SD-Card."
exit 1
fi
wget -qq -O ${build_root}/boot/start4.elf \
https://github.com/raspberrypi/firmware/raw/stable/boot/start4.elf
wget -qq -O ${build_root}/boot/bootcode.bin \
https://github.com/raspberrypi/firmware/raw/stable/boot/bootcode.bin
wget -qq -O ${build_root}/boot/fixup4.dat \
https://github.com/raspberrypi/firmware/raw/stable/boot/fixup4.dat
# cmdline.txt
if [[ ! -f ${build_root}/boot/cmdline.txt ]]; then
echo -e "Patching boot/cmdline.txt..."
echo -e "root=/dev/mmcblk0p2 rootfstype=ext4 rootdelay=2 rootwait" \
> ${build_root}/boot/cmdline.txt
fi
# config.txt
if [[ ! -f ${build_root}/boot/config.txt ]]; then
echo -e "Patching boot/config.txt..."
echo -e "framebuffer_depth=24\nboot_delay=1" \
> ${build_root}/boot/config.txt
fi
exit 0
#!/bin/bash
## EXPERIMENTAL - Chroot into Raspberry
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
fi
script_root=$(dirname `readlink -f $0`)
build_root=$(dirname `readlink -f $0`)/../../mnt/gentoo
live_mode=0
live_dev=""
extensions=0
dots() {
local pid=$!
local delay=0.25
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
printf "."
sleep $delay
done
printf "\n"
}
if [[ -z `equery u app-emulation/qemu | grep +static-user` ]]; then
echo -e "Prerequirements (change use and rebuild app-emulation/qemu):
make.conf:
QEMU_SOFTMMU_TARGETS=\"aarch64 [...]\"
QEMU_USER_TARGETS=\"aarch64 [...]\"
general package use (/etc/portage/package/use/qemu):
app-emulation/qemu static-user
>=dev-libs/glib-2.52.3 static-libs
>=sys-apps/attr-2.4.47-r2 static-libs
>=dev-libs/libpcre-8.41 static-libs"
echo -e "\nPlease reinstall app-emulation/qemu with static-user flag and then rerun this script."
exit 1
fi
for var in "$@"; do
case ${var} in
"-e")
extensions=1
;;
*)
if [[ `file ${var}` == *"block"* ]]; then
live_mode=1
live_dev=${var}
elif [[ -d ${var} ]]; then
build_root=${var}
fi
;;
esac
done
if [[ ${live_mode} == 1 ]]; then
${script_root}/mount.sh "${live_dev}"
fi
echo -en "generating app-emulation/qemu package."
(quickpkg app-emulation/qemu &>/dev/null) & dots
echo -en "installing app-emulation/qemu in chroot."
(cd ${build_root} && ROOT=$PWD/ emerge --usepkgonly --oneshot --nodeps qemu &>/dev/null) & dots
echo -e "configuring qemu-wrapper..."
echo -e '#include <string.h>
#include <unistd.h>
int main(int argc, char **argv, char **envp) {
char *newargv[argc + 3];
newargv[0] = argv[0];
newargv[1] = "-cpu";
newargv[2] = "cortex-a8";
memcpy(&newargv[3], &argv[1], sizeof(*argv) * (argc - 1));
newargv[argc + 2] = NULL;
return execve("/usr/bin/qemu-arm", newargv, envp);
}' > /tmp/qemu-wrapper.c
gcc -static /tmp/qemu-wrapper.c -O3 -s -o ${build_root}/qemu-wrapper
rm /tmp/qemu-wrapper.c
echo -e "registering aarch64..."
[ -d /proc/sys/fs/binfmt_misc ] || modprobe binfmt_misc
[ -f /proc/sys/fs/binfmt_misc/register ] || mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc
echo ':qemu-aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/usr/bin/qemu-aarch64:' > /proc/sys/fs/binfmt_misc/register 2> /dev/null
echo ':aarch64:M::\x7fELF\x02\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\xb7:\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff:/usr/bin/qemu-aarch64:' > /proc/sys/fs/binfmt_misc/register 2> /dev/null
echo ':arm:M::\x7fELF\x01\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x02\x00\x28\x00:\xff\xff\xff\xff\xff\xff\xff\x00\xff\xff\xff\xff\xff\xff\xff\xff\xfe\xff\xff\xff:/qemu-wrapper:' > /proc/sys/fs/binfmt_misc/register 2> /dev/null
echo -e "mounting needed dependencies..."
mount --rbind /dev ${build_root}/dev
mount --make-rslave ${build_root}/dev
mount -t proc /proc ${build_root}/proc
mount --rbind /sys ${build_root}/sys
mount --make-rslave ${build_root}/sys
mount --rbind /tmp ${build_root}/tmp
cp /etc/resolv.conf ${build_root}/etc
echo "export PS1=\"(chroot) \$PS1\"" > ${build_root}/etc/bash/bashrc.d/chroot.sh
if [[ $extensions == 1 ]]; then
echo -e "**extensions are enabled**"
for ex in ${script_root}/../extensions/chroot/*.ex ; do
[[ -r ${ex} ]] && source "${ex}" "${build_root}"
done
fi
echo -e "chrooting..."
(cd ${build_root} && chroot . /bin/bash --login)
## file-cleanup
echo -e "cleaning things up..."
rm ${build_root}/etc/bash/bashrc.d/chroot.sh
rm ${build_root}/qemu-wrapper
## unmounting
(umount -fl ${build_root}/* &>/dev/null)
if [[ ${live_mode} == 1 ]]; then
${script_root}/mount.sh ${live_dev} -u
fi
exit 0
#!/bin/bash
if [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be executed as 'root', exit."
exit 2
fi
build_root=$(dirname `readlink -f $0`)/../../mnt
uri="http://distfiles.gentoo.org/experimental/arm64"
relType="systemd"
s3tarball=`wget -qO- ${uri} | grep -Po '(?<=href=")[^"]*\.bz2' | sort -r | grep -m1 stage3-arm64-${relType}`
dots() {
local pid=$!
local delay=0.25
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
printf "."
sleep $delay
done
printf "\n"
}
if [[ -z ${s3tarball} ]]; then
echo -e "Error, tarball not found!"
exit 1;
else
echo -e "Latest Stage3 is: ${s3tarball}"
if [[ -f "${build_root}/.latest_installed_stage3" ]]; then
ls3tarball=`cat "${build_root}/.latest_installed_stage3"`
echo -e "Latest used Stage3 is: ${s3tarball}"
fi
fi
## checking for stage3
if [[ -f "${build_root}/stage3.tar.bz2" ]]; then
echo -e "Found stage3 archive. Validating remote..."
osum=`curl -s ${uri}/${s3tarball}.DIGESTS | grep -m1 stage3 | awk '{print $1}'`
lsum=`sha512sum ${build_root}/stage3.tar.bz2 | awk '{print $1}'`
if [[ ${osum} != ${lsum} ]]; then
echo -e "Stage3 archive not valid to remote, deleting."
rm ${build_root}/stage3.tar.bz2
else
echo -e "Stage3 hash is verified successful."
fi
fi
# recheck for existence (could be removed above)
if [[ ! -f "${build_root}/stage3.tar.bz2" ]]; then
echo -en "Fetching latest stage3-tarball (arm64)."
(wget -qq -O ${build_root}/stage3.tar.bz2 ${uri}/${s3tarball}) & dots
fi
# unpacking tarball
# TODO: needs better check vor version (force?)
if [[ ! -f "${build_root}/.latest_installed_stage3" ]]; then
echo -en "Unpacking stage3-tarball (please wait)."
(tar -xjf ${build_root}/stage3.tar.bz2 -C ${build_root}/gentoo/) & dots
echo ${s3tarball} > "${build_root}/.latest_installed_stage3"
fi
## checking for portage..
osum=`curl -s http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2.md5sum | awk '{print $1}'`
if [[ -f "${build_root}/portage.tar.bz2" ]]; then
echo -e "Found portage archive. Validating remote..."
lsum=`md5sum ${build_root}/portage.tar.bz2 | awk '{print $1}'`
if [[ ${osum} != ${lsum} ]]; then
echo -e "Portage checksum mismatch, deleting."
rm ${build_root}/portage.tar.bz2
fi
fi
# recheck for existence (could be removed above)
if [[ ! -f "${build_root}/portage.tar.bz2" ]]; then
echo -en "Fetching portage tree."
(wget -qq -O ${build_root}/portage.tar.bz2 \
http://distfiles.gentoo.org/snapshots/portage-latest.tar.bz2) & dots
fi
lsum=`md5sum ${build_root}/portage.tar.bz2 | awk '{print $1}'`
if [[ ${osum} == ${lsum} ]]; then
echo -e "Portage archive hash successfully validated."
# unpacking tarball
echo -en "Unpacking portage (please wait)."
(tar -xjf ${build_root}/portage.tar.bz2 -C ${build_root}/gentoo/usr) & dots
fi
## patching..
echo -e "Patching fstab..."
echo -e \
"/dev/mmcblk0p1 /boot vfat noauto,noatime 1 2
/dev/mmcblk0p2 / ext4 noatime 0 1
/dev/mmcblk0p3 none swap sw 0 0"\
> ${build_root}/gentoo/etc/fstab
echo -e "Patching make.conf..."
cat ${build_root}/gentoo/etc/portage/make.conf | egrep -v "^(COMMON_FLAGS|#)"\
> ${build_root}/gentoo/etc/portage/make.conf_new
echo -e \
'COMMON_FLAGS="-march=armv8-a+crc -mtune=cortex-a72.cortex-a53 -ftree-vectorize -O2 -pipe -fomit-frame-pointer"' \
> ${build_root}/gentoo/etc/portage/make.conf
cat ${build_root}/gentoo/etc/portage/make.conf_new >> ${build_root}/gentoo/etc/portage/make.conf
rm ${build_root}/gentoo/etc/portage/make.conf_new
## root-password
## TODO: fix this!
# echo -e "Setting new root-password..."
# sed -i 's~root:\*~root:'"$(openssl passwd -1)"'~g' ${build_root}/gentoo/etc/shadow
## syncing
echo -en "Syncing filesystems (please wait)."
(sync) & dots
## info (if no $1 is set!)
if [[ -z $1 ]]; then
echo -e "Success! The rest must be configured manually.. :)\n\n"
fi
exit 0
#!/bin/bash
build_root=$(dirname `readlink -f $0`)/../../mnt
kernel_version="5.3"
newInst=0
makeJobs=`cat /proc/cpuinfo | grep processor | wc -l`
dots() {
local pid=$!
local delay=0.25
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
printf "."
sleep $delay
done
if [[ -z $1 ]]; then
printf "\n"
fi
}
if [[ -z "/usr/bin/aarch64-unknown-linux-gnu-gcc" ]]; then
echo -e "Crosscompiler toolchain (aarch64-unknown-linux-gnu) is missing!!!"
echo -e "\n[Gentoo example]:"
echo -e "$ emerge -a crossdev"
echo -e "$ crossdev --ov-output /usr/crossdev-overlay aarch64-unknown-linux-gnu"
echo -e "$ cd /usr/aarch64-unknown-linux-gnu/etc/portage && rm make.profile && ln -s /usr/portage/profiles/default/linux/arm64/17.0/desktop make.profile"
echo -e "\nPlease fix above issues and retry."
exit 1
fi
echo -en "Getting kernel sources via git."
if [[ ! -d "${build_root}/gentoo/usr/src/linux/.git" ]]; then
$(cd ${build_root}/gentoo/usr/src && git clone --depth 1 -b rpi-${kernel_version}.y git://github.com/raspberrypi/linux.git &>/dev/null) & dots
newInst=1
else
$(cd ${build_root}/gentoo/usr/src/linux && git pull >/dev/null 2>&1) & dots
fi
echo -e "Configuring kernel..."
cd ${build_root}/gentoo/usr/src/linux
if [[ ${newInst} == 1 ]]; then
make ARCH=arm64 CROSS_COMPILE=/usr/bin/aarch64-unknown-linux-gnu- -s bcm2711_defconfig &>/dev/null
else
make ARCH=arm64 CROSS_COMPILE=/usr/bin/aarch64-unknown-linux-gnu- -s menuconfig &>/dev/null
fi
echo -en "Building kernel and modules (please wait)."
(make ARCH=arm64 CROSS_COMPILE=/usr/bin/aarch64-unknown-linux-gnu- -j${makeJobs} &>/dev/null) & dots "n"
echo -n "M"
(make ARCH=arm64 CROSS_COMPILE=/usr/bin/aarch64-unknown-linux-gnu- modules_install INSTALL_MOD_PATH=${build_root}/gentoo/ &>/dev/null) & dots
cd $oPath
echo -e "Copying image files..."
cp ${build_root}/gentoo/usr/src/linux/arch/arm64/boot/Image ${build_root}/gentoo/boot/kernel8.img
echo -e "Fixing dtb's..."
cp ${build_root}/gentoo/usr/src/linux/arch/arm64/boot/dts/broadcom/bcm2711-rpi-4-b.dtb ${build_root}/gentoo/boot/
mkdir -p ${build_root}/gentoo/boot/overlays
cp ${build_root}/gentoo/usr/src/linux/arch/arm64/boot/dts/overlays/* ${build_root}/gentoo/boot/overlays
## syncing
echo -en "Syncing filesystems (please wait)."
(sync) & dots
echo -e "Finished!! \nNext step is booting the Pi!"
exit 0
#!/bin/bash
if [[ $# < 1 ]]; then
echo -e "usage: $0 /dev/sdX [-c|-d|-u]\n"
echo -e "Please specify device for mounting (e.g. /dev/sdX)"
echo -e "Partitiontable MUST look like this or use '-c' to create:"
echo -e "/dev/sdX1 - boot (type 0x0c - vfat)"
echo -e "/dev/sdX2 - root (type 0x83 - ext4)"
echo -e "/dev/sdX3 - swap (type 0x82 - swap)"
echo -e "-c\tcreate partition scheme"
echo -e "-d\tdummy mode (nothing is mounted)"
echo -e "-u\tunmount"
echo -e "Please try again, launching: '$0 /dev/sdX'"
exit 1
elif [[ ${EUID} != 0 ]] ; then
echo -e "Sorry, this script must be runned as 'root', exit."
exit 2
fi
## check if device exists
if [[ -z $1 && $2 != "-d" ]]; then
echo -e "Sorry, device '$1' does not exist, please retry."
exit 1
fi
dots() {
local pid=$!
local delay=0.25
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
printf "."
sleep $delay
done
printf "\n"
}
## device (/dev/sdX)
sdcard=$1
build_root=$(dirname `readlink -f $0`)/../../mnt/gentoo
## create partition scheme
if [[ $2 == "-c" ]]; then
## forcebly unmount device
umount ${sdcard}* &>/dev/null
device_sectors=`blockdev --getsize ${sdcard}`
device_bytes=`blockdev --getsize64 ${sdcard}`
device_gib_real=`echo "scale=2; $device_bytes/(1024^3)" | bc `
device_gib=`echo $device_gib_real | awk '{printf("%d\n",$1 + 0.5)}'`
# calculate swapsize
if [[ $device_gib -ge 30 ]]; then
swap_size=2048
elif [[ $device_gib -ge 16 ]]; then
swap_size=1024
else
swap_size=512
fi