update arch linux installer
This commit is contained in:
parent
8b36ddf827
commit
3830c28b84
1 changed files with 193 additions and 0 deletions
193
archlinux/install.sh
Executable file
193
archlinux/install.sh
Executable file
|
@ -0,0 +1,193 @@
|
|||
#!/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
eprintln() {
|
||||
cat <<<"$@" 1>&2
|
||||
}
|
||||
|
||||
prompt() {
|
||||
variable=$1
|
||||
default=$2
|
||||
prompt=$3
|
||||
echo "$prompt"
|
||||
read -rep "> " -i "$default" "${variable?}"
|
||||
|
||||
}
|
||||
|
||||
invert() {
|
||||
value=$1
|
||||
((value ^= 1))
|
||||
echo $value
|
||||
}
|
||||
|
||||
# Get required user info
|
||||
## Check Network Status
|
||||
if [[ ! $(
|
||||
ping -c 1 archlinux.org
|
||||
invert $?
|
||||
) ]]; then
|
||||
eprintln 'Connect to internet then rerun this script'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
## get boot mode
|
||||
_is_uefi=$([[ -f /sys/firmware/efi/fw_platform_size ]] && echo 1 || echo 0)
|
||||
|
||||
## Disk info
|
||||
mapfile -t devices < <(lsblk --paths --output NAME,SiZE --noheadings --nodeps)
|
||||
|
||||
paste <(printf "%s\n" "${!devices[@]}") <(printf "%s\n" "${devices[@]}")
|
||||
prompt root_drive "" "Which device do you want to be root drive?"
|
||||
|
||||
prompt want_home "" "Do you want to store home on another drive? (0 | 1)"
|
||||
|
||||
if [[ "${want_home?}" -eq 1 ]]; then
|
||||
prompt home_drive "" "Which device do you want to be home drive?"
|
||||
prompt home_fmt "" "Do you want to format home? (0|1)"
|
||||
fi
|
||||
|
||||
prompt want_swap "" "Do you want a swap space? (0 | 1)"
|
||||
|
||||
if [[ "${want_swap?}" -eq 1 ]]; then
|
||||
prompt swap_size "2g" "Swap size. Default is 2g. (accepting k/m/g/e/p suffix)"
|
||||
fi
|
||||
|
||||
# Summary of what is going to happen and user confirmation
|
||||
|
||||
# Pre-installation
|
||||
part_boot=",+1G,C12A7328-F81F-11D2-BA4B-00A0C93EC93B"
|
||||
part_root=","
|
||||
root_dev=$(echo ${devices[$root_drive]} | cut -d' ' -f 1)
|
||||
[[ "${want_home:-0}" -eq 1 ]] &&
|
||||
home_dev=$(echo ${devices[$home_drive]} | cut -d' ' -f 1)
|
||||
|
||||
## Partition disk(s)
|
||||
printf "label: GPT\n$part_boot\n$part_root" | sfdisk "$root_dev"
|
||||
[[ "${home_fmt:-0}" -eq 1 ]] &&
|
||||
printf "label: GPT\n," | sfdisk "$home_dev"
|
||||
|
||||
## Format disk(s)
|
||||
mkfs.fat -F 32 "$root_dev"1
|
||||
mkfs.btrfs -f "$root_dev"2
|
||||
[[ "${home_fmt:-0}" -eq 1 ]] && {
|
||||
mkfs.btrfs -f "$home_dev"1
|
||||
}
|
||||
|
||||
## Configure root btrfs
|
||||
mount --mkdir "$root_dev"2 /mnt
|
||||
btrfs subvolume create /mnt/@
|
||||
btrfs subvolume create /mnt/@/.snapshots
|
||||
mkdir /mnt/@/.snapshots/1
|
||||
btrfs subvolume create /mnt/@/.snapshots/1/snapshot
|
||||
mkdir -p /mnt/@/boot/grub2/
|
||||
# btrfs subvolume create /mnt/@/boot/grub2/i386-pc
|
||||
# btrfs subvolume create /mnt/@/boot/grub2/x86_64-efi
|
||||
btrfs subvolume create /mnt/@/home
|
||||
btrfs subvolume create /mnt/@/opt
|
||||
btrfs subvolume create /mnt/@/root
|
||||
btrfs subvolume create /mnt/@/srv
|
||||
btrfs subvolume create /mnt/@/tmp
|
||||
mkdir /mnt/@/usr/
|
||||
btrfs subvolume create /mnt/@/usr/local
|
||||
btrfs subvolume create /mnt/@/var
|
||||
chattr +C /mnt/@/var
|
||||
|
||||
cat <<-'EOF' >>/mnt/@/.snapshots/1/info.xml
|
||||
<?xml version="1.0"?>
|
||||
<snapshot>
|
||||
<type>single</type>
|
||||
<num>1</num>
|
||||
<date>$DATE</date>
|
||||
<description>first root filesystem</description>
|
||||
</snapshot>
|
||||
EOF
|
||||
|
||||
btrfs subvolume set-default "$(btrfs subvolume list /mnt | grep "@/.snapshots/1/snapshot" | grep -oP '(?<=ID )[0-9]+')" /mnt
|
||||
|
||||
umount /mnt
|
||||
|
||||
# Mount Disk(s)
|
||||
mount --mkdir "$root_dev"2 /mnt
|
||||
mount --mkdir "$root_dev"2 /mnt/.snapshots -o subvol=@/.snapshots
|
||||
# mount --mkdir "$root_dev"2 /mnt/boot/grub2/i386-pc -o subvol=@/boot/grub2/i386-pc
|
||||
# mount --mkdir "$root_dev"2 /mnt/boot/grub2/x86_64-efi -o subvol=@/boot/grub2/x86_64-efi
|
||||
mount --mkdir "$root_dev"2 /mnt/home -o subvol=@/home
|
||||
mount --mkdir "$root_dev"2 /mnt/opt -o subvol=@/opt
|
||||
mount --mkdir "$root_dev"2 /mnt/root -o subvol=@/root
|
||||
mount --mkdir "$root_dev"2 /mnt/srv -o subvol=@/srv
|
||||
mount --mkdir "$root_dev"2 /mnt/tmp -o subvol=@/tmp
|
||||
mount --mkdir "$root_dev"2 /mnt/usr/local -o subvol=@/usr/local
|
||||
mount --mkdir "$root_dev"2 /mnt/var -o subvol=@/var
|
||||
mount --mkdir -o uid=0,gid=0,fmask=0077,dmask=0077 "$root_dev"1 /mnt/boot
|
||||
[[ "${want_home:-0}" -eq 1 ]] &&
|
||||
mount --mkdir "$home_dev"1 /mnt/home
|
||||
|
||||
### swap
|
||||
[[ "${want_swap:-0}" -eq 1 ]] && {
|
||||
btrfs subvolume create /mnt/swap
|
||||
btrfs filesystem mkswapfile --uuid clear /mnt/swap/file --size "${swap_size?}"
|
||||
swapon /mnt/swap/file
|
||||
}
|
||||
|
||||
# Installation
|
||||
## Get and set mirrors in order of rate
|
||||
reflector --save "/etc/pacman.d/mirrorlist" --protocol https,rsync --sort rate --threads 24 --latest 50
|
||||
## install essential packages
|
||||
pacstrap -K /mnt base linux-zen linux-firmware amd-ucode snapper
|
||||
# Configure Installation
|
||||
## fstab
|
||||
genfstab -U /mnt | tail -32 >> /mnt/etc/fstab
|
||||
## chroot
|
||||
arch-chroot /mnt bash << CHROOT
|
||||
### time
|
||||
ln -sf /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
|
||||
hwclock --systohc
|
||||
|
||||
### localization
|
||||
sed -i 's/#en_US\\./en_US./' /etc/locale.gen
|
||||
locale-gen
|
||||
printf "LANG=en_US.UTF-8" >>/etc/locale.conf
|
||||
|
||||
### network configuratio.n
|
||||
printf "zesktop" >>/etc/hostname
|
||||
cat << 'ETHERNET' >/etc/systemd/network/20-ethernet.network
|
||||
[Match]
|
||||
Name=en*
|
||||
Name=eth*
|
||||
|
||||
[Network]
|
||||
DHCP=yes
|
||||
ETHERNET
|
||||
|
||||
### initramfs
|
||||
sed --in-place 's/#COMPRESSION=\"zstd\"/COMPRESSION=\"zstd\"/' /etc/mkinitcpio.conf
|
||||
mkinitcpio -P
|
||||
|
||||
### root password
|
||||
printf "password\npassword" | passwd
|
||||
|
||||
### Boot loader
|
||||
bootctl install
|
||||
cat << 'EOF' >/boot/loader/loader.conf
|
||||
default arch-zen.conf
|
||||
timeout 4
|
||||
console-mode max
|
||||
editor no
|
||||
EOF
|
||||
cat << 'EOF' >/boot/loader/entries/arch-zen.conf
|
||||
title Arch Linux Zen
|
||||
linux /vmlinuz-linux-zen
|
||||
initrd /amd-ucode.img
|
||||
initrd /initramfs-linux-zen.img
|
||||
options root="UUID=$(blkid "$root_dev"2 | cut -d'"' -f2)" rw
|
||||
EOF
|
||||
|
||||
### Setup snapper
|
||||
umount /.snapshots
|
||||
rm -rfv /.snapshots
|
||||
snapper --no-dbus -c root create-config /
|
||||
mount --mkdir "$root_dev"2 /.snapshots -o subvol=@/.snapshots
|
||||
CHROOT
|
||||
|
||||
# Unmount disk(s) and reboot
|
||||
# Post-installation???
|
Loading…
Reference in a new issue