Last active
June 24, 2022 15:45
-
-
Save dzindra/a8e2083a7f037ca244cf70d100c96656 to your computer and use it in GitHub Desktop.
Raspberry PI read only filesystem with writable overlay
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cp overlay /etc/initramfs-tools/scripts/ | |
echo "overlay" >> /etc/initramfs-tools/modules | |
mkdir /overlay /overlay/temp /overlay/base | |
update-initramfs -c -k `uname -r` | |
echo "initramfs initrd.img-`uname -r`" >> /boot/config.txt | |
echo "boot=overlay `cat /boot/cmdline.txt`" > /boot/cmdline.txt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Overlay filesystem mounting -*- shell-script -*- | |
# | |
# HOW TO INSTALL | |
# | |
# 1. put this file at /etc/initramfs-tools/scripts/overlay | |
# 2. run following to add overlay module to initramfs | |
# echo "overlay" >> /etc/initramfs-tools/modules | |
# 3. create overlay directories | |
# mkdir /overlay /overlay/temp /overlay/base | |
# 4. create initramfs | |
# update-initramfs -c -k `uname -r` | |
# 5. modify /boot/config.txt | |
# echo "initramfs initrd.img-`uname -r`" >> /boot/config.txt | |
# 6. add "boot=overlay" to /boot/cmdline.txt | |
# 7. reboot | |
mountroot() | |
{ | |
local_top | |
local_device_setup "${ROOT}" root | |
# Get the root filesystem type if not set | |
if [ -z "${ROOTFSTYPE}" ]; then | |
FSTYPE=$(get_fstype "${ROOT}") | |
else | |
FSTYPE=${ROOTFSTYPE} | |
fi | |
local_premount | |
ROOT=$(resolve_device "$ROOT") | |
# FIXME This has no error checking | |
modprobe ${FSTYPE} | |
modprobe overlay | |
checkfs ${ROOT} root | |
mkdir /upper /lower | |
mount -t tmpfs tmpfs /upper | |
mkdir /upper/data /upper/work | |
if [ "${FSTYPE}" != "unknown" ]; then | |
mount -r -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /lower | |
else | |
mount -r ${ROOTFLAGS} ${ROOT} /lower | |
fi | |
mount -t overlay -olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work overlay ${rootmnt} | |
} | |
mount_bottom() | |
{ | |
if [ -d ${rootmnt}/overlay/temp ]; then | |
mount -n -o move /upper ${rootmnt}/overlay/temp | |
fi | |
if [ -d ${rootmnt}/overlay/base ]; then | |
mount -n -o move /lower ${rootmnt}/overlay/base | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi! did you face any issue running docker in your raspberry?
I got the following error after enabling overlayfs:
Dec 28 15:03:21 raspberrypi dockerd[964]: failed to start daemon: rename /var/lib/docker/runtimes /var/lib/docker/runtimes-old: invalid cross-device link