-
Notifications
You must be signed in to change notification settings - Fork 2
/
install-void.sh
executable file
·207 lines (166 loc) · 5.84 KB
/
install-void.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
#!/usr/bin/env bash
#
# Script to install my main production machine (Void Linux).
#
# Author: David Anguita <david@davidanguita.name>
#
# Run me with:
#
# # ./install-void.sh
set -e
# Creating a bootable drive:
#
# - Download latest iso from: https://alpha.de.repo.voidlinux.org/live/current/
# - # dd if=void-live-x86_64-<version>.iso of=/dev/sdX && sync
#
# Running this script:
#
# - Log in as root (root:voidlinux)
# - # xbps-install -Sy xbps curl
# - # curl -L https://l.davidanguita.name/install-void.sh -o install.sh
# - # chmod +x install.sh
# - # ./install.sh
#
# Post-installation notes:
#
# - You may need to start the DHCP client service to enable networking right
# before running the kickstart script:
# $ sudo ln -s /etc/sv/dhcpcd /var/service/
# - Once your Internet connection is ready, run the kickstart script and follow
# instructions:
# $ ./kickstart.sh
# -- Configuration. Set values carefully.
# Block device in which the system will be installed on.
device=/dev/sda # It typically is `/dev/nvme0n1` in NVMe drives.
# See https://docs.voidlinux.org/installation/live-images/partitions.html#swap-partitions.
swap_partition_size=2G
# Kernel version the system will boot on.
# https://github.com/void-linux/void-packages/blob/956c03a63f935fea658ebec164e3de1bc94402c3/srcpkgs/linux/template#L3
kernel_version=linux6.6
# Time zone in `zoneinfo` format.
time_zone=Europe/Madrid
# Locale.
lang=en_US.UTF-8
# Hostname.
hostname=void
# Initial user. Will be created automatically with `sudo` privileges.
user=david
user_full_name="David Anguita"
# XBPS repo to download the base packages from. Default should be good.
xbps_repo_url=https://repo-default.voidlinux.org/current
# Kickstart script. Can be left blank.
kickstart_script_url=https://l.davidanguita.name/kickstart-void.sh
# Do not change these values unless you know what you're doing.
boot_partition="${device}1" # Change it to "${device}p1" in NVMe drives.
root_partition="${device}2" # Change it to "${device}p2" in NVMe drives.
# -- End of Configuration.
say() {
printf "\n[$(date --iso-8601=seconds)] %s\n" "$1"
}
# shellcheck disable=SC2317
confirm() {
while true; do
read -r -p "$1 (y/[n]): " answer
case $answer in
[Yy]* ) return 0; break;;
[Nn]* ) return 1; break;;
"" ) return 1; break;;
* ) echo "Please answer yes or no.";;
esac
done
}
chroot_run() {
chroot /mnt "$@"
}
# This is assumming you're using a EFI system. Legacy BIOS systems are not
# supported in this script yet.
say "Setting up partitions"
sed -e 's/\s*\([\+0-9a-zA-Z]*\).*/\1/' << EOF | fdisk ${device}
g # create GPT partition table
n # new partition
1 # partition number 1
# default - start at beginning of disk
+512M # Assign 512 MB to the EFI system partition
t # change partition type
1 # select EFI System type
n # new partition
2 # partion number 2
# default, start immediately after preceding partition
# default, extend partition to end of disk
p # print the in-memory partition table
w # write the partition table
q # and we're done
EOF
say "Setting up file systems"
cryptsetup luksFormat ${root_partition}
cryptsetup luksOpen ${root_partition} crypt
pvcreate /dev/mapper/crypt
vgcreate vg /dev/mapper/crypt
lvcreate -L ${swap_partition_size} -n swap vg
lvcreate -l 100%FREE -n root vg
# boot partition: FAT32.
mkfs.vfat -F 32 ${boot_partition}
# root partition: EXT4.
mkfs.ext4 /dev/mapper/vg-root
# swap partition.
mkswap /dev/mapper/vg-swap
swapon /dev/mapper/vg-swap
mount /dev/mapper/vg-root /mnt
mkdir -p /mnt/boot
mount ${boot_partition} /mnt/boot
say "Installing packages"
# Authentication mechanism, needed during installation
xbps-install -Sy -R ${xbps_repo_url} pam
# Base system
xbps-install -Sy -R ${xbps_repo_url} -r /mnt \
base-system lvm2 cryptsetup grub-x86_64-efi sudo
say "Preparing for chroot"
mkdir -p /mnt/{dev,proc,sys}
mount -R /proc /mnt/proc
mount -R /dev /mnt/dev
mount -R /sys /mnt/sys
say "Setting up root user"
passwd -R /mnt root
chown root:root /mnt
chmod 755 /mnt
say "Setting up hostname"
echo ${hostname} > /mnt/etc/hostname
say "Setting up static networking"
echo "127.0.1.1 ${hostname}.localdomain ${hostname}" >> /mnt/etc/hosts
say "Setting up time zone"
ln -s /usr/share/zoneinfo/${time_zone} /mnt/etc/localtime
hwclock --systohc
say "Setting up locales"
echo "LANG=${lang}" > /mnt/etc/locale.conf
echo "${lang} UTF-8" >> /mnt/etc/default/libc-locales
xbps-reconfigure -r /mnt -f glibc-locales
say "Setting up mount points"
boot_partition_uuid=$(blkid -o export ${boot_partition} | awk -F'=' '/^UUID/{ print $2 }')
cat <<- EOF | tee /mnt/etc/fstab
tmpfs /tmp tmpfs defaults,nosuid,nodev 0 0
UUID=${boot_partition_uuid} /boot vfat defaults 0 0
/dev/mapper/vg-root / ext4 defaults 0 0
/dev/mapper/vg-swap none swap sw 0 0
EOF
say "Installing bootloader (grub)"
mkdir -p /mnt/boot/grub
chroot_run grub-mkconfig -o /boot/grub/grub.cfg
chroot_run grub-install --target=x86_64-efi --efi-directory=/boot --bootloader-id=void --recheck
echo 'GRUB_CMDLINE_LINUX="rd.auto=1"' >> /mnt/etc/default/grub
echo hostonly=true > /mnt/etc/dracut.conf.d/hostonly.conf
xbps-reconfigure -r /mnt -f ${kernel_version}
sed -i.bak -E \
"/%wheel ALL=\(ALL:ALL\) ALL/s/^#[[:space:]]//g" \
/mnt/etc/sudoers
say "Adding initial user: ${user} (${user_full_name})"
useradd -R /mnt -m -s /bin/bash -U -G wheel -c "${user_full_name}" ${user}
passwd -R /mnt ${user}
if [ -n "${kickstart_script_url}" ]; then
say "Downloading kickstart script to user's home directory"
curl -L ${kickstart_script_url} -o /mnt/home/${user}/kickstart.sh
chroot_run chown ${user}:${user} /home/${user}/kickstart.sh
chroot_run chmod +x /home/${user}/kickstart.sh
fi
say "Finishing up"
umount -R /mnt
if confirm "All done. Power off?"; then poweroff; fi