Skip to content

Instantly share code, notes, and snippets.

@mjcc30
Forked from vitezfh/create-pi.sh
Last active March 6, 2024 21:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mjcc30/d7a631f347712a6cdd2085c88a36d4d6 to your computer and use it in GitHub Desktop.
Save mjcc30/d7a631f347712a6cdd2085c88a36d4d6 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/sda"
part1="${device}1"
part2="${device}2"
rootfs="/tmp/rootfs"
hostname="pi"
# cp from iso folder
image="void-rpi-aarch64-PLATFORMFS-20230628.tar.xz"
# generate by wpa_passphrase Bbox-11D7A152 ZC61hJYM13xaKHsakC > wpa_supplicant.conf
wpa_supplicant="wpa_supplicant.conf"
# rc.conf
rc_conf="rc.conf"
[ -n "$1" ] && device=$1
[ -n "$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 $part1
mkfs.ext4 -O '^has_journal' $part2
rm -rf $rootfs
mkdir $rootfs
mount $part2 $rootfs
mkdir "${rootfs}/boot"
mount $part1 "${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
sed -i 's/^#KEYMAP="[a-zA-Z]*"/KEYMAP="fr"/' $rootfs/etc/rc.conf
echo "$hostname" >$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/
ln -sf /usr/share/zoneinfo/Europe/Paris /etc/localtime
echo $hostname > /etc/hostname
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 """
# Overclocking
gpu_mem=16
#arm_freq=2300
#gpu_freq=750
#over_voltage=14
#force_turbo=1
""" >>$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