-
Notifications
You must be signed in to change notification settings - Fork 6
/
02-install.sh
executable file
·278 lines (233 loc) · 6.12 KB
/
02-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
#!/bin/bash
set -e
exec &> >(tee "install.log")
# Debug
if [[ "$1" == "debug" ]]
then
set -x
debug=1
fi
print () {
echo -e "\n\033[1m> $1\033[0m\n"
if [[ -n "$debug" ]]
then
read -rp "press enter to continue"
fi
}
# Root dataset
root_dataset=$(cat /tmp/root_dataset)
# Set mirror and architecture
REPO=https://alpha.de.repo.voidlinux.org/current
ARCH=x86_64
# Copy keys
print 'Copy xbps keys'
mkdir -p /mnt/var/db/xbps/keys
cp /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
### Install base system
print 'Install Void Linux'
XBPS_ARCH=$ARCH xbps-install -y -S -r /mnt -R "$REPO" \
base-system \
void-repo-nonfree \
# Init chroot
print 'Init chroot'
mount --rbind /sys /mnt/sys && mount --make-rslave /mnt/sys
mount --rbind /dev /mnt/dev && mount --make-rslave /mnt/dev
mount --rbind /proc /mnt/proc && mount --make-rslave /mnt/proc
# Disable gummiboot post install hooks, only installs for generate-zbm
echo "GUMMIBOOT_DISABLE=1" > /mnt/etc/default/gummiboot
# Install packages
print 'Install packages'
packages=(
intel-ucode
zfs
zfsbootmenu
efibootmgr
gummiboot # required by zfsbootmenu
chrony # ntp
cronie # cron
seatd # minimal seat management daemon, required by sway
acpid # power management
socklog-void # syslog daemon
iwd # wifi daemon
dhclient
openresolv # dns
git
ansible
)
XBPS_ARCH=$ARCH xbps-install -y -S -r /mnt -R "$REPO" "${packages[@]}"
# Set hostname
read -r -p 'Please enter hostname : ' hostname
echo "$hostname" > /mnt/etc/hostname
# Configure zfs
print 'Copy ZFS files'
cp /etc/hostid /mnt/etc/hostid
cp /etc/zfs/zpool.cache /mnt/etc/zfs/zpool.cache
cp /etc/zfs/zroot.key /mnt/etc/zfs
# Configure iwd
cat > /mnt/etc/iwd/main.conf <<"EOF"
[General]
UseDefaultInterface=true
EnableNetworkConfiguration=true
EOF
# Configure DNS
cat >> /mnt/etc/resolvconf.conf <<"EOF"
resolv_conf=/etc/resolv.conf
name_servers_append="1.1.1.1 9.9.9.9"
name_server_blacklist="192.168.*"
EOF
# Enable ip forward
cat > /mnt/etc/sysctl.conf <<"EOF"
net.ipv4.ip_forward = 1
EOF
# Prepare locales and keymap
print 'Prepare locales and keymap'
echo 'KEYMAP=fr' > /mnt/etc/vconsole.conf
echo 'fr_FR.UTF-8 UTF-8' > /mnt/etc/default/libc-locales
echo 'LANG="fr_FR.UTF-8"' > /mnt/etc/locale.conf
# Configure system
cat >> /mnt/etc/rc.conf << EOF
KEYMAP="fr"
TIMEZONE="Europe/Paris"
HARDWARECLOCK="UTC"
EOF
# Configure dracut
print 'Configure dracut'
cat > /mnt/etc/dracut.conf.d/zol.conf <<"EOF"
hostonly="yes"
nofsck="yes"
add_dracutmodules+=" zfs "
omit_dracutmodules+=" btrfs resume "
install_items+=" /etc/zfs/zroot.key "
EOF
### Configure username
print 'Set your username'
read -r -p "Username: " user
### Chroot
print 'Chroot to configure services'
chroot /mnt/ /bin/bash -e <<EOF
# Configure DNS
resolvconf -u
# Configure services
ln -s /etc/sv/dhcpcd-eth0 /etc/runit/runsvdir/default/
ln -s /etc/sv/iwd /etc/runit/runsvdir/default/
ln -s /etc/sv/chronyd /etc/runit/runsvdir/default/
ln -s /etc/sv/crond /etc/runit/runsvdir/default/
ln -s /etc/sv/dbus /etc/runit/runsvdir/default/
ln -s /etc/sv/seatd /etc/runit/runsvdir/default/
ln -s /etc/sv/acpid /etc/runit/runsvdir/default/
ln -s /etc/sv/socklog-unix /etc/runit/runsvdir/default/
ln -s /etc/sv/nanoklogd /etc/runit/runsvdir/default/
# Generates locales
xbps-reconfigure -f glibc-locales
# Add user
zfs create zroot/data/home/${user}
useradd -m ${user} -G network,wheel,socklog,video,audio,_seatd,input
chown -R ${user}:${user} /home/${user}
# Configure fstab
grep efi /proc/mounts > /etc/fstab
EOF
# Configure fstab
print 'Configure fstab'
cat >> /mnt/etc/fstab <<"EOF"
tmpfs /dev/shm tmpfs rw,nosuid,nodev,noexec,inode64 0 0
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
efivarfs /sys/firmware/efi/efivars efivarfs defaults 0 0
EOF
# Set root passwd
print 'Set root password'
chroot /mnt /bin/passwd
# Set user passwd
print 'Set user password'
chroot /mnt /bin/passwd "$user"
# Configure sudo
print 'Configure sudo'
cat > /mnt/etc/sudoers <<EOF
root ALL=(ALL) ALL
$user ALL=(ALL) ALL
Defaults rootpw
EOF
### Configure zfsbootmenu
# Create dirs
mkdir -p /mnt/efi/EFI/ZBM /etc/zfsbootmenu/dracut.conf.d
# Generate zfsbootmenu efi
print 'Configure zfsbootmenu'
cat > /mnt/etc/zfsbootmenu/config.yaml <<EOF
Global:
ManageImages: true
BootMountPoint: /efi
DracutConfDir: /etc/zfsbootmenu/dracut.conf.d
Components:
Enabled: false
EFI:
ImageDir: /efi/EFI/ZBM
Versions: false
Enabled: true
Kernel:
CommandLine: ro quiet loglevel=0
Prefix: vmlinuz
EOF
# Add keymap to dracut
cat > /mnt/etc/zfsbootmenu/dracut.conf.d/keymap.conf <<EOF
install_optional_items+=" /etc/cmdline.d/keymap.conf "
EOF
mkdir -p /mnt/etc/cmdline.d/
cat > /mnt/etc/cmdline.d/keymap.conf <<EOF
rd.vconsole.keymap=fr
EOF
# Set cmdline
zfs set org.zfsbootmenu:commandline="ro quiet nowatchdog net.ifnames=0 zswap.enabled=0" zroot/ROOT/"$root_dataset"
# Generate ZBM
print 'Generate zbm'
chroot /mnt/ /bin/bash -e <<"EOF"
# Export locale
export LANG="fr_FR.UTF-8"
# Generate initramfs, zfsbootmenu
xbps-reconfigure -fa
EOF
# Set DISK
if [[ -f /tmp/disk ]]
then
DISK=$(cat /tmp/disk)
else
print 'Select the disk you installed on:'
select ENTRY in $(ls /dev/disk/by-id/);
do
DISK="/dev/disk/by-id/$ENTRY"
echo "Creating boot entries on $ENTRY."
break
done
fi
# Create UEFI entries
print 'Create efi boot entries'
modprobe efivarfs
mountpoint -q /sys/firmware/efi/efivars \
|| mount -t efivarfs efivarfs /sys/firmware/efi/efivars
if efibootmgr | grep ZFSBootMenu
then
for entry in $(efibootmgr | grep ZFSBootMenu | sed -E 's/Boot([0-9]+).*/\1/')
do
efibootmgr -B -b "$entry"
done
fi
efibootmgr --disk "$DISK" \
--part 1 \
--create \
--label "ZFSBootMenu Backup" \
--loader "\EFI\ZBM\vmlinuz-backup.efi" \
--verbose
efibootmgr --disk "$DISK" \
--part 1 \
--create \
--label "ZFSBootMenu" \
--loader "\EFI\ZBM\vmlinuz.efi" \
--verbose
# Umount all parts
print 'Umount all parts'
umount /mnt/efi
umount -l /mnt/{dev,proc,sys}
zfs umount -a
# Export zpool
print 'Export zpool'
zpool export zroot
# Finish
echo -e '\e[32mAll OK\033[0m'