Skip to content

Instantly share code, notes, and snippets.

@yeokm1
Last active April 13, 2018 02:54
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yeokm1/00bf00fbcda99cc33c2b to your computer and use it in GitHub Desktop.
Save yeokm1/00bf00fbcda99cc33c2b to your computer and use it in GitHub Desktop.
Set up Yocto runnig on Intel Edison to boot from and use a read-only file-system

Unlike your typical computer where you usually shutdown properly, I cannot rely on this during the use of my Intel Edison. If the Intel Edison is improperly shutdown too many times, data corruption in the file system leading to unbootable system may result. So we should use a read-only file system.

This version has been adapted from my Raspberry Pi Arch Linux's instructions.

#Update everything first
opkg update
opkg upgrade

#Adjust /etc/fstab, add/modify to the following hashed lines. Mount certain directories to RAM disk.
vi /etc/fstab
#Add the following lines up to the #end.
tmpfs /var/log tmpfs nodev,nosuid 0 0
tmpfs /var/tmp tmpfs nodev,nosuid 0 0

#Add "ro" to the mount options column for the following lines
rootfs                          /         auto     ro,nodev...
/dev/disk/by-partlabel/boot     /boot     auto     ro,noauto,x-systemd..
/dev/disk/by-partlabel/home     /home     auto     ro,noauto,x-systemd..

#Instead of adjusting the /etc/fstab file manually as above, you can use the following commands
#Backup /etc/fstab
cp /etc/fstab /etc/fstab.bak

#Add ro option to / in /etc/fstab
sed -i 's:\(.*\)\(/ \s*\w*\s*\)\(.*\):\1\2ro,\3:' /etc/fstab
#Add ro option to /boot in /etc/fstab
sed -i 's:\(.*\)\(/boot\s*\w*\s*\)\(.*\):\1\2ro,\3:' /etc/fstab

#Add ro option to /home in /etc/fstab. If you need /home to be writable, skip this and move to the next example.
sed -i 's:\(.*\)\(/home\s*\w*\s*\)\(.*\):\1\2ro,\3:' /etc/fstab

#Make /home writable but with data=journal protection. We first format the /home partition to ext3 to use the data journaling feature.
cd /
umount /dev/mmcblk0p10
mkfs.ext3 /dev/mmcblk0p10
tune2fs -o journal_data /dev/mmcblk0p10
mount -t ext3 -o data=journal /dev/mmcblk0p10 /home
#Replace entire /home line to change fs type from auto to ext3 and use only data=journal option
sed -i 's/^\/dev\/disk\/by-partlabel\/home.*/\/dev\/disk\/by-partlabel\/home     \/home       ext3    data=journal  1   1/' /etc/fstab

#Add "tmpfs /var/log tmpfs nodev,nosuid 0 0" to /etc/fstab
echo -e "tmpfs\t/var/log\ttmpfs\tnodev,nosuid\t0\t0" >> /etc/fstab
#Add "tmpfs /var/tmp tmpfs nodev,nosuid 0 0" to /etc/fstab
echo -e "tmpfs\t/var/tmp\ttmpfs\tnodev,nosuid\t0\t0" >> /etc/fstab

#Put shortcut shell scripts to re-enable read-write temporarily if needed
cd ~

#If you set /home to be readonly in /etc/fstab
printf "mount -o remount,rw /\nmount -o remount,rw /home" > writeenable.sh
printf "mount -o remount,ro /\nmount -o remount,ro /home" > readonly.sh

If you allow /home to be writable in /etc/fstab
printf "mount -o remount,rw /" > writeenable.sh
printf "mount -o remount,ro /" > readonly.sh

chmod 500 writeenable.sh
chmod 500 readonly.sh

#Remove history
history -c -w

reboot

To enable read-write temporarily to do say an update, just run ./writeenable.sh.

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