Skip to content

Instantly share code, notes, and snippets.

@lukassup
Last active May 18, 2022 19:44
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 lukassup/3db7d67e82866af7bac46753c0a5701d to your computer and use it in GitHub Desktop.
Save lukassup/3db7d67e82866af7bac46753c0a5701d to your computer and use it in GitHub Desktop.
Network booting RetroPie on Raspberry Pi 4

Diskless RetroPie on Raspberry Pi 4

This should work fine when booting to in ARMv7 mode (32bit) - currently only version of RetroPie.

AArch64 mode (64bit) uses U-Boot and I couldn't set it up yet...

  1. Install Raspbian to an SD Card and boot your Raspberry Pi 4

     TODO
    
  2. Find your Raspberry Pi 4 serial number, will be referred to as $SERIAL later

     TODO
    
  3. Enable Network Booting for Raspberry Pi

     TODO
    
  4. Setup NFS shares for boot and root partitions on the NFS server

     192.168.0.10:/tftpboot/$SERIAL/     # /boot
     192.168.0.10:/pi4-$SERIAL/          # /
    

With network booting enabled Raspberry Pi tries to load files from /tftpboot/$SERIAL/ by default. It's configurable with DHCP options but lets stick to defaults here.

  1. Setup TFTP server (eg dnsmasq, dhcpd, opentftpd, etc) on NFS server for /tftpboot

  2. Setup your DHCP server to provide DHCP options for you Raspberry Pi 4

     # vendor-specific
     option-43='Raspberry Pi Boot   '  # trailing spaces, very important
    
     # vendor-class
     option-60='PXEClient'
    
     # tftp-server-name
     option-66='192.168.0.10'         # NFS/TFTP server
     # in case your DHCP server and TFTP server are on different hosts
    
  3. Setup directories

     mkdir -p ~/raspberry/{iso,nfs}root/boot
    
  4. Download latest Retropie image

     cd ~/raspberry/
     curl -sSLO https://github.com/RetroPie/RetroPie-Setup/releases/download/4.8/retropie-buster-4.8-rpi4_400.img.gz
    
  5. Create loopback devices from partitions in the image, mount filesystems

     sudo kpartx -v -a ~/raspberry/retropie-buster-4.8-rpi4_400.img
     sudo mount /dev/mapper/loop0p2 ~/raspberry/isoroot
     sudo mount /dev/mapper/loop0p1 ~/raspberry/isoroot/boot
    
  6. Mount NFS shares

     cd ~/raspberry
     sudo mount -t nfs 192.168.0.10:/pi4-$SERIAL/ ./nfsroot/
     sudo mkdir -p nfsroot/boot
     sudo mount -t nfs 192.168.0.10:/tftpboot/$SERIAL/ ./nfsroot/boot/
    
  7. Copy files from ISO into NFS

     cd ~/raspberry
     sudo rsync -azv ./isoroot/ ./nfsroot/
    
  8. Update /boot/cmdline.txt. Important bits are root=/dev/nfs, nfsroot=... and ip=dhcp. I've disabled reduced logging for debugging boot issues, you can keep loglevel and quiet if you'd like.

     cd ~/raspberry
     sudo -e ./nfsroot/boot/cmdline.txt
     #contents
     console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.0.10:/pi4-$SERIAL ip=dhcp rw rootwait consoleblank=0 plymouth.enable=0
    
  9. Update /etc/fstab

     cd ~/raspberry
     sudo -e ./nfsroot/etc/fstab
     #contents
     proc /proc proc defaults 0 0
     192.168.0.10:/pi4-$SERIAL / nfs defaults 0 0
     192.168.0.10:/tftpboot/$SERIAL /boot nfs defaults 0 0
    
  10. Enable SSH

     sudo ln -s /lib/systemd/system/ssh.service ./nfsroot/etc/systemd/system/sshd.service
     sudo ln -s /lib/systemd/system/ssh.service ./nfsroot/etc/systemd/system/multi-user.target.wants/ssh.service
    
  11. Remove SD card from Raspberry Pi and attempt to network boot now.

  12. You can SSH into your Raspberry Pi to finish configuring RetroPie

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment