diff --git a/setup.sh b/setup.sh index ecabb66..bcb0c3b 100644 --- a/setup.sh +++ b/setup.sh @@ -42,6 +42,7 @@ function install_pkgs () { } function prepare_zfsbootmenu_efi_bin_pkg () { + #1.4 # Our Arch Linux will use prebuilt ZFSBootMenu UEFI image files for ease # of use. We'd like to install them from within our chroot but the AUR # package 'zfsbootmenu-efi-bin' that we're using currently (Friday, @@ -90,7 +91,7 @@ function prepare_zfsbootmenu_efi_bin_pkg () { } function install_zfs () { - #1.4 + #1.5 declare reset_colors='\033[0m' curl -s 'https://raw.githubusercontent.com/eoli3n/archiso-zfs/master/init' | bash printf -- "${reset_colors}" @@ -261,7 +262,7 @@ function export_pool () { } function setup_zpool () { - #1.4 + #1.6 local drive_by_id zpool_drive="$(select_part 'zfs')" drive_by_id="$(get_drive_id "${zpool_drive}")" @@ -281,7 +282,7 @@ function setup_zpool () { } function mount_system () { - #1.5 + #1.7 zfs mount "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" zfs mount -a @@ -294,12 +295,13 @@ function mount_system () { } function copy_zpool_cache () { - #1.6 + #1.8 mkdir -p '/mnt/etc/zfs' zpool set 'cachefile=/etc/zfs/'"${zpool_name}"'.cache' "${zpool_name}" } function pacman_dl_parallel () { + #2.4 # We're setting this in Arch Linux ISO CD while we install proper Arch. # No need to revert this later as it is ephemeral anyway. sed -ri -e 's'$'\x1''^.*?(ParallelDownloads)[^\r\n\f]*'$'\x1''\1 = 20'$'\x1''g' '/etc/pacman.conf' @@ -320,7 +322,7 @@ function pacman_dont_check_space () { } function install_archlinux () { - #1.7 + #1.9 pacman_dl_parallel pacman_dont_check_space pacstrap /mnt \ @@ -347,7 +349,7 @@ function install_archlinux () { } function gen_fstab () { - #1.8 + #1.10 genfstab -U /mnt | grep -v "${zpool_name}" | tr -s '\n' | sed -r -e 's/\/mnt//' -e '/./,$!d' > '/mnt/etc/fstab' } @@ -360,7 +362,7 @@ EOF } function set_hostname () { - #1.9 + #1.11 declare new_hostname install_pkgs 'pwgen' new_hostname="$(pwgen --no-numerals --no-capitalize --ambiguous 8)" @@ -369,7 +371,7 @@ function set_hostname () { } function set_locale () { - #1.10 + #1.12 printf -- '%s\n' \ 'KEYMAP=de-latin1' \ 'FONT=Lat2-Terminus16' \ @@ -380,7 +382,7 @@ function set_locale () { } function add_zfs_hook_to_initramfs () { - #1.11 + #1.13 # 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' \ @@ -395,7 +397,7 @@ function add_zfs_hook_to_initramfs () { } function set_initramfs_build_list () { - #1.12 + #1.14 # No need to build fallback initramfs, our new fallback is ZFS snapshots sed -ri \ -e '/^#/d' \ @@ -409,14 +411,14 @@ function set_initramfs_build_list () { } function add_zfs_files_to_new_os () { - #1.13 + #1.15 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 } function enter_chroot () { - #1.14 + #2.1 arch-chroot /mnt /bin/bash -xe <<EOF curl --silent '${this_script_url}' | bash EOF @@ -482,6 +484,7 @@ function create_unpriv_user () { } function unleash_makepkg () { + #2.5 local path_prefix path_prefix='/mnt' if we_are_changerooted; then @@ -493,6 +496,7 @@ function unleash_makepkg () { } function get_aur_helper () { + #2.7 create_unpriv_user 'build' usermod --append --groups 'wheel' 'build' printf -- '%s\n' '%wheel ALL=(ALL:ALL) NOPASSWD: ALL' > '/etc/sudoers.d/10-wheel-group-no-passwd-prompt' @@ -551,6 +555,7 @@ function paru_install () { } function install_zbm_image () { + #2.8 # This takes image files written earlier in our Arch Linux live CD ISO # image at prepare_zfsbootmenu_efi_bin_pkg() and installs them via their # locally built package file. When done we delete the manually built @@ -560,6 +565,7 @@ function install_zbm_image () { } function keep_initiramfs_root_only_rw () { + #2.3 declare systemd_local_admin_override_path unit_name systemd_local_admin_override_path='/etc/systemd/system' unit_name='chmod-initramfs' @@ -591,6 +597,7 @@ EOF } function add_motd_getting_started_msg () { + #2.6 cat > '/etc/motd' <<"EOF" #################### @@ -606,7 +613,7 @@ EOF } function install_os_in_chroot () { - #1.16 + #2.2 ### Reinit keyring # As keyring is initialized at boot, and copied to the install dir with pacstrap, and ntp is running # Time changed after keyring initialization, it leads to malfunction @@ -616,11 +623,11 @@ function install_os_in_chroot () { pacman-key --populate archlinux pacman -S archlinux-keyring --noconfirm - keep_initiramfs_root_only_rw - pacman_dl_parallel - unleash_makepkg - add_motd_getting_started_msg - get_aur_helper + keep_initiramfs_root_only_rw #2.3 + pacman_dl_parallel #2.4 + unleash_makepkg #2.5 + add_motd_getting_started_msg #2.6 + get_aur_helper #2.7 paru_install --replace-conflicting 'paru-bin' paru_install 'zfs-dkms' 'zfs-utils' 'rsync' hwclock --systohc @@ -629,16 +636,16 @@ function install_os_in_chroot () { mkinitcpio -P # Install ZFSBootMenu image - install_zbm_image + install_zbm_image #2.8 } function set_root_pw () { - #2.1 + #3.2 printf -- '%s\n' 'root:password' | chpasswd --root '/mnt' } function configure_networking () { - #2.2 + #3.3 cat > '/mnt/etc/systemd/network/50-wired.network' <<"EOF" [Match] Name=en* @@ -656,7 +663,7 @@ EOF } function configure_dns () { - #2.3 + #3.4 rm '/mnt/etc/resolv.conf' ln -s '/run/systemd/resolve/stub-resolv.conf' '/mnt/etc/resolv.conf' @@ -667,17 +674,17 @@ function configure_dns () { } function configure_reflector () { - #2.4 + #3.5 systemctl enable 'reflector' --root='/mnt' } function configure_zfs () { - #2.5 + #3.6 systemctl enable 'zfs-import-cache' 'zfs-mount' 'zfs-import.target' 'zfs.target' --root='/mnt' } function configure_zfs_mount_gen () { - #2.6 + #3.7 mkdir -p '/mnt/etc/zfs/zfs-list.cache' touch '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}" zfs list -H -o name,mountpoint,canmount,atime,relatime,devices,exec,readonly,setuid,nbmand | sed 's/\/mnt//' > '/mnt/etc/zfs/zfs-list.cache/'"${zpool_name}" @@ -685,12 +692,12 @@ function configure_zfs_mount_gen () { } function configure_zfsbootmenu () { - #2.7 + #3.8 zfs set org.zfsbootmenu:commandline='rw nowatchdog rd.vconsole.keymap=de-latin1' "${zpool_name}"'/root/'"${zfs_arch_dataset_name}" } function gen_zfsbootmenu () { - #2.8 + #3.9 arch-chroot /mnt /bin/bash -xe <<"EOF" source /etc/locale.conf mkdir -p '/efi/EFI/ZBM' @@ -713,7 +720,7 @@ function get_disks_with_one_efipart () { } function add_zbm_to_efi () { - #2.9 + #3.10 if ! efibootmgr | grep -Piq -- 'ZFSBootMenu'; then local efi_disks_list efi_disks_list="$(get_disks_with_one_efipart)" @@ -729,48 +736,48 @@ function add_zbm_to_efi () { } function umount_all () { - #2.10 + #3.11 umount '/mnt/efi' zfs umount -a zpool export "${zpool_name}" } function finalize_os_setup () { - #1.15 - set_root_pw #2.1 - configure_networking #2.2 - configure_dns #2.3 - configure_reflector #2.4 - configure_zfs #2.5 - configure_zfs_mount_gen #2.6 - configure_zfsbootmenu #2.7 - gen_zfsbootmenu #2.8 - add_zbm_to_efi #2.9 - umount_all #2.10 + #3.1 + set_root_pw #3.2 + configure_networking #3.3 + configure_dns #3.4 + configure_reflector #3.5 + configure_zfs #3.6 + configure_zfs_mount_gen #3.7 + configure_zfsbootmenu #3.8 + gen_zfsbootmenu #3.9 + add_zbm_to_efi #3.10 + umount_all #3.11 } function main () { if we_are_changerooted; then - install_os_in_chroot #1.16 + install_os_in_chroot #2.2 else set_ntp #1.1 update_pacman_db #1.2 install_pkgs 'base-devel' 'git' 'jq' #1.3 - prepare_zfsbootmenu_efi_bin_pkg - install_zfs #1.4 - setup_zpool #1.4 - mount_system #1.5 - copy_zpool_cache #1.6 - install_archlinux #1.7 - gen_fstab #1.8 - set_hostname #1.9 - set_locale #1.10 - add_zfs_hook_to_initramfs #1.11 - set_initramfs_build_list #1.12 - add_zfs_files_to_new_os #1.13 - enter_chroot #1.14 + prepare_zfsbootmenu_efi_bin_pkg #1.4 + install_zfs #1.5 + setup_zpool #1.6 + mount_system #1.7 + copy_zpool_cache #1.8 + install_archlinux #1.9 + gen_fstab #1.10 + set_hostname #1.11 + set_locale #1.12 + add_zfs_hook_to_initramfs #1.13 + set_initramfs_build_list #1.14 + add_zfs_files_to_new_os #1.15 + enter_chroot #2.1 # We're done in chroot - finalize_os_setup #1.15 + finalize_os_setup #3.1 fi }