Skip to content

Instantly share code, notes, and snippets.

@yeokm1
Last active January 5, 2021 01:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save yeokm1/2aeb7f0692ca848bd85a to your computer and use it in GitHub Desktop.
Save yeokm1/2aeb7f0692ca848bd85a to your computer and use it in GitHub Desktop.
Set up Raspbian on Raspberry Pi to boot from and use a read-only file-system
sudo apt-get update
sudo apt-get upgrade
sudo rm -rf opt
cd /var/log/ 
sudo rm `find . -type f`
sudo swapoff --all
sudo update-rc.d -f dphys-swapfile remove
sudo apt-get remove dphys-swapfile
sudo rm /etc/init.d/dphys-swapfile
sudo apt-get autoremove
sudo apt-get clean

sudo nano /etc/default/rcS
#Add "RAMTMP=yes" to the bottom

sudo nano /etc/fstab

#Add modify these lines
tmpfs           /tmp            tmpfs   nodev,nosuid,size=30M,mode=1777    0    0
tmpfs           /var/log        tmpfs   nodev,nosuid,size=30M,mode=1777    0    0
/dev/mmcblk0p1  /boot           vfat    defaults,ro,errors=remount-ro          0       2
/dev/mmcblk0p2  /               ext2    defaults,ro,noatime,errors=remount-ro  0       1


sudo nano +60 /etc/init.d/hwclock.sh
#Change "-f" to "-L"

sudo nano /etc/environment
#Add "BLKID_FILE="/var/local/blkid.tab"" into the file


sudo rm /etc/mtab
sudo ln -s /proc/self/mounts /etc/mtab

cd ~
printf "mount -o remount,rw /\nmount -o remount,rw /boot" > writeenable.sh
printf "mount -o remount,ro /\nmount -o remount,ro /boot" > readonly.sh
chmod 500 writeenable.sh
chmod 500 readonly.sh

sudo nano /etc/rc.local
#Add following up to #end just before exit 0
echo ""
echo "Disk is mounted in readonly mode."
echo "To enable readwrite, run sudo ./writeenable.sh"
echo "To set back to readonly, run sudo ./readonly.sh"
#end


#To change hostname
#Replace “raspberrypi” with whatever hostname you desire. 

sudo nano /etc/hosts
sudo nano /etc/hostname
sudo /etc/init.d/hostname.sh #Script to commit changes

history -c -w
sudo reboot

##References

  1. http://www.raspberrypi.org/forums/viewtopic.php?p=213440
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment