Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision | |||
solve_raspbian_sd_card_corruption_issues_with_read-only_mounted_root_partition [30.01.2017 14:55] – 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 21: | 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 41: | 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 52: | 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 97: | 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 |