Skip to content

Instantly share code, notes, and snippets.

@vitezfh
Last active March 6, 2024 20:22
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save vitezfh/065340a1a222441dde30302c00f96054 to your computer and use it in GitHub Desktop.
Save vitezfh/065340a1a222441dde30302c00f96054 to your computer and use it in GitHub Desktop.
Void Linux on the Raspberry Pi - SD-card install script for Headless use! Only tested on Zero W
#!/bin/bash
# This makes a readily bootable Voidlinux SD-Card for the raspberrypi
# Sets up some configs, making the Pi connect to wifi and sshd
#
# First boot up takes a very long time (5+ mins even) on a Zero W. Really give it time.
# For remedy on subsequent booting see:
# https://wiki.voidlinux.org/Raspberry_Pi#Enabling_hardware_RNG_device
# SD-Card:
device="/dev/mmcblk0"
# .tar.xz void image
image="void-rpi*-PLATFORMFS-*.tar.xz"
# The wpa_supplicant.conf to copy over to the pi, so it can boot up
# ready to connect:
wpa_supplicant="/etc/wpa_supplicant/wpa_supplicant.conf"
rootfs="/tmp/rootfs"
[ ! -z "$1" ] && device=$1
[ ! -z "$2" ] && image=$2
help_msg(){
echo "sudo $0 <mmc device> <tar.xz image>"
}
if [[ $UID != 0 ]]; then
echo "Please run this script with sudo:"
echo "sudo $0 $*"
exit 1
fi
echo "This is not a safe script, read it through before running.
Type yes to continue:
"
read ok
[ "$ok" != "yes" ] && exit 1
$([ "$@" -e "-h" ] || [ "$@" -e "--help" ]) && help_msg && exit
if ! [ -e "$device" ]; then
echo "Device $device not found"
exit
fi
parted --script $device \
mktable msdos \
mkpart primary fat32 2048s 256MB \
toggle 1 boot \
mkpart primary ext4 256MB 100%
mkfs.vfat $device"p1"
mkfs.ext4 -O '^has_journal' $device"p2"
mkdir $rootfs
mount $device"p2" $rootfs
mkdir $rootfs"/boot"
mount $device"p1" $rootfs"/boot"
tar xvfJp $image -C $rootfs
sync
echo '/dev/mmcblk0p1 /boot vfat defaults 0 0' >> $rootfs/etc/fstab
cp $wpa_supplicant $rootfs/etc/wpa_supplicant/wpa_supplicant.conf
echo "raspberrypi" > $rootfs/etc/hostname
echo "
ln -s /etc/sv/wpa_supplicant /etc/runit/runsvdir/default/
ln -s /etc/sv/dhcpcd /etc/runit/runsvdir/default/
ln -s /etc/sv/sshd /etc/runit/runsvdir/default/
ln -s /etc/sv/chronyd /etc/runit/runsvdir/default/
reboot
" > $rootfs/etc/first-run.sh
chmod +x $rootfs/etc/first-run.sh
echo "
[ -f '/etc/first-run.sh' ] && sh /etc/first-run.sh && rm /etc/first-run.sh
" >> $rootfs/etc/rc.local
# Needed for logging in if after updating, one forgets to create a user
# LibreSSL blocks root login
echo "PermitRootLogin yes" >> $rootfs/etc/ssh/sshd_config
echo "
root ALL=(ALL) ALL
%wheel ALL=(ALL) NOPASSWD: ALL
%sudo ALL=(ALL) ALL
" > $rootfs/etc/sudoers.d/auto
echo "
gpu_mem=16
" >> $rootfs/boot/config.txt
echo 'FORCEFSCK="-f"' >> $rootfs/etc/rc.conf
umount $rootfs"/boot" $rootfs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment