-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchroot.sh
More file actions
103 lines (89 loc) · 2.83 KB
/
chroot.sh
File metadata and controls
103 lines (89 loc) · 2.83 KB
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
#!/usr/bin/bash
set -eux
notice() {
set +x
printf '\e[32m%s\n\e[0m' "$@"
set -x
}
notice "Setting up locale and timezone."
ln -sf /usr/share/zoneinfo/Australia/Sydney /etc/localtime
hwclock --systohc
sed -i '/en_AU.UTF-8/s/#//' /etc/locale.gen
locale-gen
echo LANG=en_AU.UTF-8 > /etc/locale.conf
echo KEYMAP=dvorak > /etc/vconsole.conf
notice "Setting up networking."
echo "archvm$(date +%Y%m%d)" > /etc/hostname
echo "
127.0.0.1 localhost
::1 localhost
127.0.1.1 archvm.localdomain archvm
10.0.2.2 vmhost" > /etc/hosts
notice "Setting up root account."
echo root:root | chpasswd
notice "Disabling DNSSEC."
# Some corporate DNS servers don't play well with DNSSEC.
echo DNSSEC=false >> /etc/systemd/resolved.conf
notice "Setting up DNS for dhcpcd."
echo "static domain_name_servers=8.8.8.8 8.8.4.4" >> /etc/dhcpcd.conf
echo "#static domain_name_servers=10.140.21.86" >> /etc/dhcpcd.conf
notice "Setting shutdown timeout."
echo "DefaultTimeoutStartSec=30s" >> /etc/systemd/system.conf
echo "DefaultTimeoutStopSec=30s" >> /etc/systemd/system.conf
notice "Setting up NTP."
systemctl enable systemd-timesyncd.service
notice "Setting up swap."
# TODO: This isn't idempotent, and fails on second run.
dd if=/dev/zero of=/swapfile bs=1M count=4096 status=progress
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
echo "/swapfile none swap defaults 0 0" >> /etc/fstab
notice "Installing guest modules."
# Guest modules set up separately from other packages due to provider
# dependencies.
#
# I've had some problems executing this. The error message is:
#
# "Signature is unknown trust"
#
# Solution was to:
#
# rm -rf /etc/pacman.d/gnupg
# pacman-key --init
# pacman-key --populate archlinux
#
if [ "$(uname -m)" == x86_64 ]; then
pacman --noconfirm -S virtualbox-guest-utils-nox
fi
notice "Installing extra packages."
# These packages are the minimum needed for rebooting, connecting via SSH, and
# git cloning additional setup scripts as a non-root user.
pacman --noconfirm -S dhcpcd openssh sudo git
systemctl enable dhcpcd.service
systemctl enable sshd.service
echo "
Defaults passwd_timeout=0
%wheel ALL=(ALL) ALL
petsta ALL=(ALL) NOPASSWD: ALL
" >> /etc/sudoers
notice "Creating user."
useradd -m petsta
echo "petsta:petsta" | chpasswd
gpasswd -a petsta wheel
# Set up systemd-boot as the bootloader. A bootloader is used rather than
# directly booting via EFISTUB, since the virtualised UEFI boot menu in
# Parallels and VirtualBox is not easy to use.
notice "Installing bootloader."
bootctl install
[ "$(uname -m)" == "aarch64" ] && vmlinuz="Image"
[ "$(uname -m)" == "x86_64" ] && vmlinuz="vmlinuz-linux"
[ -z "${vmlinuz:-}" ] && echo "unsupported: $(uname -m)" && exit 1
echo "timeout 2" > /boot/loader/loader.conf
echo "
title Arch Linux
linux /${vmlinuz}
initrd /initramfs-linux.img
options root=$part2 rw
" > /boot/loader/entries/arch.conf
bootctl list