This commit is contained in:
Daniel Langbein 2021-05-03 17:38:10 +02:00
parent c7cb22732c
commit ee2e6f4303
6 changed files with 84 additions and 37 deletions

View File

@ -3,16 +3,15 @@
# https://wiki.archlinux.org/index.php/Archiso#Prepare_a_custom_profile # https://wiki.archlinux.org/index.php/Archiso#Prepare_a_custom_profile
# #
# Arch installer with some additional packages: # Arch installer with some additional packages:
# -> TODO: set custom welchme messae in /etc/motd # -> TODO: set custom welcome message in /etc/motd
# -> de-p1st-installer (TODO) # -> de-p1st-installer
# -> de-p1st mirror in pacman.conf # -> [de-p1st] repository enabled in pacman.conf
# -> german mirrors preselected
# -> german keyboard # -> german keyboard
# -> nano with syntax highlighting # -> nano with syntax highlighting
# -> git # -> git
# #
BUILD_DIR=./archlive 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 PACMAN_CFG_ADDITION='pkg/de-p1st-pacman/pacman.d/de-p1st' # will be used to extend the builder's pacman.conf

View File

@ -2,7 +2,7 @@
_pkgname=installer _pkgname=installer
_reponame=arch _reponame=arch
pkgname="de-p1st-$_pkgname" pkgname="de-p1st-$_pkgname"
pkgver=0.0.1 pkgver=0.0.2
pkgrel=1 pkgrel=1
pkgdesc="Bash script to install Arch Linux" pkgdesc="Bash script to install Arch Linux"
arch=('any') arch=('any')

View File

@ -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"

View File

