add devbyid dependency
[automated-distro-installer] / arch-init-chroot
1 #!/bin/bash -x
2 # Copyright (C) 2016 Ian Kelling
3
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
8
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 set -eE -o pipefail
18 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
19
20 # note, when I did genfstab, i
21 # neeeded to to do for x in mv /etc/*.pacorig; do mv $x ${x%.pacorig}; done
22
23 pacman -Syu
24
25 [[ -L /etc/localtime ]] || ln -s /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
26 l=en_US.UTF-8
27 echo "$l UTF-8" > /etc/locale.gen
28 locale-gen
29 echo "LANG=$l" > /etc/locale.conf
30 # if coming from windows, and you had to set the time, do this
31 # hwclock --systohc --utc
32
33 # A password is required to access the volume:
34 # Command requires device and ampped name as arguments
35
36 # If we were using btrfs raid, we supposedly would need this.
37 # # add btrfs as module instead of hook due to
38 # # https://wiki.archlinux.org/index.php/Btrfs,
39 # # https://bugs.archlinux.org/task/42884
40 # # disabled, as with just the module, startup spammed something about
41 # # command takes a device name and something else.
42 # sed -ri --follow-symlinks '/^ *MODULES *=.*btrfs/!s/^( *MODULES *=.*)"/\1 btrfs"/' /etc/mkinitcpio.conf
43 # # remove extra space
44 # sed -ri --follow-symlinks 's/^( *MODULES *=[^"]*)" */\1"/' /etc/mkinitcpio.conf
45
46
47
48
49 # for desktop without full fs encryption, use this:
50 #cat > /etc/crypttab <<'EOF'
51 #tmp /dev/lvm/tmp /dev/urandom tmp,cipher=aes-xts-plain64,size=256
52
53 # otgherwise ERROR: file not found: `fsck.btrfs'
54 pacman -S --noconfirm btrfs-progs
55
56 pacman -S --noconfirm grub gptfdisk
57
58
59 shopt -s extglob
60 echo "$0: fstab:"
61 cat /etc/fstab
62 # https://wiki.archlinux.org/index.php/Dm-crypt/System_configuration#Boot_loader
63 # if cryptdevice was lvm, it woulde be in this format,
64 # where x2-vg is from lvdisplay, VG Name field.
65 # cryptdevice=/dev/disk/by-uuid/585dff23-136f-446f-815f-01053b70c957:x2-vg
66 # but, if you are using your own fstab, it seems you just give it a name,
67 # which will be the crypt device name under /dev/mapper/
68 # https://wiki.archlinux.org/index.php/GRUB#Additional_arguments
69
70
71 root_devs=( ${ROOT_PARTITIONS} )
72 first_root_dev=${root_devs[0]}
73
74
75 k_args=(
76 cryptdevices=${ROOT_PARTITIONS// /,}
77 root=/dev/mapper/crypt_dev_${first_root_dev##*/}
78 resume=${first_root_dev%[0-9]}$swapn
79 )
80 extra_encrypt_hooks=()
81
82
83 # If we have more than 1 to decrypt, arch wiki lead me onto
84 # a sort of hacky way run the encrypt hook multiple times.
85
86 base=/usr/lib/initcpio
87
88
89 # https://wiki.archlinux.org/index.php/Dm-crypt/Encrypting_an_entire_system#Configuring_mkinitcpio_2
90 # used to have lvm2 after encrypt for lvm, but not using lvm anymore
91 for x in encrypt btrfs; do
92 sed -ri --follow-symlinks -f - /etc/mkinitcpio.conf <<EOF
93 /^ *HOOKS.*\b$x\b/!s/^( *HOOKS=.*)filesystems/\1$x filesystems/
94 EOF
95 done
96
97 # this is the default file, otherwise you use cryptkey=device:fstype:path
98 sed -ri --follow-symlinks -f - /etc/mkinitcpio.conf <<EOF
99 s#^\s*FILES=.*#FILES="/crypto_keyfile.bin"#
100 EOF
101 echo "$0: FILES:"
102 grep FILES /etc/mkinitcpio.conf
103 k_args="${k_args[*]}"
104 echo "$0: grub cmdline additions: $k_args"
105 sed -ri --follow-symlinks -f - /etc/default/grub <<EOF
106 \%$k_args%!s%^ *GRUB_CMDLINE_LINUX_DEFAULT *= *"%\0$k_args %
107 EOF
108
109 mkinitcpio -p linux
110
111
112 # remove the default quiet arg.
113 # this doesn't seem to affect anything, so leave it alone.
114 #sed -ri --follow-symlinks 's/^( *GRUB_CMDLINE_LINUX_DEFAULT *= *.*) ?\bquiet\b(.*)/\1\2/' /etc/default/grub
115
116 # https://wiki.archlinux.org/index.php/GRUB#Install_to_disk
117 for dev in $BOOT_DEVICE; do
118 grub-install --recheck $dev
119 done
120 grub-mkconfig -o /boot/grub/grub.cfg
121 # gtk2 is an optional dependency of unison.
122 # I know Im gonna want the gui, so just doing it now.
123 pacman -S --noconfirm openssh rsync
124
125
126 pacman -S --noconfirm sudo
127
128 . /a/bin/fai/fai-wrapper
129 /a/bin/fai/fai/config/distro-install-common/end
130 systemctl enable sshd
131
132 rm -rf /home/ian/.ssh
133 cp -r /root/.ssh /home/ian
134 chown -R ian:ian /home/ian/.ssh
135 # the groups recommended by
136 # https://wiki.archlinux.org/index.php/Users_and_groups#Group_list
137 usermod -aG games,rfkill,users,uucp,wheel ian
138
139
140 pacman -S --noconfirm net-tools # for route
141 # get the mac of the interface used by the broadcast route.
142 mac=$(cat /sys/class/net/$(route -n | sed -rn 's/^0\.0\.0\.0.*[[:space:]]([^[:space:]]+)[[:space:]]*$/\1/p')/address)
143
144
145 # simple bridge.
146 cat > /etc/systemd/network/wired.network <<EOF
147 [Match]
148 Name=en*
149
150 [Network]
151 Bridge=br0
152 EOF
153
154 cat > /etc/systemd/network/br0.network <<EOF
155 [Match]
156 Name=br0
157
158 [Network]
159 DHCP=ipv4
160 EOF
161
162 cat > /etc/systemd/network/br0.netdev <<EOF
163 [NetDev]
164 Name=br0
165 Kind=bridge
166 # use the same mac as the physical port,
167 # which is mapped to a static ip in our dhcp server.
168 MACAddress=$mac
169 EOF
170
171
172
173
174 for x in networkd resolved; do systemctl enable systemd-$x; done