From ee2e6f43030d6050113920095b8256b076d7b3fd Mon Sep 17 00:00:00 2001 From: langfingaz Date: Mon, 3 May 2021 17:38:10 +0200 Subject: [PATCH] fix --- build-archiso.sh | 9 ++-- pkg/de-p1st-installer/PKGBUILD | 2 +- pkg/de-p1st-installer/README.md | 32 ++++++++++++++ pkg/de-p1st-installer/de-p1st-installer.sh | 49 +++++++++++++--------- pkg/de-p1st-installer/installer.cfg | 9 +++- pkg/de-p1st-installer/lib/block-device.sh | 20 ++++----- 6 files changed, 84 insertions(+), 37 deletions(-) create mode 100644 pkg/de-p1st-installer/README.md diff --git a/build-archiso.sh b/build-archiso.sh index 950052a..5fa6e49 100755 --- a/build-archiso.sh +++ b/build-archiso.sh @@ -3,16 +3,15 @@ # https://wiki.archlinux.org/index.php/Archiso#Prepare_a_custom_profile # # Arch installer with some additional packages: -# -> TODO: set custom welchme messae in /etc/motd -# -> de-p1st-installer (TODO) -# -> de-p1st mirror in pacman.conf -# -> german mirrors preselected +# -> TODO: set custom welcome message in /etc/motd +# -> de-p1st-installer +# -> [de-p1st] repository enabled in pacman.conf # -> german keyboard # -> nano with syntax highlighting # -> git # BUILD_DIR=./archlive -PKGS=('git' 'de-p1st-keyboard' 'de-p1st-nano' 'de-p1st-pacman' 'de-p1st-systemd') +PKGS=('git' 'de-p1st-keyboard' 'de-p1st-nano' 'de-p1st-pacman' 'de-p1st-systemd' 'de-p1st-installer') PACMAN_CFG_ADDITION='pkg/de-p1st-pacman/pacman.d/de-p1st' # will be used to extend the builder's pacman.conf diff --git a/pkg/de-p1st-installer/PKGBUILD b/pkg/de-p1st-installer/PKGBUILD index d4fc827..0f82721 100644 --- a/pkg/de-p1st-installer/PKGBUILD +++ b/pkg/de-p1st-installer/PKGBUILD @@ -2,7 +2,7 @@ _pkgname=installer _reponame=arch pkgname="de-p1st-$_pkgname" -pkgver=0.0.1 +pkgver=0.0.2 pkgrel=1 pkgdesc="Bash script to install Arch Linux" arch=('any') diff --git a/pkg/de-p1st-installer/README.md b/pkg/de-p1st-installer/README.md new file mode 100644 index 0000000..0c5388e --- /dev/null +++ b/pkg/de-p1st-installer/README.md @@ -0,0 +1,32 @@ +# Arch installer + +## Running the installer + +### via custom livemedium + +1) Build the ISO: Run script found in the base of this git repo: + +```shell +./build-archiso.sh +``` + +2) Boot into the live medium +3) Adjust `/etc/de-p1st-installer/installer.cfg` (or delete for interactive mode) +4) Run the installer + +```shell +de-p1st-installer +``` + +### via official livemedium + +1) Boot into the live medium from [archlinux.org](archlinux.org) +2) Add to `/etc/pacman.conf`: + +```shell +[de-p1st] +SigLevel = Optional TrustAll +Server = https://arch.p1st.de +``` + +3) Continue with step (3) of "via custom livemedium" diff --git a/pkg/de-p1st-installer/de-p1st-installer.sh b/pkg/de-p1st-installer/de-p1st-installer.sh index d6a7fa5..cdb29c2 100755 --- a/pkg/de-p1st-installer/de-p1st-installer.sh +++ b/pkg/de-p1st-installer/de-p1st-installer.sh @@ -28,7 +28,7 @@ function increase_cow_space() { } echo "Increasing cowspace partition of live medium ..." - mount -o remount,size=2G /run/archiso/cowspace || return $? + sudo mount -o remount,size=2G /run/archiso/cowspace || return $? } function get_user_input() { @@ -162,6 +162,7 @@ function run_pacstrap() { # KERNEL # CPU_VENDOR + echo "Running pacstrap ..." PKGS=() case "${KERNEL}" in @@ -207,13 +208,14 @@ function run_pacstrap() { ;; esac - pacstrap /mnt "${PKGS[@]}" || return $? + sudo pacstrap /mnt "${PKGS[@]}" || return $? } function run_genfstab() { # @pre # FS + echo "Generating fstab ..." local fstab fstab="$(genfstab -U /mnt)" @@ -239,7 +241,7 @@ function run_genfstab() { ;; esac - printf "%s" "${fstab}" > /mnt/etc/fstab || return $? + printf "%s" "${fstab}" | sudo tee /mnt/etc/fstab >/dev/null || return $? } function config_hostname_and_hosts() { @@ -249,8 +251,10 @@ function config_hostname_and_hosts() { # STATIC_IP (optional, e.g. 93.133.433.133) # IPV6_CAPABLE (optional, e.g. 1) - echo "${HOSTNAME}" >/mnt/etc/hostname || return $? + echo "Set hostname ..." + echo "${HOSTNAME}" | sudo tee /mnt/etc/hostname >/dev/null || return $? + echo "Create hosts file ..." # If the system has a permanent IP address, it should be used instead of 127.0.1.1. # * https://wiki.archlinux.org/index.php/Installation_guide#Network_configuration @@ -265,14 +269,14 @@ function config_hostname_and_hosts() { echo "# The following lines are desirable for IPv4 capable hosts 127.0.0.1 localhost # 127.0.1.1 is often used for the FQDN of the machine -${STATIC_IP} ${FQDN} ${HOSTNAME}" > /mnt/etc/hosts || return $? +${STATIC_IP} ${FQDN} ${HOSTNAME}" | sudo tee /mnt/etc/hosts >/dev/null || return $? if [ "${IPV6_CAPABLE}" = "1" ]; then echo " # The following lines are desirable for IPv6 capable hosts ::1 localhost ip6-localhost ip6-loopback ff02::1 ip6-allnodes -ff02::2 ip6-allrouters" >> /mnt/etc/hosts || return $? +ff02::2 ip6-allrouters" | sudo tee -a /mnt/etc/hosts >/dev/null || return $? fi } @@ -282,16 +286,17 @@ function user_and_pwd() { # USER_PWD # ROOT_PWD (optional) + echo "Adding user and changing shell to /bin/zsh ..." # -m: create home # -U: Create a group with the same name as the user, and add the user to this group. - arch-chroot /mnt useradd -m -s /usr/bin/zsh -g wheel "${USERNAME}" || return $? - arch-chroot /mnt chsh -s /usr/bin/zsh || return $? + sudo arch-chroot /mnt useradd -m -s /usr/bin/zsh -g wheel "${USERNAME}" || return $? + sudo arch-chroot /mnt chsh -s /usr/bin/zsh || return $? # If ROOT_PWD is not given, the use USER_PWD for root user ROOT_PWD="${ROOT_PWD:="${USER_PWD}"}" - printf "%s:%s" "${USERNAME}" "${USER_PWD}" | chpasswd --root /mnt || return $? - printf "%s:%s" "root" "${ROOT_PWD}" | chpasswd --root /mnt || return $? + printf "%s:%s" "${USERNAME}" "${USER_PWD}" | sudo chpasswd --root /mnt || return $? + printf "%s:%s" "root" "${ROOT_PWD}" | sudo chpasswd --root /mnt || return $? } function bootloader() { @@ -299,15 +304,16 @@ function bootloader() { # TARGET_BLOCK_DEVICE # LUKS_PART_UUID + echo "Installing grub ..." case "${BIOS_TYPE}" in uefi) # portable fallback efi name for grub: # * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming # * arch-chroot /mnt cp /boot/EFI/GRUB/grubx64.efi /boot/EFI/BOOT/bootx64.efi - arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable || return $? + sudo arch-chroot /mnt grub-install --target=x86_64-efi --bootloader-id=GRUB --efi-directory=/boot --removable || return $? ;; bios) - arch-chroot /mnt grub-install --target=i386-pc "${TARGET_BLOCK_DEVICE}" || return $? + sudo arch-chroot /mnt grub-install --target=i386-pc "${TARGET_BLOCK_DEVICE}" || return $? ;; *) echo "Not yet implemented!" @@ -315,9 +321,10 @@ function bootloader() { ;; esac - sed -i "s|^GRUB_CMDLINE_LINUX=.*\$|GRUB_CMDLINE_LINUX=\"cryptdevice=/dev/disk/by-uuid/${LUKS_PART_UUID}:crypt\"|" \ + echo "Generating /boot/grub/grub.cfg ..." + sudo sed -i "s|^GRUB_CMDLINE_LINUX=.*\$|GRUB_CMDLINE_LINUX=\"cryptdevice=/dev/disk/by-uuid/${LUKS_PART_UUID}:crypt\"|" \ /mnt/etc/default/grub || return $? - arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg || return $? + sudo arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg || return $? } function main() { @@ -352,11 +359,11 @@ function main() { join_by "," TMP1 FS_MOUNT_OPTIONS || return $? echo "Mounting data partition with options: ${FS_MOUNT_OPTIONS}" - mount -o "${FS_MOUNT_OPTIONS}" "$DATA_PART" /mnt || return $? + sudo mount -o "${FS_MOUNT_OPTIONS}" "$DATA_PART" /mnt || return $? echo "Mounting boot partition ..." mkdir /mnt/boot || return $? - mount "$BOOT_PART" /mnt/boot || return $? + sudo mount "$BOOT_PART" /mnt/boot || return $? # in: BIOS_TYPE, KERNEL, CPU_VENDOR run_pacstrap || return $? @@ -368,12 +375,16 @@ function main() { # in: USERNAME, USER_PWD, ROOT_PWD (optional) user_and_pwd || return $? - mkinitcpio -P || return $? + sudo arch-chroot /mnt mkinitcpio -P || return $? # in: TARGET_BLOCK_DEVICE, LUKS_PART_UUID bootloader || return $? - umount -R /mnt || return $? - cryptsetup luksClose "$(basename "${DATA_PART}")" || return $? + if [ "${LEAVE_MOUNTED}" -eq "1" ]; then + echo "Leaving partitions below /mnt mounted and ${DATA_PART} opened." + else + sudo umount -R /mnt || return $? + sudo cryptsetup luksClose "$(basename "${DATA_PART}")" || return $? + fi echo "Finished installation without errors!" } diff --git a/pkg/de-p1st-installer/installer.cfg b/pkg/de-p1st-installer/installer.cfg index 1ed1665..5aa7b70 100644 --- a/pkg/de-p1st-installer/installer.cfg +++ b/pkg/de-p1st-installer/installer.cfg @@ -1,5 +1,4 @@ -# Example config -# for test in virtual machine +# Example config (for test in virtual machine) # FQDN=domain.name.of.this.host.de # STATIC_IP=123.456.789.012 @@ -21,5 +20,11 @@ BOOT_PART_SIZE=500 # MiB FS=BTRFS FS_CHOSEN_MOUNT_OPTIONS=('noatime') +# If not booted into the target system, these values should be set: +# CPU_VENDOR: "amd", "intel" or "none" CPU_VENDOR=none BIOS_TYPE=uefi + +# If set to "1", then the data, boot and luks partitions +# will be left mounted/opened after installation +LEAVE_MOUNTED=1 diff --git a/pkg/de-p1st-installer/lib/block-device.sh b/pkg/de-p1st-installer/lib/block-device.sh index 4b0f153..c74b290 100644 --- a/pkg/de-p1st-installer/lib/block-device.sh +++ b/pkg/de-p1st-installer/lib/block-device.sh @@ -74,7 +74,7 @@ function partition() { # # Create a partition with fat32 as the file system type and set the # esp flag on it. - parted --script "${TARGET_BLOCK_DEVICE}" -- mklabel gpt \ + sudo parted --script "${TARGET_BLOCK_DEVICE}" -- mklabel gpt \ mkpart ESP fat32 2Mib "${BOOT_PART_SIZE}MiB" \ set 1 esp on \ mkpart primary "${BOOT_PART_SIZE}MiB" 100% || return $? @@ -90,7 +90,7 @@ function partition() { # # archwiki -> GRUB#GUID_Partition_Table_(GPT)_specific_instructions # https://www.gnu.org/software/grub/manual/grub/html_node/BIOS-installation.html#BIOS-installation - parted --script "${TARGET_BLOCK_DEVICE}" -- mklabel gpt \ + sudo parted --script "${TARGET_BLOCK_DEVICE}" -- mklabel gpt \ mkpart primary 1MiB 2MiB \ set 1 bios_grub on \ mkpart primary 2MiB "${BOOT_PART_SIZE}MiB" \ @@ -124,17 +124,17 @@ function format() { # luks partition formatted and opened at DATA_PART echo "Wiping old signatures from partitions ..." - wipefs "${BOOT_PART}" || return $? - wipefs "${LUKS_PART}" || return $? + sudo wipefs "${BOOT_PART}" || return $? + sudo wipefs "${LUKS_PART}" || return $? echo "Formatting boot partition ${BOOT_PART} ..." - mkfs.fat -F32 "${BOOT_PART}" || return $? + sudo mkfs.fat -F32 "${BOOT_PART}" || return $? # Note: # FDE: GRUB does support LUKS2 since this commit: https://git.savannah.gnu.org/cgit/grub.git/commit/?id=365e0cc3e7e44151c14dd29514c2f870b49f9755 # -> Using "--type luks1" is no longer required. echo "Creating encrypted luks partition ${LUKS_PART} ..." - printf "%s" "${LUKS_PWD}" | cryptsetup luksFormat \ + printf "%s" "${LUKS_PWD}" | sudo cryptsetup luksFormat \ --cipher aes-xts-plain64 --key-size 512 --hash sha512 \ --iter-time 10000 --use-random "${LUKS_PART}" || return $? @@ -145,22 +145,22 @@ function format() { DATA_PART="/dev/mapper/${luks_name}" # open luks partition - printf "%s" "${LUKS_PWD}" | cryptsetup luksOpen "${LUKS_PART}" "${luks_name}" || return $? + printf "%s" "${LUKS_PWD}" | sudo cryptsetup luksOpen "${LUKS_PART}" "${luks_name}" || return $? echo "Formatting the data partition ${DATA_PART} ..." case "${FS}" in BTRFS) - mkfs.btrfs "${DATA_PART}" || return $? + sudo mkfs.btrfs "${DATA_PART}" || return $? ;; EXT4) # archwiki -> Ext4#Enabling_metadata_checksums - mkfs.ext4 -O metadata_csum "${DATA_PART}" || return $? + sudo mkfs.ext4 -O metadata_csum "${DATA_PART}" || return $? ;; F2FS) # archwiki -> F2FS#Creating_a_F2FS_file_system # - requires f2fs-tools # - compression: "-O compression" and when mounting the filesystem, specify compress_algorithm=(lzo|lz4|zstd|lzo-rle) - mkfs.f2fs -O extra_attr,inode_checksum,sb_checksum,compression "${DATA_PART}" || return $? + sudo mkfs.f2fs -O extra_attr,inode_checksum,sb_checksum,compression "${DATA_PART}" || return $? ;; *) echo "Filesystem ${FS} is not yet supported!"