|
|
@@ -39,13 +39,10 @@ function preChrootStep {
|
|
|
|
|
|
printf "Arch installation\n"
|
|
|
read -p "System drive: " DISK
|
|
|
+ read -p
|
|
|
read -p "Hostname: " HOSTNAME
|
|
|
read -p "Username: " USERNAME
|
|
|
PASSWORD=$(openssl passwd -6) || exit $?
|
|
|
- printf "Generate ssh key\n"
|
|
|
- ssh-keygen -f /tmp/id_ed25519 -t ed25519 -C "${USERNAME}@${HOSTNAME}" -q || exit $?
|
|
|
- SSH_PUB=$(cat /tmp/id_ed25519.pub)
|
|
|
- SSH_PRIV=$(cat /tmp/id_ed25519)
|
|
|
|
|
|
LOGFILE="archInstall.$(date +%Y%m%d-%H%M%S).log"
|
|
|
|
|
|
@@ -72,56 +69,56 @@ function preChrootStep {
|
|
|
|
|
|
printf "Creating partitions\n" | tee -a $LOGFILE
|
|
|
(
|
|
|
- echo o # New partition table
|
|
|
+ echo g # New partition table
|
|
|
echo n # New partition
|
|
|
echo p # Primary partition
|
|
|
echo 1 # Partition number
|
|
|
echo # First sector (use default)
|
|
|
- echo +300M # Last sector
|
|
|
+ echo +1024M # Last sector
|
|
|
echo n # New partition
|
|
|
echo p # Primary partition
|
|
|
echo 2 # Partition number
|
|
|
echo # First sector (use default)
|
|
|
echo # Last sector (use default)
|
|
|
+ echo t # Set type
|
|
|
+ echo 1 # Select partition
|
|
|
+ echo 1 # Set type EFI
|
|
|
+ echo t # Select partition
|
|
|
+ echo 2 # Selection partition
|
|
|
+ echo 20 # Set type Linux file system
|
|
|
echo w # Write changes
|
|
|
) | fdisk -W always ${DISK} >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- BOOTPART="${DISK}1"
|
|
|
- BTRFSPART="${DISK}2"
|
|
|
+ BOOTPART="${DISK}p1"
|
|
|
+ ROOTPART="${DISK}p2"
|
|
|
|
|
|
- printf "Creating filesystems\n" | tee -a $LOGFILE
|
|
|
- mkfs.fat ${BOOTPART} >> $LOGFILE 2>&1 || exit $?
|
|
|
- mkfs.btrfs ${BTRFSPART} >> $LOGFILE 2>&1 || exit $?
|
|
|
-
|
|
|
- printf "Mounting btrfs partition\n" | tee -a $LOGFILE
|
|
|
- mount ${BTRFSPART} /mnt >> $LOGFILE 2>&1 || exit $?
|
|
|
-
|
|
|
- printf "Creating btrfs subvolumes\n" | tee -a $LOGFILE
|
|
|
- btrfs subvolume create /mnt/@root >> $LOGFILE 2>&1 || exit $?
|
|
|
- btrfs subvolume create /mnt/@home >> $LOGFILE 2>&1 || exit $?
|
|
|
- btrfs subvolume create /mnt/@log >> $LOGFILE 2>&1 || exit $?
|
|
|
- btrfs subvolume create /mnt/@swap >> $LOGFILE 2>&1 || exit $?
|
|
|
+ printf "Creating LUKS2 container\n" | tee -a $LOGFILE
|
|
|
+ cryptsetup luksFormat --type luks2 ${ROOTPART} >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- printf "Unmounting btrfs partition\n" | tee -a $LOGFILE
|
|
|
- umount /mnt >> $LOGFILE 2>&1
|
|
|
+ printf "Decrypt LUKS2 container\n" | tee -a $LOGFILE
|
|
|
+ cryptsetup open ${ROOTPART} cryptlvm >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- printf "Mounting root\n" | tee -a $LOGFILE
|
|
|
- mount -o defaults,relatime,compress=zstd,subvol=@root ${BTRFSPART} /mnt >> $LOGFILE 2>&1 || exit $?
|
|
|
+ printf "Setup LVM volumes\n" | tee -a $LOGFILE
|
|
|
+ pvcreate /dev/mapper/cryptlvm >> $LOGFILE 2>&1 || exit $?
|
|
|
+ vgcreate VolGroup1 /dev/mapper/cryptlvm >> $LOGFILE 2>&1 || exit $?
|
|
|
+ lvcreate -l 100%FREE VolGroup1 -n root
|
|
|
+ lvreduce -L -256M VolGroup1/root >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- printf "Creating mount directories\n" | tee -a $LOGFILE
|
|
|
- mkdir -p /mnt/boot/efi /mnt/home /mnt/var/log /mnt/swap >> $LOGFILE 2>&1 || exit $?
|
|
|
+ printf "Creating filesystems\n" | tee -a $LOGFILE
|
|
|
+ mkfs.fat -F32 ${BOOTPART} >> $LOGFILE 2>&1 || exit $?
|
|
|
+ mkfs.ext4 /dev/Volgroup1/root >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- printf "Mounting volumes\n" | tee -a $LOGFILE
|
|
|
- mount ${BOOTPART} /mnt/boot/efi >> $LOGFILE 2>&1 || exit $?
|
|
|
- mount ${BTRFSPART} -o defaults,relatime,compress=zstd,subvol=@home /mnt/home >> $LOGFILE 2>&1 || exit $?
|
|
|
- mount ${BTRFSPART} -o defaults,relatime,compress=zstd,subvol=@log /mnt/var/log >> $LOGFILE 2>&1 || exit $?
|
|
|
- mount ${BTRFSPART} -o defaults,relatime,compress=zstd,subvol=@swap /mnt/swap >> $LOGFILE 2>&1 || exit $?
|
|
|
+ printf "Mount filesystems\n" | tee -a $LOGFILE
|
|
|
+ mount /dev/VolGroup1/root /mnt
|
|
|
+ mkdir -p /mnt/efi
|
|
|
+ mount ${BOOTPART} /mnt/efi
|
|
|
|
|
|
printf "Creating swap file\n" | tee -a $LOGFILE
|
|
|
- btrfs filesystem mkswapfile --size 8G /mnt/swap/swapfile >> $LOGFILE 2>&1 || exit $?
|
|
|
- swapon /mnt/swap/swapfile
|
|
|
+ SWAPSIZE=$(free --giga | grep Mem: | awk '{printf "%dG", $2 * 1.5}')
|
|
|
+ mkswap -U clear --size $SWAPSIZE --file /mnt/swapfile >> $LOGFILE 2>&1 || exit $?
|
|
|
+ swapon /mnt/swapfile >> $LOGFILE 2>&1 || exit $?
|
|
|
|
|
|
- PACSTRAPPKGS="base base-devel linux linux-firmware btrfs-progs grub efibootmgr networkmanager sudo sed git ansible"
|
|
|
+ PACSTRAPPKGS="base linux linux-firmware linux-headers networkmanager efibootmgr vim sudo sed git"
|
|
|
|
|
|
printf "Checking CPU manufacturer\n" | tee -a $LOGFILE
|
|
|
CPU=$(lscpu | grep "^Vendor ID:" | awk '{ print $3 }')
|
|
|
@@ -144,11 +141,11 @@ function preChrootStep {
|
|
|
function chrootStep {
|
|
|
checkVariables
|
|
|
|
|
|
- printf "Setting up time\n"
|
|
|
+ printf "Setting up time\n" | tee -a $LOGFILE
|
|
|
ln -sf /usr/share/zoneinfo/Europe/Stockholm /etc/localtime || exit $?
|
|
|
hwclock --systohc || exit $?
|
|
|
|
|
|
- printf "Setting up locale\n"
|
|
|
+ printf "Setting up locale\n" | tee -a $LOGFILE
|
|
|
sed -i -e 's/^#\(en_US.UTF-8\)/\1/' /etc/locale.gen || exit $?
|
|
|
sed -i -e 's/^#\(sv_SE.UTF-8\)/\1/' /etc/locale.gen || exit $?
|
|
|
locale-gen >&2 || exit $?
|
|
|
@@ -168,24 +165,14 @@ function chrootStep {
|
|
|
useradd -m $USERNAME -G wheel >&2 || exit $?
|
|
|
echo "${USERNAME}:${PASSWORD}" | chpasswd -e >&2 || exit $?
|
|
|
|
|
|
- printf "Add user ssh key" | tee -a $LOGFILE
|
|
|
- (umask 066; mkdir /home/${USERNAME}/.ssh)
|
|
|
- (umask 066; echo "${SSH_PRIV}" > /home/${USERNAME}/.ssh/id_ed25519)
|
|
|
- (umask 022; echo "${SSH_PUB}" > /home/${USERNAME}/.ssh/id_ed25519.pub)
|
|
|
- chown -R ${USERNAME}:${USERNAME} /home/${USERNAME}/.ssh
|
|
|
-
|
|
|
- printf "Setting temporary root password\n"
|
|
|
+ printf "Setting temporary root password\n" | tee -a $LOGFILE
|
|
|
echo "root:root" | chpasswd >&2 || exit $?
|
|
|
|
|
|
- printf "Starting and enabling NetworkManager\n"
|
|
|
+ printf "Starting and enabling NetworkManager\n" | tee -a $LOGFILE
|
|
|
systemctl enable NetworkManager >&2 || exit $?
|
|
|
systemctl start NetworkManager >&2 || exit $?
|
|
|
|
|
|
- printf "Installing GRUB\n"
|
|
|
- grub-install --target=x86_64-efi --efi-directory=/boot/efi --bootloader-id=GRUB >&2 || exit $?
|
|
|
- grub-mkconfig -o /boot/grub/grub.cfg >&2 || exit $?
|
|
|
-
|
|
|
- printf "Exiting chroot\n"
|
|
|
+ printf "Exiting chroot\n" | tee -a $LOGFILE
|
|
|
exit
|
|
|
}
|
|
|
|
|
|
@@ -193,7 +180,7 @@ function postChrootStep {
|
|
|
printf "Cleanup\n" | tee -a $LOGFILE
|
|
|
cp $LOGFILE /mnt/$LOGFILE
|
|
|
cd /
|
|
|
- swapoff /mnt/swap/swapfile
|
|
|
+ swapoff /mnt/swapfile
|
|
|
umount -R /mnt
|
|
|
}
|
|
|
|