Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
solve_raspbian_sd_card_corruption_issues_with_read-only_mounted_root_partition [30.01.2017 14:46] – Pascal Suter | solve_raspbian_sd_card_corruption_issues_with_read-only_mounted_root_partition [25.10.2018 08:12] (current) – [The Script] Pascal Suter | ||
---|---|---|---|
Line 14: | Line 14: | ||
sudo dphys-swapfile uninstall | sudo dphys-swapfile uninstall | ||
sudo update-rc.d dphys-swapfile remove</ | sudo update-rc.d dphys-swapfile remove</ | ||
+ | * after you have set up and configured your raspberry pi the way you want it, simply activate the overlayRoot script as alternate init script by adding this entry to the end of your cmdline.txt file in the boot partition of the raspbian sd card: < | ||
+ | * to make changes, simply remove the entry above and reboot and your raspberry is writeable again. then re-enable and reboot for it to be readonly again. | ||
===== The Script ===== | ===== The Script ===== | ||
Line 19: | Line 21: | ||
#!/bin/sh | #!/bin/sh | ||
# Read-only Root-FS for Raspian using overlayfs | # Read-only Root-FS for Raspian using overlayfs | ||
- | # Version 1.0 | + | # Version |
+ | # | ||
+ | # Version History: | ||
+ | # | ||
+ | # 1.1: adopted new fstab style with PARTUUID. the script will now look for a /dev/xyz definiton first | ||
+ | # (old raspbian), if that is not found, it will look for a partition with LABEL=rootfs, | ||
+ | # is not found it look for a PARTUUID string in fstab for / and convert that to a device name | ||
+ | # using the blkid command. | ||
# | # | ||
# Created 2017 by Pascal Suter @ DALCO AG, Switzerland to work on Raspian as custom init script | # Created 2017 by Pascal Suter @ DALCO AG, Switzerland to work on Raspian as custom init script | ||
Line 39: | Line 48: | ||
# | # | ||
# | # | ||
- | # Tested with Raspbian mini, 2017-01-11 | + | # Tested with Raspbian mini, 2018-10-09 |
# | # | ||
# This script will mount the root filesystem read-only and overlay it with a temporary tempfs | # This script will mount the root filesystem read-only and overlay it with a temporary tempfs | ||
Line 50: | Line 59: | ||
# | # | ||
# Install: | # Install: | ||
- | # copy this script to / | + | # copy this script to / |
- | # file in the raspbian image' | + | # |
# I strongly recommend to disable swapping before using this. it will work with swap but that just does | # I strongly recommend to disable swapping before using this. it will work with swap but that just does | ||
# not make sens as the swap file will be stored in the tempfs which again resides in the ram. | # not make sens as the swap file will be stored in the tempfs which again resides in the ram. | ||
Line 95: | Line 104: | ||
rootMountOpt=`awk '$2 == "/" | rootMountOpt=`awk '$2 == "/" | ||
rootFsType=`awk '$2 == "/" | rootFsType=`awk '$2 == "/" | ||
+ | echo "check if we can locate the root device based on fstab" | ||
+ | blkid $rootDev | ||
+ | if [ $? -gt 0 ]; then | ||
+ | echo "no success, try if a filesystem with label ' | ||
+ | rootDevFstab=$rootDev | ||
+ | rootDev=`blkid -L " | ||
+ | if [ $? -gt 0 ]; then | ||
+ | echo "no luck either, try to further parse fstab' | ||
+ | echo "try if fstab contains a PARTUUID definition" | ||
+ | echo " | ||
+ | if [ $? -gt 0 ]; then | ||
+ | fail "could not find a root filesystem device in fstab. Make sure that fstab contains a device definition or a PARTUUID entry for / or that the root filesystem has a label ' | ||
+ | fi | ||
+ | device="" | ||
+ | partition="" | ||
+ | eval `echo " | ||
+ | rootDev=`blkid -t " | ||
+ | blkid $rootDev | ||
+ | if [ $? -gt 0 ]; then | ||
+ | fail "The PARTUUID entry in fstab could not be converted into a valid device name. Make sure that fstab contains a device definition or a PARTUUID entry for / or that the root filesystem has a label ' | ||
+ | fi | ||
+ | fi | ||
+ | fi | ||
mount -t ${rootFsType} -o ${rootMountOpt}, | mount -t ${rootFsType} -o ${rootMountOpt}, | ||
if [ $? -ne 0 ]; then | if [ $? -ne 0 ]; then |