fix various arch issues
[automated-distro-installer] / arch-pxe
1 #!/bin/bash -lx
2
3 # Setup arch pxe boot server from the base image.
4 # Requires manually downloading image to /a/opt, and set it's name below.
5
6 set -eE -o pipefail
7 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
8
9 x="$(readlink -f "$BASH_SOURCE")"
10 script_dir="${x%/*}"
11 cd /a/opt
12 iso="archlinux-2016.05.01-dual"
13 sfs=$iso/arch/x86_64/airootfs.sfs
14 rm -rf $iso
15 ex $iso.iso
16 sed -i -f - $iso/arch/boot/syslinux/archiso_pxe64.cfg <<EOF
17 1itotaltimeout 1
18 /^LABEL arch64_nfs/a menu default
19 s/^APPEND .*/\0 script=arch-iso-init.sh/
20 EOF
21 # based on https://blog.chendry.org/2015/02/06/automating-arch-linux-installation.html
22 # and https://wiki.archlinux.org/index.php/Remastering_the_Install_ISO
23
24 s rm -rf squashfs-root # remove any existing folder
25 s unsquashfs $sfs
26 s mkdir -p squashfs-root/root/.ssh
27 s chmod 755 squashfs-root/root/.ssh
28 s cp ~/.ssh/id_rsa.pub squashfs-root/root/.ssh/authorized_keys
29
30 s cp $script_dir/arch-iso-init.sh squashfs-root/root
31 s rm $sfs
32 s mksquashfs squashfs-root $sfs -comp xz
33 # file transfer to wrt is slow, so remove some useless files
34 rm $iso/arch/i686/airootfs.sfs $iso/arch/boot/i686/archiso.img
35 c $(dirname $sfs); md5sum ${sfs##*/} > airootfs.md5; b
36
37 # seems if you've done a pxe boot, mounted the nfs,
38 # then shutdown, it's still busy.
39 ssh wrt "/etc/init.d/nfsd stop; \
40 { ! mount | grep /run/archiso/bootmnt || umount /run/archiso/bootmnt; } && \
41 rm -rf /mnt/usb/$iso"
42 scp -r $iso wrt:/mnt/usb
43 ssh wrt "cd /mnt/usb && rm -f tftpboot && ln -s $iso tftpboot"
44
45 # The default settings in the installer expect to find the NFS at /run/archiso/bootmnt
46
47 pxe-server arch
48
49 # background:
50 # great documentation at https://wiki.archlinux.org/index.php/PXE
51 # background: arch can do netboot like ubuntu etc, but the docs look a little complicated, so fuck it,
52 # we use nfs cuz it's easy
53
54 rm -rf $iso
55 s rm -rf squashfs-root