-
Notifications
You must be signed in to change notification settings - Fork 5
/
desktop-install.sh
executable file
·326 lines (267 loc) · 8.76 KB
/
desktop-install.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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
#!/usr/bin/env bash
set -e
echo "*** WARNING ****************************************************"
echo "* HAVE YOU PASSED IN THE PACKAGE FILES YOU WANT FOR INSTALL ? *"
echo "*** WARNING ****************************************************"
echo "AVAILABLE BLOCK DEVICES"
lsblk
echo -n "enter the block device's name (sda,nvme1): "
read -r blockdev
echo -n "efi booting or legacy (efi|legacy): "
read -r boottype
echo -n "main filesystem (xfs|ext4|btrfs): "
read -r filesystem
echo -n "nvme disk or regular (nvme|regular): "
read -r nvmedisk
echo -n "check blocks (yes|no (default)): "
read -r checkblocks
echo -n "give your default administrator username: "
read -r user
echo -n "give your full name: "
read -r fullname
echo -n "set your password: "
read -r password
if [[ "$blockdev" == "" ]]; then
echo "no blockdev given"
exit 1
fi
if [[ "$boottype" == "" ]]; then
echo "no boottype given"
exit 2
fi
if [[ "$filesystem" == "" ]]; then
echo "no filesystem given"
exit 4
fi
if [[ "$nvmedisk" == "" ]]; then
echo "no nvmedisk given"
exit 5
fi
if [[ "$checkblocks" == "" ]]; then
checkblocks="no"
fi
if [[ "$filesystem" == "btrfs" ]]; then
echo -n "btrfs read-only root? (yes|no (default)): "
read -r btrfsroroot
fi
if [[ "$btrfsroroot" == "yes" ]]; then
btrfsroroot=yes
else
btrfsroroot=no
fi
if [[ "$nvmedisk" == "nvme" ]]; then
partitionextra="p"
else
partitionextra=""
fi
# create random string to append to the keyfile and hostname
randstring="$(date +%s | sha256sum | base64 | head -c 8)"
if [[ "$checkblocks" == "yes" ]]; then
badblocks -c 10240 -s -w -t random -v "/dev/$blockdev"
fi
# force local update of archlinux-keyring
/usr/bin/archlinux-keyring-wkd-sync
if [[ "$boottype" == "efi" ]]; then
parted --script "/dev/$blockdev" \
mklabel gpt \
mkpart ESP fat32 0% 200MiB \
set 1 esp on \
set 1 legacy_boot on \
mkpart primary 200MiB 4296MiB \
mkpart primary 4296MiB 100%
efipart=1
# EFI Partition
mkfs.fat -F32 -n EFI "/dev/${blockdev}${partitionextra}${efipart}"
else
parted --script "/dev/$blockdev" \
mklabel gpt \
mkpart non-fs 0% 2MiB \
set 1 bios_grub on \
mkpart primary 2MiB 4098MiB \
mkpart primary 4098MiB 100% \
set 3 boot on
fi
swappart=2
rootpart=3
rootdev="/dev/${blockdev}${partitionextra}${rootpart}"
basepackagelist=("desktop-base-packages.txt")
if [[ "$filesystem" == "btrfs" ]]; then
basepackagelist+=("fs-btrfs-packages.txt")
pacman -Sy --noconfirm snapper
# "ROOT"
mkfs.btrfs -L ROOT "$rootdev"
mount "$rootdev" /mnt
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/srv
mkdir -p /mnt/usr
btrfs subvolume create /mnt/usr/local
btrfs subvolume create /mnt/var
# disable CoW on /var
chattr +C /mnt/var
umount /mnt
# write first snapshot info manually
mount -o subvol=root "$rootdev" /mnt
snapper --no-dbus -c root create-config /mnt
snapper create \
--read-write \
--cleanup-algorithm number \
--description "initial install"
umount /mnt
mount "$rootdev" /mnt
btrfs subvolume list -p /mnt
# root subvol id
rootsubvol=$(btrfs subvolume list -p /mnt | grep 'root/.snapshots/1/snapshot' | sed 's/ID \([0-9]\+\).*/\1/g')
btrfs subvolume set-default "$rootsubvol" /mnt
umount /mnt
rootmountoptions="rw,noatime,nodiratime,discard=async,compress=zstd"
mount -o $rootmountoptions "$rootdev" /mnt
mkdir -p /mnt/.snapshots
mount -o $rootmountoptions,subvol=root/.snapshots "$rootdev" /mnt/.snapshots
mkdir -p /mnt/home
mount -o $rootmountoptions,subvol=home "$rootdev" /mnt/home
mkdir -p /mnt/srv
mount -o $rootmountoptions,subvol=srv "$rootdev" /mnt/srv
mkdir -p /mnt/usr/local
mount -o $rootmountoptions,subvol=usr/local "$rootdev" /mnt/usr/local
mkdir -p /mnt/var
mount -o $rootmountoptions,subvol=var "$rootdev" /mnt/var
elif [[ "$filesystem" == "xfs" ]]; then
basepackagelist+=("fs-xfs-packages.txt")
mkfs.xfs -L ROOT "$rootdev"
rootmountoptions="rw,noatime,attr2,inode64,noquota,discard"
mount -o $rootmountoptions "$rootdev" /mnt
elif [[ "$filesystem" == "ext4" ]]; then
basepackagelist+=("fs-ext4-packages.txt")
mkfs.ext4 -L ROOT "$rootdev"
rootmountoptions="rw,noatime,data=ordered,discard"
mount -o $rootmountoptions "$rootdev" /mnt
else
echo "unsupported filesystem defined"
exit 1
fi
bootloaderpackage=grub
if [[ "$boottype" == "efi" ]]; then
bootloaderpackage="$bootloaderpackage efibootmgr"
mkdir -p /mnt/boot
mkdir -p /mnt/boot/efi
mount "/dev/${blockdev}${partitionextra}${efipart}" /mnt/boot/efi
mkdir -p /mnt/boot/efi/EFI/BOOT
else
mkdir -p /mnt/boot
fi
# ucode package
cpu_vendor="$(lscpu | grep 'Vendor' | awk '{ print $NF }')"
ucode_package=''
if [[ "GenuineIntel" == "$cpu_vendor" ]]; then
ucode_package="intel-ucode"
elif [[ "AuthenticAMD" == "$cpu_vendor" ]]; then
ucode_package="amd-ucode"
fi
# use our mirrorlist, not the one from the iso
cp ./etc/pacman.d/mirrorlist /etc/pacman.d/mirrorlist
# install packages
# shellcheck disable=SC2046
pacstrap -C ./etc/pacman.conf /mnt \
$(cat "${basepackagelist[@]}") \
$bootloaderpackage \
$ucode_package
# copy all etc extras
cp -a ./etc/ /mnt/
cp -a ./etc-desktop/* /mnt/etc/
chown root: -R /mnt/etc
if [[ "$filesystem" == "btrfs" ]]; then
cp -a /etc/conf.d/snapper \
/mnt/etc/conf.d/snapper
cp -a /etc/snapper/configs/root \
/mnt/etc/snapper/configs/root
sed -e 's/\(SUBVOLUME=\).*/\1"\/"/' \
-e 's/\(^NUMBER_LIMIT=\).*/\1"20"/' \
-e 's/\(^NUMBER_LIMIT_IMPORTANT=\).*/\1"5"/' \
-e 's/\(^TIMELINE_CREATE=\).*/\1"no"/' \
-i /mnt/etc/snapper/configs/root
# make sure the pacman db is on the root subvolume if btrfs is in use
sed -e 's/#\(DBPath.*=\).*/\1 \/opt\/pacman/' -i /mnt/etc/pacman.conf
mv /mnt/var/lib/pacman /mnt/opt/pacman
fi
# install the remaining packages (avoid gpg key issues with extra packages)
# shellcheck disable=SC2046
if [[ -n $1 ]]; then
arch-chroot /mnt \
pacman -Syu --noconfirm \
$(cat "$@")
fi
# generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
sed -e '/\s\+\/\s\+/d' -i /mnt/etc/fstab
# set timezone
ln -sf /usr/share/zoneinfo/Europe/Brussels /mnt/etc/localtime
arch-chroot /mnt hwclock --systohc
# generate locales for en_US
sed -e 's/#en_US/en_US/g' -e 's/#nl_BE/nl_BE/g' -i /mnt/etc/locale.gen
arch-chroot /mnt locale-gen
echo "LANG=en_US.UTF-8" > /mnt/etc/locale.conf
# keyboard
echo "KEYMAP=be-latin1" > /mnt/etc/vconsole.conf
echo "XKBLAYOUT=be" >> /mnt/etc/vconsole.conf
echo "XKBOPTIONS=terminate:ctrl_alt_bksp" >> /mnt/etc/vconsole.conf
# set hostname
echo "archlinux-$randstring" > /mnt/etc/hostname
echo "127.0.0.1 localhost archlinux-$randstring" >> /mnt/etc/hosts
echo "::1 localhost archlinux-$randstring" >> /mnt/etc/hosts
mkswap -L swap "/dev/${blockdev}${partitionextra}${swappart}"
(
echo ""
echo "/dev/${blockdev}${partitionextra}${swappart} none swap defaults 0 0"
) >> /mnt/etc/fstab
# bootloader installation
if [[ "$boottype" == "efi" ]]; then
arch-chroot /mnt grub-install \
--target=x86_64-efi \
--bootloader-id=GRUB \
--efi-directory=/boot/efi \
--boot-directory=/boot/efi/EFI/BOOT \
--removable \
--recheck
mkdir -p /mnt/boot/efi/EFI/BOOT/grub
else
arch-chroot /mnt grub-install \
--target=i386-pc \
--boot-directory=/boot \
--recheck \
"/dev/${blockdev}${partitionextra}"
fi
# bootloader extra cmd
eval "$(blkid -o export "/dev/${blockdev}${partitionextra}${rootpart}")"
ROOTUUID=$UUID
grubcmd="root=/dev/disk/by-uuid/$ROOTUUID"
## root filesystem flags
grubcmd="$grubcmd rootflags=$rootmountoptions"
if [[ "$btrfsroroot" == "yes" ]]; then
grubcmd="$grubcmd ro"
fi
grubcmd="${grubcmd//\//\\\/}"
grubcmd="$grubcmd mem_sleep_default=deep"
grubcmd="$grubcmd lockdown=integrity"
## add grub GRUB_CMDLINE_LINUX
sed -e "s/^\(GRUB_CMDLINE_LINUX=\).*/\1\"$grubcmd\"/" \
-e 's/^\(GRUB_CMDLINE_LINUX_DEFAULT=\).*/\1"loglevel=3"/' \
-e 's/^\(GRUB_TERMINAL_INPUT\)/#\1/' \
-i /mnt/etc/default/grub
if [[ "$boottype" == "efi" ]]; then
(
cd /mnt/boot
ln -s efi/EFI/BOOT/grub .
)
arch-chroot /mnt grub-mkconfig -o /boot/efi/EFI/BOOT/grub/grub.cfg
else
sed -e 's/^\(GRUB_GFXPAYLOAD_LINUX=\)/\1text/' \
-i /mnt/etc/default/grub
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
fi
arch-chroot /mnt dracut-rebuild || true
# finish the installation
cp -a create-user.sh create-admin-user.sh /mnt/root/
cp -a desktop-post-install.sh /mnt
arch-chroot /mnt /desktop-post-install.sh "$user" "$fullname" "$password"
rm /mnt/desktop-post-install.sh