-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-preinstall.sh
147 lines (129 loc) · 6.3 KB
/
0-preinstall.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/bin/bash
echo "-------------------------------------------------"
echo "Starting Pre-install "
echo "-------------------------------------------------"
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
ISO=$(curl -4 ifconfig.co/country-iso)
echo "SCRIPT_DIR=${SCRIPT_DIR}" >> ${HOME}/arch-base/.env
echo "ISO=${ISO}" >> ${HOME}/arch-base/.env
timedatectl set-ntp true
echo -e "-----------------------------------------------"
echo -e "Setting up ${ISO} mirrors for faster downloads "
echo -e "-----------------------------------------------"
sed -i 's/^#Para/Para/' /etc/pacman.conf
mv /etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist.bak
reflector -a 48 -c ${ISO} -f 5 -l 20 --sort rate --save /etc/pacman.d/mirrorlist
echo "-------------------------------------------------"
echo "-------select your disk to format----------------"
echo "-------------------------------------------------"
lsblk
read -p "Please enter disk to work on: (example /dev/sda): " DISK
echo "THIS WILL FORMAT AND DELETE ALL DATA ON THE DISK"
read -p "Are you sure you want to continue (Y/N):" FORMAT
case ${FORMAT} in
y|Y|yes|Yes|YES)
echo "-------------------------------------------------"
echo -e "\nFormatting disk...\n$HR"
echo "-------------------------------------------------"
sgdisk -Z ${DISK}
sgdisk -a 2048 -o ${DISK}
sgdisk -n 1::+260M --typecode=1:ef00 ${DISK}
sgdisk -n 2::-0 --typecode=2:8300 ${DISK}
if [[ ${DISK} =~ "nvme" ]]; then
EFI_PARTITION="${DISK}p1"
ROOT_PARTITION="${DISK}p2"
else
EFI_PARTITION="${DISK}1"
ROOT_PARTITION="${DISK}2"
fi
echo "EFI_PARTITION=${EFI_PARTITION}" >> ${HOME}/arch-base/.env
echo "ROOT_PARTITION=${ROOT_PARTITION}" >> ${HOME}/arch-base/.env
echo "-------------------------------------------------"
echo "Setting up LUKS encryption "
echo "-------------------------------------------------"
cryptsetup -y -v --type luks1 luksFormat ${ROOT_PARTITION}
echo "-------------------------------------------------"
echo "Opening LUKS volume "
echo "-------------------------------------------------"
CRYPTROOT_NAME="cryptroot"
CRYPTROOT_PATH="/dev/mapper/${CRYPTROOT_NAME}"
cryptsetup open ${ROOT_PARTITION} ${CRYPTROOT_NAME}
echo "CRYPTROOT_NAME=${CRYPTROOT_NAME}" >> ${HOME}/arch-base/.env
echo "CRYPTROOT_PATH=${CRYPTROOT_PATH}" >> ${HOME}/arch-base/.env
echo "-------------------------------------------------"
echo "Creating filesystem "
echo "-------------------------------------------------"
mkfs.fat -F32 ${EFI_PARTITION}
mkfs.btrfs ${CRYPTROOT_PATH}
mount ${CRYPTROOT_PATH} /mnt
btrfs subvolume create /mnt/@
btrfs subvolume create /mnt/@home
btrfs subvolume create /mnt/@snapshots
btrfs subvolume create /mnt/@log
btrfs subvolume create /mnt/@cache
btrfs subvolume create /mnt/@swap
umount /mnt
esac
echo "-------------------------------------------------"
echo "Setting up mount points "
echo "-------------------------------------------------"
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@ ${CRYPTROOT_PATH} /mnt
mkdir -p /mnt/boot/efi
mkdir -p /mnt/{home,swap,.snapshots}
mkdir -p /mnt/var/{log,cache}
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@home ${CRYPTROOT_PATH} /mnt/home
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@log ${CRYPTROOT_PATH} /mnt/var/log
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@cache ${CRYPTROOT_PATH} /mnt/var/cache
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@swap ${CRYPTROOT_PATH} /mnt/swap
mount -o noatime,compress=zstd,space_cache,discard=async,subvol=@snapshots ${CRYPTROOT_PATH} /mnt/.snapshots
mount ${EFI_PARTITION} /mnt/boot/efi
if ! grep -qs '/mnt' /proc/mounts; then
echo "-------------------------------------------------"
echo "!!! ERROR setting up mount points !!! "
echo "!!! Cannot continue with installation !!! "
echo "-------------------------------------------------"
echo "Rebooting in 3 Seconds ..." && sleep 1
echo "Rebooting in 2 Seconds ..." && sleep 1
echo "Rebooting in 1 Second ..." && sleep 1
reboot now
fi
echo "-------------------------------------------------"
echo "Installing base packages "
echo "-------------------------------------------------"
pacstrap /mnt base linux linux-firmware btrfs-progs git vim --noconfirm --needed
echo "-------------------------------------------------"
echo "Generating fstab file "
echo "-------------------------------------------------"
genfstab -U /mnt >> /mnt/etc/fstab
echo "-------------------------------------------------"
echo "Setting up swapfile "
echo "-------------------------------------------------"
TOTAL_MEM=$(awk '/MemTotal/ {printf( "%d\n", $2 / 1024 )}' /proc/meminfo)
SWAPFILE_SIZE=$((${TOTAL_MEM}+2048))
truncate -s 0 /mnt/swap/swapfile
chattr +C /mnt/swap/swapfile
btrfs property set /mnt/swap/swapfile compression none
dd if=/dev/zero of=/mnt/swap/swapfile bs=1M count=${SWAPFILE_SIZE} status=progress
chmod 600 /mnt/swap/swapfile
mkswap /mnt/swap/swapfile
swapon /mnt/swap/swapfile
echo "/swap/swapfile none swap defaults 0 0" >> /mnt/etc/fstab
echo "-------------------------------------------------"
echo "Setting up LUKS keyfile "
echo "-------------------------------------------------"
dd bs=512 count=4 if=/dev/random of=/mnt/crypto_keyfile.bin iflag=fullblock
chmod 600 /mnt/crypto_keyfile.bin
chmod 600 /mnt/boot/initramfs-linux*
echo "-------------------------------------------------"
echo "Adding the LUKS keyfile "
echo "Enter your disk encryption password when prompted"
echo "-------------------------------------------------"
cryptsetup luksAddKey ${ROOT_PARTITION} /mnt/crypto_keyfile.bin
echo "-------------------------------------------------"
echo "Copying Arch-Base scripts to installation "
echo "-------------------------------------------------"
cp -R ${SCRIPT_DIR} /mnt/
cp /etc/pacman.d/mirrorlist /mnt/etc/pacman.d/mirrorlist
echo "-------------------------------------------------"
echo "Pre-install Complete "
echo "-------------------------------------------------"