Last active
March 23, 2023 20:29
-
-
Save fhill2/914b72318d5639ab075b09808e525485 to your computer and use it in GitHub Desktop.
arch-install-ext4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -uo pipefail | |
trap 's=$?; echo "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR | |
# if re running, unmount anything at /mnt first | |
is_mounted() { | |
mount | awk -v DIR="$1" '{if ($3 == DIR) { exit 0}} ENDFILE{exit -1}' | |
} | |
if is_mounted "/mnt"; then | |
# cant use umount -l, as it doesnt error if the drive is "busy", meaning parted fails below | |
umount -l /mnt | |
fi | |
### Get infomation from user ### | |
hostname=$(dialog --stdout --inputbox "Enter hostname" 0 0) || exit 1 | |
clear | |
: ${hostname:?"hostname cannot be empty"} | |
user="f1" | |
password="." | |
devicelist=$(lsblk -dplnx size -o name,size | grep -Ev "boot|rpmb|loop" | tac) | |
device=$(dialog --stdout --menu "Select installtion disk" 0 0 0 ${devicelist}) || exit 1 | |
clear | |
echo "ERASING $device ... Ctrl+C to cancel.." | |
sleep 3s # incase I picked the wrong drive.... | |
### Set up logging ### | |
exec 1> >(tee "stdout.log") | |
exec 2> >(tee "stderr.log") | |
parted --script "${device}" -- mklabel gpt \ | |
mkpart ESP fat32 1Mib 129MiB \ | |
set 1 boot on \ | |
mkpart primary ext4 129MiB 100% | |
echo "$device" | |
# Simple globbing was not enough as on one device I needed to match /dev/mmcblk0p1 | |
# but not /dev/mmcblk0boot1 while being able to match /dev/sda1 on other devices. | |
part_boot="$(ls ${device}* | grep -E "^${device}p?1$")" | |
part_root="$(ls ${device}* | grep -E "^${device}p?2$")" | |
echo "$part_boot" | |
echo "$part_root" | |
wipefs "${part_boot}" | |
wipefs "${part_root}" | |
mkfs.fat -F32 "${part_boot}" | |
mkfs.ext4 "${part_root}" | |
fatlabel "${part_boot}" "boot" | |
e2label "${part_root}" "root" | |
# btrfs filesystem label "${part_root}" "root" | |
mount "${part_root}" /mnt | |
mkdir /mnt/boot | |
mount "${part_boot}" /mnt/boot | |
#echo "$part_boot" | |
#echo "$part_root" | |
pacstrap /mnt base base-devel neovim networkmanager linux linux-headers zsh linux-firmware mkinitcpio nfs-utils git --noconfirm --needed | |
genfstab -t LABEL /mnt >> /mnt/etc/fstab | |
echo "${hostname}" > /mnt/etc/hostname | |
arch-chroot /mnt ln -sf /usr/share/zoneinfo/Europe/London /etc/localtime | |
arch-chroot /mnt hwclock --systohc | |
sed -i 's/^%wheel ALL=(ALL) NOPASSWD: ALL/# %wheel ALL=(ALL) NOPASSWD: ALL/' /mnt/etc/sudoers | |
sed -i 's/^# %wheel ALL=(ALL) ALL/%wheel ALL=(ALL) ALL/' /mnt/etc/sudoers | |
echo "en_GB.UTF-8 UTF-8" > /mnt/etc/locale.gen | |
echo "LANG=en_GB.UTF-8" > /mnt/etc/locale.conf | |
arch-chroot /mnt locale-gen | |
cat >>/mnt/etc/hosts <<EOF | |
127.0.0.1 localhost | |
::1 localhost | |
127.0.0.1 $hostname.localdomain $hostname | |
192.168.0.22 arch-desk | |
EOF | |
arch-chroot /mnt useradd -mU -s /usr/bin/zsh -G wheel "$user" | |
arch-chroot /mnt chsh -s /usr/bin/zsh | |
arch-chroot /mnt echo "$user:$password" | chpasswd | |
arch-chroot /mnt echo "root:$password" | chpasswd | |
# echo "$user:$password" | chpasswd --root /mnt | |
# echo "root:$password" | chpasswd --root /mnt | |
arch-chroot /mnt bootctl --path=/boot install | |
arch-chroot /mnt echo "default arch-*" > /boot/loader/loader.conf | |
cat > /boot/loader/entries/arch.conf<< EOF | |
title Arch Linux | |
linux /vmlinuz-linux | |
initrd /initramfs-linux.img | |
options root=${part_root} rw | |
EOF | |
arch-chroot /mnt systemctl enable NetworkManager | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment