Install script and kernel configuration for a musl based VoidLinux minimalist installation for a KVM guest acting as a gateway/firewall

install.sh 2.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. #!/bin/bash
  2. set -e
  3. PKG_LIST="base-voidstrap-busybox syslinux runit-void iptables wpa_supplicant linux4.14-gw"
  4. HOSTNAME="gw.internal"
  5. KEYMAP="fr_CH"
  6. TIMEZONE="Europe/Zurich"
  7. LANG="en_US.UTF-8"
  8. # Install requirements
  9. xbps-install -y -S -f parted
  10. # Wipe /dev/vda and create partitions
  11. dd if=/dev/zero of=/dev/vda bs=1M count=100
  12. parted /dev/vda mklabel msdos
  13. parted -a optimal /dev/vda mkpart primary 2048s 100%
  14. parted /dev/vda set 1 boot on
  15. # Format filesystems
  16. mkfs.ext4 -L root -O ^64bit /dev/vda1
  17. # Mount them
  18. mount /dev/vda1 /mnt
  19. for dir in dev proc sys; do
  20. mkdir /mnt/${dir}
  21. mount -o bind /${dir} /mnt/${dir}
  22. done
  23. # Now install void
  24. mkdir -p /mnt/var/db/xbps/keys/
  25. cp -a /var/db/xbps/keys/* /mnt/var/db/xbps/keys/
  26. XBPS_ARCH=x86_64-musl xbps-install -y -S --repository=http://repos.mauras.ch/voidlinux/musl/ --repository=http://repo.voidlinux.eu/current/musl -r /mnt $PKG_LIST
  27. # Do a bit of customization
  28. chroot /mnt passwd -d root
  29. echo $HOSTNAME > /mnt/etc/hostname
  30. echo "TIMEZONE=${TIMEZONE}" >> /mnt/etc/rc.conf
  31. echo "KEYMAP=${KEYMAP}" >> /mnt/etc/rc.conf
  32. echo "TTYS=2" >> /mnt/etc/rc.conf
  33. echo "LANG=$LANG" > /mnt/etc/locale.conf
  34. # Add fstab entries
  35. cat << EOF >> /mnt/etc/fstab
  36. LABEL=root / ext4 rw,relatime,data=ordered,discard 0 0
  37. EOF
  38. # Link /var/tmp > /tmp
  39. rm -rf /mnt/var/tmp
  40. ln -s /tmp /mnt/var/tmp
  41. # Set kernel synlink for extlinux
  42. KERN_VER="$(xbps-query -s linux4.14 | cut -f 2 -d '-' | cut -f 1 -d ' ')"
  43. mkdir -p /mnt/boot/extlinux/
  44. chroot /mnt ln -s /boot/vmlinuz-${KERN_VER} /boot/extlinux/vmlinuz
  45. # Install extlinux
  46. dd bs=440 count=1 conv=notrunc if=/mnt/usr/share/syslinux/mbr.bin of=/dev/vda
  47. cat << EOF >> /mnt/boot/extlinux/extlinux.conf
  48. PROMPT 1
  49. TIMEOUT 20
  50. DEFAULT void
  51. LABEL void
  52. LINUX vmlinuz
  53. APPEND root=/dev/vda1 rw
  54. EOF
  55. #cp /mnt/usr/share/syslinux/*.c32 /mnt/boot/extlinux/
  56. chroot /mnt extlinux -i /boot/extlinux
  57. # Now add customization to installation
  58. if [ -d ./custom ]; then
  59. cp -r ./custom /mnt/tmp
  60. # If we detect any .sh let's run them in the chroot
  61. for SHFILE in /mnt/tmp/custom/*.sh; do
  62. chroot /mnt sh /tmp/custom/$(basename $SHFILE)
  63. done
  64. # Then cleanup chroot
  65. rm -rf /mnt/tmp/custom
  66. fi