forked from BlackIkeEagle/archlinux-reinstall
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall-server.sh
executable file
·238 lines (195 loc) · 6.76 KB
/
install-server.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
#!/usr/bin/env bash
set -e
echo "*** WARNING ****************************************************"
echo "* HAVE YOU PASSED IN THE PACKAGE FILES YOU WANT FOR INSTALL ? *"
echo "*** WARNING ****************************************************"
echo -n "enter the block device's name (sda,nvme1): "
read -a blockdev
echo -n "efi booting or legacy (efi|legacy): "
read -a boottype
echo -n "main filesystem (xfs|ext4|btrfs): "
read -a filesystem
echo -n "nvme disk or regular (nvme|regular): "
read -a nvmedisk
echo -n "check blocks (yes|no (default)): "
read -a checkblocks
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 [[ "$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 [[ "$boottype" == "efi" ]]; then
if [[ "$checkblocks" == "yes" ]]; then
badblocks -c 10240 -s -w -t random -v /dev/$blockdev
fi
parted --script /dev/$blockdev \
mklabel gpt \
mkpart primary fat32 0% 200MiB \
set 1 esp on \
set 1 legacy_boot on \
mkpart primary 200MiB 400MiB \
mkpart primary 400MiB 4496MiB \
mkpart primary 4496MiB 100%
efipart=1
bootpart=2
swappart=3
rootpart=4
# EFI Partition
mkfs.fat -F32 -n EFI /dev/${blockdev}${partitionextra}${efipart}
mkfs.ext2 -L boot /dev/${blockdev}${partitionextra}${bootpart}
else
if [[ "$checkblocks" == "yes" ]]; then
badblocks -c 10240 -s -w -t random -v /dev/$blockdev
fi
parted --script /dev/$blockdev \
mklabel msdos \
mkpart primary 0% 200MiB \
set 1 boot on \
mkpart primary 200MiB 4296MiB \
mkpart primary 4296MiB 100%
bootpart=1
swappart=2
rootpart=3
mkfs.ext2 -L boot /dev/${blockdev}${partitionextra}${bootpart}
fi
basepackagelist=("server-base-packages.txt")
if [[ "$filesystem" == "btrfs" ]]; then
basepackagelist+=("btrfs-packages.txt")
# "ROOT"
mkfs.btrfs -L ROOT /dev/${blockdev}${partitionextra}${rootpart}
mount /dev/${blockdev}${partitionextra}${rootpart} /mnt
mkdir -p /mnt/var
mkdir -p /mnt/var/lib
btrfs subvolume create /mnt/root
btrfs subvolume create /mnt/home
btrfs subvolume create /mnt/var/cache
btrfs subvolume create /mnt/var/lib/docker
btrfs subvolume list -p /mnt
umount /mnt
rootmountoptions="rw,noatime,nodiratime,ssd,space_cache,compress=lzo,subvol=root"
mount -o $rootmountoptions /dev/${blockdev}${partitionextra}${rootpart} /mnt
mkdir -p /mnt/home
mount -o rw,noatime,nodiratime,ssd,space_cache,compress=lzo,subvol=home /dev/${blockdev}${partitionextra}${rootpart} /mnt/home
mkdir -p /mnt/var/cache
mount -o rw,noatime,nodiratime,ssd,space_cache,compress=lzo,subvol=var/cache /dev/${blockdev}${partitionextra}${rootpart} /mnt/var/cache
mkdir -p /mnt/var/lib/docker
mount -o rw,noatime,nodiratime,ssd,space_cache,compress=lzo,subvol=var/lib/docker /dev/${blockdev}${partitionextra}${rootpart} /mnt/var/lib/docker
elif [[ "$filesystem" == "xfs" ]]; then
basepackagelist+=("xfs-packages.txt")
mkfs.xfs -L ROOT /dev/${blockdev}${partitionextra}${rootpart}
rootmountoptions="rw,noatime,attr2,inode64,noquota,discard"
mount -o $rootmountoptions /dev/${blockdev}${partitionextra}${rootpart} /mnt
elif [[ "$filesystem" == "ext4" ]]; then
basepackagelist+=("ext4-packages.txt")
mkfs.ext4 -L ROOT /dev/${blockdev}${partitionextra}${rootpart}
rootmountoptions="rw,noatime,data=ordered,discard"
mount -o $rootmountoptions /dev/${blockdev}${partitionextra}${rootpart} /mnt
else
echo "unsupported filesystem defined"
exit 1
fi
bootloaderpackage=grub
if [[ "$boottype" == "efi" ]]; then
bootloaderpackage="$bootloaderpackage efibootmgr"
mkdir -p /mnt/boot
mount /dev/${blockdev}${partitionextra}${bootpart} /mnt/boot
mkdir -p /mnt/boot/efi
mount /dev/${blockdev}${partitionextra}${efipart} /mnt/boot/efi
mkdir -p /mnt/boot/efi/EFI/archlinux
else
mkdir -p /mnt/boot
mount /dev/${blockdev}${partitionextra}${bootpart} /mnt/boot
fi
# install packages
if [[ ! -z $1 ]]; then
pacstrap -C ./etc/pacman.conf /mnt \
$(cat ${basepackagelist[@]}) \
$(cat "$@") \
$bootloaderpackage
else
pacstrap -C ./etc/pacman.conf /mnt \
$(cat ${basepackagelist[@]}) \
$bootloaderpackage
fi
# copy all etc extras
cp -a ./etc/ /mnt/
# generate fstab
genfstab -U /mnt >> /mnt/etc/fstab
# set timezone
ln -sf /usr/share/zoneinfo/UTC /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=us" > /mnt/etc/vconsole.conf
# set hostname
echo "archserver-$randstring" > /mnt/etc/hostname
echo "127.0.1.1 archserver-$randstring" >> /mnt/etc/hosts
# make sure firewalld uses iptables
#if [[ -e /mnt/etc/firewalld/firewalld.conf ]]; then
# sed -e 's/^\(FirewallBackend=\).*/\1iptables/' \
# -i /mnt/etc/firewalld/firewalld.conf
#fi
# encrypted swap
mkswap -L swap /dev/${blockdev}${partitionextra}${swappart}
# bootloader installation
if [[ "$boottype" == "efi" ]]; then
arch-chroot /mnt grub-install \
--target=x86_64-efi \
--boot-directory=/boot \
--efi-directory=/boot/efi \
--bootloader=archlinux \
--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 rootflags=$rootmountoptions"
grubcmd="${grubcmd//\//\\\/}"
## add grub GRUB_CMDLINE_LINUX
sed -e "s/^\(GRUB_CMDLINE_LINUX=\).*/\1\"$grubcmd\"/" \
-i /mnt/etc/default/grub
if [[ "$boottype" == "efi" ]]; then
arch-chroot /mnt grub-mkconfig -o /boot/efi/EFI/BOOT/grub/grub.cfg
else
arch-chroot /mnt grub-mkconfig -o /boot/grub/grub.cfg
fi
arch-chroot /mnt mkinitcpio -p linux || true
rm -f /mnt/etc/resolv.conf && \
ln -sf /run/systemd/resolve/resolv.conf /mnt/etc/resolv.conf
# finish the installation
cp -a server-post-install.sh /mnt
arch-chroot /mnt /server-post-install.sh
rm /mnt/server-post-install.sh