From ffa322afdd31a21d13784e8387c6ec899b269782 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Sun, 22 Oct 2023 16:35:49 +0200 Subject: [PATCH 01/12] refactor(iso): Fewer packages needed in ISO (#7) --- setup.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.sh b/setup.sh index 5da1519..159e37f 100644 --- a/setup.sh +++ b/setup.sh @@ -756,7 +756,7 @@ function main () { set_ntp #1.2 resize_cow_space #1.3 update_pacman_db #1.4 - install_pkgs 'base-devel' 'git' 'jq' #1.5 + install_pkgs 'jq' #1.5 install_zfs #1.6 setup_zpool #1.7 mount_system #1.8 -- 2.47.2 From 73001c8e95b305aa9e00deddd4a90607a33c02f5 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 00:08:27 +0200 Subject: [PATCH 02/12] docs(iso): Differentiate between UEFI and legacy BIOS (#7) --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index a3ddb85..0118ace 100644 --- a/README.md +++ b/README.md @@ -6,14 +6,31 @@ Helper script to install Arch Linux with ZFSBootMenu from within a running Arch We expect minimal prep on your end. Please make sure that before execution the following conditions are met. +### UEFI + +On a UEFI system ensure these conditions are met. See [How to prep](#how-to-prep) for details on how to meet these conditions. + +- One GPT-partitioned disk - Arch Linux live CD ISO image sees exactly one partition with partition type code `BF00` ("Solaris root") - Arch Linux live CD ISO image sees exactly one partition with partition type code `EF00` ("EFI system partition") - The `EF00` EFI partition is mountable, in practical terms this usually only means it has a file system. - No ZFS zpool exists -### How to prep +### Legacy BIOS -On a blank example disk `/dev/sda` you can fulfill the requirements (One `EF00` partition with a file system plus one `BF00` partition) for example like so: +If you are instead running a legacy BIOS machine ensure these conditions are met. See [How to prep](#how-to-prep) for details on how to meet these conditions. + +- One MBR-partitioned disk +- Arch Linux live CD ISO image sees exactly one partition with partition type code `BF` ("Solaris root") +- Arch Linux live CD ISO image sees exactly one partition with partition type code `83` ("Linux") +- The `83` Linux partition is mountable, in practical terms this usually only means it has a file system. +- No ZFS zpool exists + +## How to prep + +### UEFI + +On a blank example disk `/dev/sda` you can fulfill the UEFI requirements (One `EF00` partition with a file system plus one `BF00` partition) for example like so: ``` sgdisk --new '1::+512M' --new '2' --typecode '1:EF00' --typecode '2:BF00' /dev/sda mkfs.vfat /dev/sda1 @@ -37,6 +54,28 @@ NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS └─/dev/sda2 202:2 0 9.5G 0 part ``` +### Legacy BIOS + +For a legacy BIOS machine you'll be using a master boot record (MBR) on your disk. +``` +printf -- '%s\n' 'label: dos' 'start=1MiB, size=512MiB, type=83, bootable' 'start=513MiB, size=+, type=bf' | sfdisk /dev/sda +mkfs.vfat /dev/sda1 +``` +> `label: dos`: Create the following partition layout in a master boot record. +> +> `start=1MiB, size=512MiB, type=83, bootable`: Partition 1 begins 1 Mebibyte after disk start and is 512 Mebibyte in size. We're setting its bootable flag and setting partition type code `83` ("Linux"). +> +> `start=513MiB, size=+, type=bf`: Partition 2 begins right at the start of Mebibyte 513, this is the very next sector after the end of partition 1. It takes up the remaining disk space, we're assigning type code `bf` ("Solaris"). + +The result will be something like this at which point you can start the `setup.sh` script, see [How to run this?](#how-to-run-this) below for more details. +``` +# lsblk --paths --output 'NAME,SIZE,FSTYPE,PARTTYPE,PARTTYPENAME,PTTYPE' /dev/sda +NAME SIZE FSTYPE PARTTYPE PARTTYPENAME PTTYPE +/dev/sda 10G dos +├─/dev/sda1 512M vfat 0x83 Linux dos +└─/dev/sda2 9.5G 0xbf Solaris dos +``` + ## ZFS dataset layout The script will create a single ZFS zpool `zpool` on the `BF00` partition with dataset child `zpool/root` which itself has one child `zpool/root/archlinux`, that's where Arch Linux gets installed. Parallel to `zpool/root` it'll create `zpool/data` with a `zpool/data/home` child dataset that gets mounted at `/home`. -- 2.47.2 From 3eee3cbe6b3e7c9496f107ec5769a5e39f204553 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 00:46:15 +0200 Subject: [PATCH 03/12] feat(iso): Crudely detect BIOS vs. UEFI intent (#7) --- setup.sh | 107 +++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 73 insertions(+), 34 deletions(-) diff --git a/setup.sh b/setup.sh index 159e37f..00199b4 100644 --- a/setup.sh +++ b/setup.sh @@ -24,11 +24,17 @@ declare zpool_name zfs_arch_dataset_name zpool_name='zpool' zfs_arch_dataset_name='archlinux' +declare -A partition_types +partition_types[gpt_zfs]='6a85cf4d-1dd2-11b2-99a6-080020736631' +partition_types[gpt_efi]='c12a7328-f81f-11d2-ba4b-00a0c93ec93b' +partition_types[mbr_zfs]='0xbf' +partition_types[mbr_boot]='0x83' + # https://unix.stackexchange.com/a/48550 set -E trap '[ "$?" -ne 77 ] || exit 77' ERR -declare zpool_drive efi_drive +declare zpool_drive efi_drive part_schema function we_are_changerooted () { if [ "$(stat -c '%d:%i' '/')" != "$(stat -c '%d:%i' '/proc/1/root/.')" ]; then @@ -38,23 +44,51 @@ function we_are_changerooted () { fi } -function no_kernel_update_in_iso () { +function uefi_or_bios () { #1.1 + local part_count_linux part_count_efi + # Select disks with at least one partition. Among them count how many + # with the given partition type code we have. + part_count_linux="$(get_partitions | jq --raw-output '[.[][] | select(.children | length > 0) | .children[] | select(.parttype=="'"${partition_types[mbr_boot]}"'") | .path] | length')" + part_count_efi="$(get_partitions | jq --raw-output '[.[][] | select(.children | length > 0) | .children[] | select(.parttype=="'"${partition_types[gpt_efi]}"'") | .path] | length')" + if [[ "${part_count_linux}" -eq '1' ]] && [[ "${part_count_efi}" -eq '0' ]]; then + part_schema='mbr' + >&3 printf -- '%s\n' \ + 'Treating this as an MBR/legacy BIOS machine ...' + elif [[ "${part_count_linux}" -eq '0' ]] && [[ "${part_count_efi}" -eq '1' ]]; then + part_schema='gpt' + >&3 printf -- '%s\n' \ + 'Treating this as a GPT/UEFI machine ...' + else + >&3 printf -- '%s\n' \ + 'We are seeing partitions as follows:' \ + '- Partition type code '"${partition_types[mbr_boot]}"': '"${part_count_linux}" \ + '- Partition type code '"${partition_types[gpt_efi]}"': '"${part_count_efi}" \ + '' \ + 'We are instead expecting either 1 and 0 indicating a legacy' \ + 'BIOS setup or 0 and 1 indicating UEFI. '"${part_count_linux}"' and '"${part_count_efi}"' is' \ + 'neither. Cowardly exiting ...' + exit 77 + fi +} + +function no_kernel_update_in_iso () { + #1.2 sed -ri -e 's'$'\x1''#(IgnorePkg)[^\r\n\f]+'$'\x1''\1 = linux linux-headers'$'\x1''g' /etc/pacman.conf } function set_ntp () { - #1.2 + #1.3 timedatectl set-ntp true } function resize_cow_space () { - #1.3 + #1.4 mount -o remount,size='50%' /run/archiso/cowspace } function update_pacman_db () { - #1.4 + #1.5 printf -- '%s\n' 'Refreshing mirror list ...' systemctl start reflector # In an ISO and for the minimal number of packages we need we do not @@ -63,13 +97,13 @@ function update_pacman_db () { } function install_pkgs () { - #1.5 + #1.6 printf -- '%s\n' 'Installing packages ...' pacman -S --needed --noconfirm "${@}" } function install_zfs () { - #1.6 + #1.7 declare reset_colors='\033[0m' curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash printf -- "${reset_colors}" @@ -256,7 +290,7 @@ function export_pool () { } function setup_zpool () { - #1.7 + #1.8 local drive_by_id zpool_drive="$(select_part 'zfs')" drive_by_id="$(get_drive_id "${zpool_drive}")" @@ -276,7 +310,7 @@ function setup_zpool () { } function mount_system () { - #1.8 + #1.9 zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" zfs mount -a @@ -289,7 +323,7 @@ function mount_system () { } function copy_zpool_cache () { - #1.9 + #1.10 mkdir -p '/mnt/etc/zfs' zpool set 'cachefile=/etc/zfs/'"${zpool_name}"'.cache' "${zpool_name}" } @@ -309,7 +343,7 @@ function pacman_dont_check_space () { } function install_archlinux () { - #1.10 + #1.11 pacman_dl_parallel pacman_dont_check_space pacstrap /mnt \ @@ -336,7 +370,7 @@ function install_archlinux () { } function gen_fstab () { - #1.11 + #1.12 genfstab -U /mnt | grep -v "${zpool_name}" | tr -s '\n' | sed -r -e 's/\/mnt//' -e '/./,$!d' > '/mnt/etc/fstab' } @@ -349,7 +383,7 @@ EOF } function set_hostname () { - #1.12 + #1.13 declare new_hostname install_pkgs 'pwgen' new_hostname="$(pwgen --no-numerals --no-capitalize --ambiguous 8)" @@ -358,7 +392,7 @@ function set_hostname () { } function set_locale () { - #1.13 + #1.14 printf -- '%s\n' \ 'KEYMAP=de-latin1' \ 'FONT=Lat2-Terminus16' \ @@ -369,7 +403,7 @@ function set_locale () { } function add_zfs_hook_to_initramfs () { - #1.14 + #1.15 # Add zfs hook, remove fsck hook from initramfs. sed -ri \ -e 's'$'\x1''(HOOKS=)(.*?[\(| ])(filesystems)([\)| ][^\r\n\f]*)'$'\x1''\1\2zfs \3\4'$'\x1''g' \ @@ -384,7 +418,7 @@ function add_zfs_hook_to_initramfs () { } function set_initramfs_build_list () { - #1.15 + #1.16 # No need to build fallback initramfs, our new fallback is ZFS snapshots sed -ri \ -e '/^#/d' \ @@ -398,7 +432,7 @@ function set_initramfs_build_list () { } function add_zfs_files_to_new_os () { - #1.16 + #1.17 for zfs_file in '/etc/hostid' '/etc/zfs/zpool.cache' $([[ ! "${ARCHZBM_ZFSPROPS_NO_ENCRYPTION}" ]] && printf -- '%s' '/etc/zfs/'"${zpool_name}"'.key'); do rsync -av --itemize-changes {'','/mnt'}"${zfs_file}" done @@ -571,7 +605,11 @@ Kernel: CommandLine: ro loglevel=0 zbm.import_policy=hostid Prefix: vmlinuz EOF -# Up here maybe 'ro quiet' instead of 'ro' +# Up here maybe 'ro quiet' instead of 'ro'. This is ZFSBootMenu's kernel +# command line. + + # Assign cmdline for final kernel start. This is our Arch Linx kernel + # command line. zfs set org.zfsbootmenu:commandline='rw nowatchdog rd.vconsole.keymap=de-latin1' "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" } @@ -752,22 +790,23 @@ function main () { if we_are_changerooted; then install_os_in_chroot #2.2 else - no_kernel_update_in_iso #1.1 - set_ntp #1.2 - resize_cow_space #1.3 - update_pacman_db #1.4 - install_pkgs 'jq' #1.5 - install_zfs #1.6 - setup_zpool #1.7 - mount_system #1.8 - copy_zpool_cache #1.9 - install_archlinux #1.10 - gen_fstab #1.11 - set_hostname #1.12 - set_locale #1.13 - add_zfs_hook_to_initramfs #1.14 - set_initramfs_build_list #1.15 - add_zfs_files_to_new_os #1.16 + uefi_or_bios #1.1 + no_kernel_update_in_iso #1.2 + set_ntp #1.3 + resize_cow_space #1.4 + update_pacman_db #1.5 + install_pkgs 'jq' #1.6 + install_zfs #1.7 + setup_zpool #1.8 + mount_system #1.9 + copy_zpool_cache #1.10 + install_archlinux #1.11 + gen_fstab #1.12 + set_hostname #1.13 + set_locale #1.14 + add_zfs_hook_to_initramfs #1.15 + set_initramfs_build_list #1.16 + add_zfs_files_to_new_os #1.17 enter_chroot #2.1 # We're done in chroot finalize_os_setup #3.1 -- 2.47.2 From 78053e813a56c7076f7072ff274b3b76b482bc66 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 01:01:18 +0200 Subject: [PATCH 04/12] feat(iso): Select correct partition for zpool on a legacy BIOS machine (#7) --- setup.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index 00199b4..17c38b6 100644 --- a/setup.sh +++ b/setup.sh @@ -125,16 +125,21 @@ function get_part_parent () { } function get_parts () { - local zfs_install_drive + local zfs_install_drive part_type_code declare parttype parts parttype="${1:?}" zfs_install_drive="${2:-}" case "${parttype}" in zfs) - parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | .children[] | select(.parttype=="6a85cf4d-1dd2-11b2-99a6-080020736631") | .path')" || exit 1 + if [[ "${part_schema}" = 'mbr' ]]; then + part_type_code="${partition_types[mbr_zfs]}" + else + part_type_code="${partition_types[gpt_zfs]}" + fi + parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | .children[] | select(.parttype=="'"${part_type_code}"'") | .path')" || exit 1 ;; efi) - parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b") | .path')" || exit 1 + parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="'"${partition_types[gpt_efi]}"'") | .path')" || exit 1 ;; *) >&3 printf -- '%s\n' 'Unknown partition type '"'"'"${parttype}"'"'"', exiting ...' @@ -181,7 +186,7 @@ function get_drive_id () { } function select_part () { - local parts enriched_parts enriched_parts_count part_number part_type zfs_install_drive + local parts enriched_parts enriched_parts_count part_number part_type zfs_install_drive part_type_code declare part part_type="${1:?}" # 'efi' or 'zfs' zfs_install_drive="${2:-}" @@ -198,7 +203,12 @@ function select_part () { part_type_human_readable='EFI system partition (ESP) with partition type code EF00' ;; zfs) - part_type_human_readable='ZFS zpool partition with partition type code BF00' + if [[ "${part_schema}" = 'mbr' ]]; then + part_type_code='bf' + else + part_type_code='BF00' + fi + part_type_human_readable='ZFS zpool partition with partition type code '"${part_type_code}" ;; esac >&3 printf -- '%s\n' \ @@ -626,7 +636,7 @@ function get_disks_with_one_efipart () { # Find disks that have exactly one EFI partition and where that EFI # partition is partition number 1. We expect exactly one disk to meet # these criteria. Anything else and we bail. - disks_with_one_efipart="$(lsblk --output PATH,PARTTYPE --json --tree | jq --raw-output '.[][] | select(.children | length > 0) | select( any (.children[]; (.path | test("^[^[:digit:]]+1")) and (.parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")) and ([select(.children[].parttype=="c12a7328-f81f-11d2-ba4b-00a0c93ec93b")] | length == 1) ) | .path')" + disks_with_one_efipart="$(lsblk --output PATH,PARTTYPE --json --tree | jq --raw-output '.[][] | select(.children | length > 0) | select( any (.children[]; (.path | test("^[^[:digit:]]+1")) and (.parttype=="'"${partition_types[gpt_efi]}"'")) and ([select(.children[].parttype=="'"${partition_types[gpt_efi]}"'")] | length == 1) ) | .path')" if [[ "$(wc -l <<<"${disks_with_one_efipart}")" -eq '1' ]] && [[ "$(wc -c <<<"${disks_with_one_efipart}")" -gt '1' ]]; then printf -- '%s' "${disks_with_one_efipart}" return 0 -- 2.47.2 From a654f1ad141bab75f983d70b0754253f93370e4d Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 01:18:38 +0200 Subject: [PATCH 05/12] feat(iso): Mount drives on legacy BIOS machine (#7) --- setup.sh | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/setup.sh b/setup.sh index 17c38b6..a8ea41d 100644 --- a/setup.sh +++ b/setup.sh @@ -34,7 +34,7 @@ partition_types[mbr_boot]='0x83' set -E trap '[ "$?" -ne 77 ] || exit 77' ERR -declare zpool_drive efi_drive part_schema +declare zpool_drive efi_drive boot_drive part_schema function we_are_changerooted () { if [ "$(stat -c '%d:%i' '/')" != "$(stat -c '%d:%i' '/proc/1/root/.')" ]; then @@ -138,6 +138,9 @@ function get_parts () { fi parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | .children[] | select(.parttype=="'"${part_type_code}"'") | .path')" || exit 1 ;; + boot) + parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="'"${partition_types[mbr_boot]}"'") | .path')" || exit 1 + ;; efi) parts="$(get_partitions | jq --raw-output '.[][] | select(.children | length > 0) | select(.path=="'"${zfs_install_drive:?}"'") | .children[] | select(.parttype=="'"${partition_types[gpt_efi]}"'") | .path')" || exit 1 ;; @@ -186,15 +189,22 @@ function get_drive_id () { } function select_part () { - local parts enriched_parts enriched_parts_count part_number part_type zfs_install_drive part_type_code + local parts enriched_parts enriched_parts_count part_number part_type zfs_install_drive part_type_code specific_part_type declare part - part_type="${1:?}" # 'efi' or 'zfs' + part_type="${1:?}" # 'boot' or 'zfs' zfs_install_drive="${2:-}" - if [[ "${zfs_install_drive}" ]]; then - # This is intended to find correct EFI partition - parts="$(get_parts "${part_type}" "${zfs_install_drive}")" + + if [[ "${part_schema}" = 'mbr' ]]; then + specific_part_type='boot' else - parts="$(get_parts "${part_type}")" + specific_part_type='efi' + fi + + if [[ "${zfs_install_drive}" ]]; then + # This is intended to find correct boot/EFI partition + parts="$(get_parts "${specific_part_type}" "${zfs_install_drive}")" + else + parts="$(get_parts "${specific_part_type}")" fi if [[ ! "${parts}" ]]; then @@ -324,12 +334,20 @@ function mount_system () { zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" zfs mount -a - local zfs_parent efi_part + local zfs_parent efi_part boot_part zfs_parent="$(get_part_parent "${zpool_drive:?}")" - efi_drive="${zfs_parent}" - efi_part="$(select_part 'efi' "${zfs_parent:?}")" - mkdir -p '/mnt/efi' - mount "${efi_part}" '/mnt/efi' + + if [[ "${part_schema}" = 'mbr' ]]; then + boot_drive="${zfs_parent}" + boot_part="$(select_part 'boot' "${zfs_parent:?}")" + mkdir -p '/mnt/boot/syslinux' + mount "${boot_part}" '/mnt/boot/syslinux' + else + efi_drive="${zfs_parent}" + efi_part="$(select_part 'boot' "${zfs_parent:?}")" + mkdir -p '/mnt/efi' + mount "${efi_part}" '/mnt/efi' + fi } function copy_zpool_cache () { -- 2.47.2 From 84266e66cfe4d255264f6e4c31c964872716dae7 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 02:01:36 +0200 Subject: [PATCH 06/12] feat(os): Create syslinux boot loader for legacy BIOS machine (#7) --- setup.sh | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index a8ea41d..018aa2e 100644 --- a/setup.sh +++ b/setup.sh @@ -612,11 +612,41 @@ function paru_install () { fi } +function configure_syslinux () { + paru_install 'syslinux' + cp /usr/lib/syslinux/bios/*.c32 /boot/syslinux + extlinux --install /boot/syslinux + cat > /boot/syslinux/syslinux.cfg < '/etc/zfsbootmenu/config.yaml' < '/etc/zfsbootmenu/config.yaml' < '/etc/zfsbootmenu/config.yaml' < Date: Mon, 23 Oct 2023 02:05:25 +0200 Subject: [PATCH 07/12] feat(os): Finalize and umount on legacy BIOS machine (#7) --- setup.sh | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 018aa2e..a1cb3a7 100644 --- a/setup.sh +++ b/setup.sh @@ -845,7 +845,11 @@ function insert_zbm_postconf_hook () { function umount_all () { #3.10 - umount '/mnt/efi' + if [[ "${part_schema}" = 'mbr' ]]; then + umount '/mnt/boot/syslinux' + else + umount '/mnt/efi' + fi zfs umount -a zpool export "${zpool_name}" } @@ -858,8 +862,10 @@ function finalize_os_setup () { configure_reflector #3.5 configure_zfs #3.6 configure_zfs_mount_gen #3.7 - set_new_uefi_boot_entries #3.8 - insert_zbm_postconf_hook #3.9 + if [[ "${part_schema}" = 'gpt' ]]; then + set_new_uefi_boot_entries #3.8 + insert_zbm_postconf_hook #3.9 + fi umount_all #3.10 } -- 2.47.2 From d685431684c90ccb80e234e810deb9bea3a9cd59 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 02:16:02 +0200 Subject: [PATCH 08/12] feat(iso): Use jq only after it's installed (#7) --- setup.sh | 90 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 45 insertions(+), 45 deletions(-) diff --git a/setup.sh b/setup.sh index a1cb3a7..21ae933 100644 --- a/setup.sh +++ b/setup.sh @@ -44,8 +44,45 @@ function we_are_changerooted () { fi } -function uefi_or_bios () { +function no_kernel_update_in_iso () { #1.1 + sed -ri -e 's'$'\x1''#(IgnorePkg)[^\r\n\f]+'$'\x1''\1 = linux linux-headers'$'\x1''g' /etc/pacman.conf +} + +function set_ntp () { + #1.2 + timedatectl set-ntp true +} + +function resize_cow_space () { + #1.3 + mount -o remount,size='50%' /run/archiso/cowspace +} + +function update_pacman_db () { + #1.4 + printf -- '%s\n' 'Refreshing mirror list ...' + systemctl start reflector + # In an ISO and for the minimal number of packages we need we do not + # care about partial upgrades + pacman -Syyuu --noconfirm +} + +function install_pkgs () { + #1.5 + printf -- '%s\n' 'Installing packages ...' + pacman -S --needed --noconfirm "${@}" +} + +function install_zfs () { + #1.6 + declare reset_colors='\033[0m' + curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash + printf -- "${reset_colors}" +} + +function uefi_or_bios () { + #1.7 local part_count_linux part_count_efi # Select disks with at least one partition. Among them count how many # with the given partition type code we have. @@ -72,43 +109,6 @@ function uefi_or_bios () { fi } -function no_kernel_update_in_iso () { - #1.2 - sed -ri -e 's'$'\x1''#(IgnorePkg)[^\r\n\f]+'$'\x1''\1 = linux linux-headers'$'\x1''g' /etc/pacman.conf -} - -function set_ntp () { - #1.3 - timedatectl set-ntp true -} - -function resize_cow_space () { - #1.4 - mount -o remount,size='50%' /run/archiso/cowspace -} - -function update_pacman_db () { - #1.5 - printf -- '%s\n' 'Refreshing mirror list ...' - systemctl start reflector - # In an ISO and for the minimal number of packages we need we do not - # care about partial upgrades - pacman -Syyuu --noconfirm -} - -function install_pkgs () { - #1.6 - printf -- '%s\n' 'Installing packages ...' - pacman -S --needed --noconfirm "${@}" -} - -function install_zfs () { - #1.7 - declare reset_colors='\033[0m' - curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash - printf -- "${reset_colors}" -} - function get_partitions () { declare partitions_json partitions_json="$(lsblk --output PATH,PARTTYPE --json --tree)" || return 1 @@ -873,13 +873,13 @@ function main () { if we_are_changerooted; then install_os_in_chroot #2.2 else - uefi_or_bios #1.1 - no_kernel_update_in_iso #1.2 - set_ntp #1.3 - resize_cow_space #1.4 - update_pacman_db #1.5 - install_pkgs 'jq' #1.6 - install_zfs #1.7 + no_kernel_update_in_iso #1.1 + set_ntp #1.2 + resize_cow_space #1.3 + update_pacman_db #1.4 + install_pkgs 'jq' #1.5 + install_zfs #1.6 + uefi_or_bios #1.7 setup_zpool #1.8 mount_system #1.9 copy_zpool_cache #1.10 -- 2.47.2 From 615b8c0e95cf50102ebd1e2d423a7f8d38abdc2e Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 02:28:01 +0200 Subject: [PATCH 09/12] fix(iso): Find zfs partition on legacy BIOS machine (#7) --- setup.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/setup.sh b/setup.sh index 21ae933..479faad 100644 --- a/setup.sh +++ b/setup.sh @@ -194,10 +194,14 @@ function select_part () { part_type="${1:?}" # 'boot' or 'zfs' zfs_install_drive="${2:-}" - if [[ "${part_schema}" = 'mbr' ]]; then - specific_part_type='boot' + if [[ "${part_type}" = 'boot' ]]; then + if [[ "${part_schema}" = 'mbr' ]]; then + specific_part_type='boot' + else + specific_part_type='efi' + fi else - specific_part_type='efi' + specific_part_type="${part_type}" fi if [[ "${zfs_install_drive}" ]]; then -- 2.47.2 From e3d5f2b9393d7b1321215bb13b14ecf863653975 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 02:52:10 +0200 Subject: [PATCH 10/12] fix(iso): Try and improve mirrorlist handling (#7) --- setup.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/setup.sh b/setup.sh index 479faad..5daf3da 100644 --- a/setup.sh +++ b/setup.sh @@ -62,6 +62,16 @@ function resize_cow_space () { function update_pacman_db () { #1.4 printf -- '%s\n' 'Refreshing mirror list ...' + printf -- '%s\n' \ + '--save /etc/pacman.d/mirrorlist' \ + '--ipv4' \ + '--ipv6' \ + '--protocol https' \ + '--latest 50' \ + '--sort rate' \ + '--score 30' \ + '--fastest 10' \ + > '/etc/xdg/reflector/reflector.conf' systemctl start reflector # In an ISO and for the minimal number of packages we need we do not # care about partial upgrades -- 2.47.2 From d059cb6ae04039ff4473766d382814c37d9ffb88 Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 03:02:23 +0200 Subject: [PATCH 11/12] fix(iso): Try and improve mirrorlist handling (#7) --- setup.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/setup.sh b/setup.sh index 5daf3da..b6bed68 100644 --- a/setup.sh +++ b/setup.sh @@ -64,13 +64,9 @@ function update_pacman_db () { printf -- '%s\n' 'Refreshing mirror list ...' printf -- '%s\n' \ '--save /etc/pacman.d/mirrorlist' \ - '--ipv4' \ - '--ipv6' \ '--protocol https' \ - '--latest 50' \ - '--sort rate' \ - '--score 30' \ - '--fastest 10' \ + '--latest 5' \ + '--sort age' \ > '/etc/xdg/reflector/reflector.conf' systemctl start reflector # In an ISO and for the minimal number of packages we need we do not -- 2.47.2 From 33e74985296d26fad9b9103889715813414cf39a Mon Sep 17 00:00:00 2001 From: hygienic-books Date: Mon, 23 Oct 2023 23:53:11 +0200 Subject: [PATCH 12/12] fix(iso): export vars we'll be needing inside a subshell (#7) --- setup.sh | 3 +++ 1 file changed, 3 insertions(+) diff --git a/setup.sh b/setup.sh index b6bed68..a023530 100644 --- a/setup.sh +++ b/setup.sh @@ -113,6 +113,7 @@ function uefi_or_bios () { 'neither. Cowardly exiting ...' exit 77 fi + export part_schema="${part_schema}" } function get_partitions () { @@ -349,11 +350,13 @@ function mount_system () { if [[ "${part_schema}" = 'mbr' ]]; then boot_drive="${zfs_parent}" + export boot_drive="${boot_drive}" boot_part="$(select_part 'boot' "${zfs_parent:?}")" mkdir -p '/mnt/boot/syslinux' mount "${boot_part}" '/mnt/boot/syslinux' else efi_drive="${zfs_parent}" + export efi_drive="${efi_drive}" efi_part="$(select_part 'boot' "${zfs_parent:?}")" mkdir -p '/mnt/efi' mount "${efi_part}" '/mnt/efi' -- 2.47.2