@ -28,7 +28,7 @@ function increase_cow_space() {
} }
echo "Increasing cowspace partition of live medium ..." 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() { function get_user_input() {
@ -162,6 +162,7 @@ function run_pacstrap() {
# KERNEL # KERNEL
# CPU_VENDOR # CPU_VENDOR
echo "Running pacstrap ..."
PKGS=() PKGS=()
case "${KERNEL}" in case "${KERNEL}" in
@ -207,13 +208,14 @@ function run_pacstrap() {
;; ;;
esac esac
pacstrap /mnt "${PKGS[@]}" || return $? sudo pacstrap /mnt "${PKGS[@]}" || return $?
} }
function run_genfstab() { function run_genfstab() {
# @pre # @pre
# FS # FS
echo "Generating fstab ..."
local fstab local fstab
fstab="$(genfstab -U /mnt)" fstab="$(genfstab -U /mnt)"
@ -239,7 +241,7 @@ function run_genfstab() {
;; ;;
esac esac
printf "%s" "${fstab}" > /mnt/etc/fstab || return $? printf "%s" "${fstab}" | sudo tee /mnt/etc/fstab >/dev/null || return $?
} }
function config_hostname_and_hosts() { function config_hostname_and_hosts() {
@ -249,8 +251,10 @@ function config_hostname_and_hosts() {
# STATIC_IP (optional, e.g. 93.133.433.133) # STATIC_IP (optional, e.g. 93.133.433.133)
# IPV6_CAPABLE (optional, e.g. 1) # 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. # 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 # * 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 echo "# The following lines are desirable for IPv4 capable hosts
127.0.0.1 localhost 127.0.0.1 localhost
# 127.0.1.1 is often used for the FQDN of the machine # 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 if [ "${IPV6_CAPABLE}" = "1" ]; then
echo " echo "
# The following lines are desirable for IPv6 capable hosts # The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback ::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes 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 fi
} }
@ -282,16 +286,17 @@ function user_and_pwd() {
# USER_PWD # USER_PWD
# ROOT_PWD (optional) # ROOT_PWD (optional)
echo "Adding user and changing shell to /bin/zsh ..."
# -m: create home # -m: create home
# -U: Create a group with the same name as the user, and add the user to this group. # -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 $? sudo 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 chsh -s /usr/bin/zsh || return $?
# If ROOT_PWD is not given, the use USER_PWD for root user # If ROOT_PWD is not given, the use USER_PWD for root user
ROOT_PWD="${ROOT_PWD:="${USER_PWD}"}" ROOT_PWD="${ROOT_PWD:="${USER_PWD}"}"
printf "%s:%s" "${USERNAME}" "${USER_PWD}" | chpasswd --root /mnt || return $? printf "%s:%s" "${USERNAME}" "${USER_PWD}" | sudo chpasswd --root /mnt || return $?
printf "%s:%s" "root" "${ROOT_PWD}" | chpasswd --root /mnt || return $? printf "%s:%s" "root" "${ROOT_PWD}" | sudo chpasswd --root /mnt || return $?
} }
function bootloader() { function bootloader() {
@ -299,15 +304,16 @@ function bootloader() {
# TARGET_BLOCK_DEVICE # TARGET_BLOCK_DEVICE
# LUKS_PART_UUID # LUKS_PART_UUID
echo "Installing grub ..."
case "${BIOS_TYPE}" in case "${BIOS_TYPE}" in
uefi) uefi)
# portable fallback efi name for grub: # portable fallback efi name for grub:
# * https://www.rodsbooks.com/efi-bootloaders/installation.html#alternative-naming # * 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 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) 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!" echo "Not yet implemented!"
@ -315,9 +321,10 @@ function bootloader() {
;; ;;
esac 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 $? /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() { function main() {
@ -352,11 +359,11 @@ function main() {
join_by "," TMP1 FS_MOUNT_OPTIONS || return $? join_by "," TMP1 FS_MOUNT_OPTIONS || return $?
echo "Mounting data partition with options: ${FS_MOUNT_OPTIONS}" 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 ..." echo "Mounting boot partition ..."
mkdir /mnt/boot || return $? mkdir /mnt/boot || return $?
mount "$BOOT_PART" /mnt/boot || return $? sudo mount "$BOOT_PART" /mnt/boot || return $?
# in: BIOS_TYPE, KERNEL, CPU_VENDOR # in: BIOS_TYPE, KERNEL, CPU_VENDOR
run_pacstrap || return $? run_pacstrap || return $?
@ -368,12 +375,16 @@ function main() {
# in: USERNAME, USER_PWD, ROOT_PWD (optional) # in: USERNAME, USER_PWD, ROOT_PWD (optional)
user_and_pwd || return $? user_and_pwd || return $?
mkinitcpio -P || return $? sudo arch-chroot /mnt mkinitcpio -P || return $?
# in: TARGET_BLOCK_DEVICE, LUKS_PART_UUID # in: TARGET_BLOCK_DEVICE, LUKS_PART_UUID
bootloader || return $? bootloader || return $?
umount -R /mnt || return $? if [ "${LEAVE_MOUNTED}" -eq "1" ]; then
cryptsetup luksClose "$(basename "${DATA_PART}")" || return $? 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!" echo "Finished installation without errors!"
} }

View File

@ -1,5 +1,4 @@
# Example config # Example config (for test in virtual machine)
# for test in virtual machine
# FQDN=domain.name.of.this.host.de # FQDN=domain.name.of.this.host.de
# STATIC_IP=123.456.789.012 # STATIC_IP=123.456.789.012
@ -21,5 +20,11 @@ BOOT_PART_SIZE=500 # MiB
FS=BTRFS FS=BTRFS
FS_CHOSEN_MOUNT_OPTIONS=('noatime') 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 CPU_VENDOR=none
BIOS_TYPE=uefi BIOS_TYPE=uefi
# If set to "1", then the data, boot and luks partitions
# will be left mounted/opened after installation
LEAVE_MOUNTED=1

View File

@ -74,7 +74,7 @@ function partition() {
# #
# Create a partition with fat32 as the file system type and set the # Create a partition with fat32 as the file system type and set the
# esp flag on it. # 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" \ mkpart ESP fat32 2Mib "${BOOT_PART_SIZE}MiB" \
set 1 esp on \ set 1 esp on \
mkpart primary "${BOOT_PART_SIZE}MiB" 100% || return $? mkpart primary "${BOOT_PART_SIZE}MiB" 100% || return $?
@ -90,7 +90,7 @@ function partition() {
# #
# archwiki -> GRUB#GUID_Partition_Table_(GPT)_specific_instructions # archwiki -> GRUB#GUID_Partition_Table_(GPT)_specific_instructions
# https://www.gnu.org/software/grub/manual/grub/html_node/BIOS-installation.html#BIOS-installation # 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 \ mkpart primary 1MiB 2MiB \
set 1 bios_grub on \ set 1 bios_grub on \
mkpart primary 2MiB "${BOOT_PART_SIZE}MiB" \ mkpart primary 2MiB "${BOOT_PART_SIZE}MiB" \
@ -124,17 +124,17 @@ function format() {
# luks partition formatted and opened at DATA_PART # luks partition formatted and opened at DATA_PART
echo "Wiping old signatures from partitions ..." echo "Wiping old signatures from partitions ..."
wipefs "${BOOT_PART}" || return $? sudo wipefs "${BOOT_PART}" || return $?
wipefs "${LUKS_PART}" || return $? sudo wipefs "${LUKS_PART}" || return $?
echo "Formatting boot partition ${BOOT_PART} ..." echo "Formatting boot partition ${BOOT_PART} ..."
mkfs.fat -F32 "${BOOT_PART}" || return $? sudo mkfs.fat -F32 "${BOOT_PART}" || return $?
# Note: # Note:
# FDE: GRUB does support LUKS2 since this commit: https://git.savannah.gnu.org/cgit/grub.git/commit/?id=365e0cc3e7e44151c14dd29514c2f870b49f9755 # 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. # -> Using "--type luks1" is no longer required.
echo "Creating encrypted luks partition ${LUKS_PART} ..." 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 \ --cipher aes-xts-plain64 --key-size 512 --hash sha512 \
--iter-time 10000 --use-random "${LUKS_PART}" || return $? --iter-time 10000 --use-random "${LUKS_PART}" || return $?
@ -145,22 +145,22 @@ function format() {
DATA_PART="/dev/mapper/${luks_name}" DATA_PART="/dev/mapper/${luks_name}"
# open luks partition # 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} ..." echo "Formatting the data partition ${DATA_PART} ..."
case "${FS}" in case "${FS}" in
BTRFS) BTRFS)
mkfs.btrfs "${DATA_PART}" || return $? sudo mkfs.btrfs "${DATA_PART}" || return $?
;; ;;
EXT4) EXT4)
# archwiki -> Ext4#Enabling_metadata_checksums # archwiki -> Ext4#Enabling_metadata_checksums
mkfs.ext4 -O metadata_csum "${DATA_PART}" || return $? sudo mkfs.ext4 -O metadata_csum "${DATA_PART}" || return $?
;; ;;
F2FS) F2FS)
# archwiki -> F2FS#Creating_a_F2FS_file_system # archwiki -> F2FS#Creating_a_F2FS_file_system
# - requires f2fs-tools # - requires f2fs-tools
# - compression: "-O compression" and when mounting the filesystem, specify compress_algorithm=(lzo|lz4|zstd|lzo-rle) # - 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!" echo "Filesystem ${FS} is not yet supported!"