From 3b68da77aa1d3bad6140cd55118f4fb57c4b53cf Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Tue, 9 Feb 2021 18:47:27 +0100 Subject: [PATCH 1/5] make shellcheck happy and randomise mac address --- bootstrap | 18 +++++++++++++++--- mk_pbp_img | 12 ++++++++---- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/bootstrap b/bootstrap index a2d57ba..4e9c04d 100755 --- a/bootstrap +++ b/bootstrap @@ -26,12 +26,16 @@ get_value() { secure="s" fi + # shellcheck source=/dev/null . "$CONFIG" + if [ -z "${!var_name}" ]; then local def_val="${default_values[$var_name]}" read -${secure}rp "$white$prompt [$def_val]:$nocolour " value echo "export $var_name=\"${value:-$def_val}\"" >> "$CONFIG" + + # shellcheck source=/dev/null . "$CONFIG" fi @@ -147,7 +151,9 @@ set_fstab() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - local boot_uuid="$(blkid | grep ${install_dev}p1 | awk '{print $2}')" + local boot_uuid + boot_uuid="$(blkid | grep "${install_dev}p1" | awk '{print $2}')" + cat >/mnt/etc/fstab </dev/null | hexdump -v -e '/1 " %02X"' | tr '[:upper:]' '[:lower:]')" + + local root_uuid + root_uuid="$(blkid | grep "${install_dev}p2" | awk '{print $2}' | sed 's/"//g')" + + sed -i "s/setenv macaddr.*/setenv macadr $mac/g" "$boot_txt" sed -i "s|root=PARTUUID=|root=/dev/void/root rd.auto=1 cryptdevice=${root_uuid}:lvm|g" "$boot_txt" cp "$boot_txt" "$boot_txt_mine" @@ -350,7 +362,7 @@ cmd_loop() { while [[ "$cmd" != "exit" ]]; do read -rp "${white}>$nocolour " cmd - if [[ " ${commands[@]} " =~ " ${cmd} " ]]; then + if [[ "${commands[*]}" == *"${cmd}"* ]]; then $cmd else if [ "$cmd" != "exit" ]; then diff --git a/mk_pbp_img b/mk_pbp_img index c5b6267..4c9111a 100755 --- a/mk_pbp_img +++ b/mk_pbp_img @@ -28,7 +28,7 @@ cleanup_mounts() { } check_tools() { - for tool in ${TOOLS[@]}; do + for tool in "${TOOLS[@]}"; do if ! command -v "$tool" &> /dev/null then echo "$tool could not be found" @@ -65,8 +65,12 @@ build_img() { sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup" -o "$platformfs_file" pinebookpro "$rootfs_file" sudo ./mkimage.sh -B 256MiB -o "$img" "$platformfs_file" + # shellcheck disable=SC2024 + # it is correct that the decompressed image is written as the unprivileged user sudo xz --decompress --stdout "$img.xz" > "$img" - local loop_dev="$(sudo losetup --show -f -P "$img")" + + local loop_dev + loop_dev="$(sudo losetup --show -f -P "$img")" sudo mount "$loop_dev"p2 "$TMP_DIR_MOUNT" sudo mount "$loop_dev"p1 "$TMP_DIR_MOUNT"/boot @@ -84,9 +88,9 @@ EOT cleanup_mounts mkdir -p "$OUT_DIR" - xz --threads=0 --compress --stdout "$img" > "$OUT_DIR/$(basename $img.xz)" + xz --threads=0 --compress --stdout "$img" > "$OUT_DIR/$(basename "$img.xz")" - echo "built pinebookpro image: $OUT_DIR/$(basename $img.xz)" + echo "built pinebookpro image: $OUT_DIR/$(basename "$img.xz")" } trap cleanup 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM From 511bed496e2f1d691e1c78414da5932396c8e285 Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Tue, 9 Feb 2021 19:26:33 +0100 Subject: [PATCH 2/5] clarify some stuff in the readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 468b216..b55d5df 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ do and to be sure to backup all important data. Pre-built images can be downloaded from the [releases](https://code.vanwa.ch/sebastian/void-linux-installer/-/releases) page (those might be outdated though). -User and password for the live image are the standard void linux one (`root/voidlinux`). +User and password for the live image are the standard void linux ones (`root/voidlinux`). # Scripts ## mk_pbp_img @@ -61,7 +61,7 @@ If booting from the card hangs, write the image again onto it or use a different Install void linux to the internal mmc storage of the pinebook pro or use it for some maintenance task. -Be aware that the time needs to be set in *UTC*, otherwise package installation might not work. +Be aware that the time needs to be set in ***UTC**, otherwise package installation might not work. If running on a pinebook pro with an ISO keyboard, run `loadkeys uk` to load the correct keymap. @@ -80,7 +80,7 @@ Runs the `full_install` command internally. Run `help` to get a list of commands you can run and quit interactive mode with typing `exit`. -A useful thing to do here is the `repair` command. Sets up all the needed filesystems +A useful thing to do here is the `repair` command. It sets up all the needed filesystems and opens a chroot. Again, it is highly recommended to read what the respective commands do and to adapt From 6a3cecda843277d2a05260dc9a126c520dcc433e Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Wed, 10 Feb 2021 21:09:50 +0100 Subject: [PATCH 3/5] clean up everything correctly --- bootstrap | 54 +++++++++++++++++++++++++++++++++++++++++++----------- mk_pbp_img | 7 ++++--- 2 files changed, 47 insertions(+), 14 deletions(-) diff --git a/bootstrap b/bootstrap index 4e9c04d..c2689a5 100755 --- a/bootstrap +++ b/bootstrap @@ -49,13 +49,15 @@ network() { ip link set "$wifi_if" up + nmcli device wifi list + local wifi_ssid wifi_ssid="$(get_value "wifi_ssid" "wifi ssid")" local wifi_pw wifi_pw="$(get_value "wifi_pw" "wifi password" 1)" - wpa_supplicant -B -i "$wifi_if" -c <(wpa_passphrase "$wifi_ssid" "$wifi_pw") - sv restart dhcpcd + nmcli con delete "$wifi_ssid" || true + nmcli device wifi connect "$wifi_ssid" password "$wifi_pw" } datetime() { @@ -97,7 +99,10 @@ open_luks() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - cryptsetup open "$install_dev"p2 void + + if ! dmsetup ls | grep "void\s"; then + cryptsetup open "$install_dev"p2 void + fi } create_lvm() { @@ -117,15 +122,38 @@ make_filesystems() { mkfs.xfs -f -L ROOT /dev/void/root } +ensure_mount() { + local src="$1" + local dest="$2" + local with_rbind="$3" + + local rbind="" + + if [ ! -z "$with_rbind" ]; then + rbind="--rbind" + fi + + if grep -qs "$dest " /proc/mounts; then + mount "$rbind" "$src" "$dest" + + if [ ! -z "$with_rbind"]; then + mount --make-rslave "$dest" + fi + fi +} + mount_filesystems() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - mount /dev/void/root /mnt - mkdir -p /mnt/boot - mount "$install_dev"p1 /mnt/boot + ensure_mount "/dev/void/root" "/mnt" - swapon /dev/void/swap + mkdir -p /mnt/boot + ensure_mount "$install_dev"p1 "/mnt/boot" + + if [ "$(cat /proc/swaps | wc -l)" == 1 ]; then + swapon /dev/void/swap + fi } install_basesystem() { @@ -141,10 +169,10 @@ EOF } mount_special_filesystems() { - mount --rbind /sys /mnt/sys && mount --make-rslave /mnt/sys - mount --rbind /dev /mnt/dev && mount --make-rslave /mnt/dev - mount --rbind /proc /mnt/proc && mount --make-rslave /mnt/proc - mount --rbind /tmp /mnt/tmp && mount --make-rslave /mnt/tmp + ensure_mount "/sys" "/mnt/sys" 1 + ensure_mount "/dev" "/mnt/dev" 1 + ensure_mount "/proc" "/mnt/proc" 1 + ensure_mount "/tmp" "/mnt/tmp" 1 } set_fstab() { @@ -275,6 +303,10 @@ EOF tidy_up() { umount -R /mnt + lvchange -an void/root + lvchange -an void/swap + vgchange -an void + cryptsetup close void } full_install() { diff --git a/mk_pbp_img b/mk_pbp_img index 4c9111a..d05f062 100755 --- a/mk_pbp_img +++ b/mk_pbp_img @@ -62,8 +62,8 @@ build_img() { cd "$GIT_DIR" sudo ./mkrootfs.sh -o "$rootfs_file" aarch64 - sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup" -o "$platformfs_file" pinebookpro "$rootfs_file" - sudo ./mkimage.sh -B 256MiB -o "$img" "$platformfs_file" + sudo ./mkplatformfs.sh -p "dracut lvm2 cryptsetup dbus NetworkManager" -o "$platformfs_file" pinebookpro "$rootfs_file" + sudo ./mkimage.sh -B 256MiB -s 3GB -o "$img" "$platformfs_file" # shellcheck disable=SC2024 # it is correct that the decompressed image is written as the unprivileged user @@ -81,7 +81,8 @@ build_img() { sudo cp "$(which qemu-aarch64-static)" "$TMP_DIR_MOUNT/usr/bin/" sudo chroot "$TMP_DIR_MOUNT" qemu-aarch64-static /bin/bash <<"EOT" -ln -s /etc/sv/dhcpcd /etc/runit/runsvdir/default/ +ln -s /etc/sv/dbus /etc/runit/runsvdir/default/ +ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/ EOT sudo rm "$TMP_DIR_MOUNT/usr/bin/qemu-aarch64-static" From 46be773a1d2bcb30d1754060ceeef30ef0ec546e Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 11 Feb 2021 00:45:29 +0100 Subject: [PATCH 4/5] clean up everything correctly --- bootstrap | 37 +++++++++++++++++++------------------ mk_pbp_img | 1 + 2 files changed, 20 insertions(+), 18 deletions(-) diff --git a/bootstrap b/bootstrap index c2689a5..0a961e3 100755 --- a/bootstrap +++ b/bootstrap @@ -99,10 +99,7 @@ open_luks() { local install_dev install_dev="$(get_value "install_dev" "installation device")" - - if ! dmsetup ls | grep "void\s"; then - cryptsetup open "$install_dev"p2 void - fi + cryptsetup open "$install_dev"p2 void } create_lvm() { @@ -133,12 +130,10 @@ ensure_mount() { rbind="--rbind" fi - if grep -qs "$dest " /proc/mounts; then - mount "$rbind" "$src" "$dest" + mount $rbind "$src" "$dest" - if [ ! -z "$with_rbind"]; then - mount --make-rslave "$dest" - fi + if [ ! -z "$with_rbind" ]; then + mount --make-rslave "$dest" fi } @@ -151,9 +146,7 @@ mount_filesystems() { mkdir -p /mnt/boot ensure_mount "$install_dev"p1 "/mnt/boot" - if [ "$(cat /proc/swaps | wc -l)" == 1 ]; then - swapon /dev/void/swap - fi + swapon /dev/void/swap } install_basesystem() { @@ -245,7 +238,7 @@ set_base_conf() { local locale locale="$(get_value "locale" "locale")" - echo "$locale" >> /etc/default/libc-locales + echo "$locale" >> /mnt/etc/default/libc-locales chroot /mnt /bin/env -i \ timezone="$timezone" \ @@ -302,11 +295,17 @@ EOF } tidy_up() { - umount -R /mnt - lvchange -an void/root - lvchange -an void/swap - vgchange -an void - cryptsetup close void + sync + + if grep -qe "/mnt " /proc/mounts; then + umount -R /mnt + fi + + swapoff /dev/void/swap > /dev/null 2>&1 || true + + vgchange --activate n + + cryptsetup close void > /dev/null 2>&1 || true } full_install() { @@ -404,6 +403,8 @@ cmd_loop() { done } +trap tidy_up 0 SIGHUP SIGINT SIGQUIT SIGABRT SIGTERM + if [ "$1" == "full" ]; then full_install else diff --git a/mk_pbp_img b/mk_pbp_img index d05f062..e3fd8d9 100755 --- a/mk_pbp_img +++ b/mk_pbp_img @@ -83,6 +83,7 @@ build_img() { sudo chroot "$TMP_DIR_MOUNT" qemu-aarch64-static /bin/bash <<"EOT" ln -s /etc/sv/dbus /etc/runit/runsvdir/default/ ln -s /etc/sv/NetworkManager /etc/runit/runsvdir/default/ +ln -s /etc/sv/sshd /etc/runit/runsvdir/default/ EOT sudo rm "$TMP_DIR_MOUNT/usr/bin/qemu-aarch64-static" From d8b71f3ed50b5ba14b7fa06a0f3e657ab460062b Mon Sep 17 00:00:00 2001 From: Sebastian Hugentobler Date: Thu, 28 Mar 2024 16:05:46 +0100 Subject: [PATCH 5/5] add unmaintained note --- README.md | 95 +++++++++++++++++++++++++++++++++---------------------- bootstrap | 2 +- 2 files changed, 58 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index b55d5df..c87aa19 100644 --- a/README.md +++ b/README.md @@ -1,37 +1,49 @@ +# UNMAINTAINED + +I no longer use void linux, excellent distribution that it is. + # Install Scripts for Void Linux on Pinebook Pro + Before using either of the scripts in this repository, read through them to clearly understand what they do. They are very opinionated and specifically -written to cater to my own needs (for example the use of `sudo`, other people +written to cater to my own needs (for example the use of `sudo`, other people might have different setups). It is, however, easy to change things around. -By default, the `bootstrap` script creates a minimal installation on the emmc storage, -with full disk encryption (with an unencrypted boot partition) via lvm on luks. Two volumes `swap` and `root` are created, -the latter is formatted with an xfs filesystem. Additionally one user is created -(with access to sudo via the wheel group) and keymap, hostname and timezone get set. +By default, the `bootstrap` script creates a minimal installation on the emmc +storage, with full disk encryption (with an unencrypted boot partition) via lvm +on luks. Two volumes `swap` and `root` are created, the latter is formatted with +an xfs filesystem. Additionally one user is created (with access to sudo via the +wheel group) and keymap, hostname and timezone get set. -This gets you to a booting system, going on from there is out of scope here -as there are many ways to do that (for myself, I use `stow` to set up everything). +This gets you to a booting system, going on from there is out of scope here as +there are many ways to do that (for myself, I use `stow` to set up everything). -An important thing to keep in mind is that not all commands in the `bootstrap` -script are idempotent, that makes it all the more important to understand what they -do and to be sure to backup all important data. +An important thing to keep in mind is that not all commands in the `bootstrap` +script are idempotent, that makes it all the more important to understand what +they do and to be sure to backup all important data. -Pre-built images can be downloaded from the [releases](https://code.vanwa.ch/sebastian/void-linux-installer/-/releases) page +Pre-built images can be downloaded from the +[releases](https://code.vanwa.ch/sebastian/void-linux-installer/-/releases) page (those might be outdated though). -User and password for the live image are the standard void linux ones (`root/voidlinux`). +User and password for the live image are the standard void linux ones +(`root/voidlinux`). # Scripts + ## mk_pbp_img -Create a live image to boot void linux on the pinebook pro. Needs to be run on an -existing void linux system (docker might be possible with a working buildx and some adaptions with the mounting of filesystems). + +Create a live image to boot void linux on the pinebook pro. Needs to be run on +an existing void linux system (docker might be possible with a working buildx +and some adaptions with the mounting of filesystems). A copy of the [void-mklive](https://github.com/void-linux/void-mklive.git) repository is downloaded next to the script into `.void-mklive` and used for -building the image. +building the image. -The script assumes it is running on an `x86_64` architecture, if that is not the case, -it needs to be changed (this applies to the use of `qemu-aarch64-static` to get a chroot). +The script assumes it is running on an `x86_64` architecture, if that is not the +case, it needs to be changed (this applies to the use of `qemu-aarch64-static` +to get a chroot). The following tools need to be accessible in `PATH`: @@ -41,33 +53,40 @@ The following tools need to be accessible in `PATH`: - sudo - xz -If there is an argument provided to the script, it is treated as the folder to where -the compressed image is written, if no argument is given, the current working -directory is used. +If there is an argument provided to the script, it is treated as the folder to +where the compressed image is written, if no argument is given, the current +working directory is used. -After a successful build, the finished image can be found in the directory described -above with a filename of `void-pbp.img.xz` +After a successful build, the finished image can be found in the directory +described above with a filename of `void-pbp.img.xz` + +Write it to a microSD card as such: -Write it to a microSD card as such: - `xz -d < void-pbp.img.xz | sudo dd of=/dev/mmcblk0 bs=4M status=progress` - `sudo sync` - -Be ***very*** careful to get the parameter for `of` right, otherwise you can destroy your system. -MicroSD cards can be fickle, it sometimes is helpful to not take them out immediately, even after running `sync`. -If booting from the card hangs, write the image again onto it or use a different card. +Be **_very_** careful to get the parameter for `of` right, otherwise you can +destroy your system. + +MicroSD cards can be fickle, it sometimes is helpful to not take them out +immediately, even after running `sync`. If booting from the card hangs, write +the image again onto it or use a different card. ## bootstrap -Install void linux to the internal mmc storage of the pinebook pro or use it for some -maintenance task. -Be aware that the time needs to be set in ***UTC**, otherwise package installation might not work. +Install void linux to the internal mmc storage of the pinebook pro or use it for +some maintenance task. -If running on a pinebook pro with an ISO keyboard, run `loadkeys uk` to load the correct keymap. +Be aware that the time needs to be set in **\*UTC**, otherwise package +installation might not work. + +If running on a pinebook pro with an ISO keyboard, run `loadkeys uk` to load the +correct keymap. Run it in either of two ways: ### non-interactive + `bootstrap full` Run a full installation, this will overwrite all data on the storage. @@ -75,14 +94,14 @@ Run a full installation, this will overwrite all data on the storage. Runs the `full_install` command internally. ### interactive + `bootstrap` -Run `help` to get a list of commands you can run and quit interactive mode -with typing `exit`. +Run `help` to get a list of commands you can run and quit interactive mode with +typing `exit`. -A useful thing to do here is the `repair` command. It sets up all the needed filesystems -and opens a chroot. - -Again, it is highly recommended to read what the respective commands do and to adapt -them to your own needs. +A useful thing to do here is the `repair` command. It sets up all the needed +filesystems and opens a chroot. +Again, it is highly recommended to read what the respective commands do and to +adapt them to your own needs. diff --git a/bootstrap b/bootstrap index 0a961e3..7d30c83 100755 --- a/bootstrap +++ b/bootstrap @@ -106,7 +106,7 @@ create_lvm() { pvcreate /dev/mapper/void vgcreate void /dev/mapper/void - lvcreate -L 4G void -n swap + lvcreate -L 48G void -n swap lvcreate -l 100%FREE void -n root }