Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the mount points of the overlayfs visible via config option #193

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 53 additions & 13 deletions raspi-config
Original file line number Diff line number Diff line change
Expand Up @@ -2547,7 +2547,7 @@ enable_overlayfs() {
BOOTRO=no
fi

cat > /etc/initramfs-tools/scripts/overlay << 'EOF'
sed -e "s!MOUNT_POINT!$MOUNT_POINT!g" > /etc/initramfs-tools/scripts/overlay << 'EOF'
# Local filesystem mounting -*- shell-script -*-

#
Expand Down Expand Up @@ -2580,24 +2580,24 @@ local_mount_root()
checkfs ${ROOT} root "${FSTYPE}"

# Create directories for root and the overlay
mkdir /lower /upper
mkdir MOUNT_POINT/lower MOUNT_POINT/upper

# Mount read-only root to /lower
# Mount read-only root to MOUNT_POINT/lower
if [ "${FSTYPE}" != "unknown" ]; then
mount -r -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} /lower
mount -r -t ${FSTYPE} ${ROOTFLAGS} ${ROOT} MOUNT_POINT/lower
else
mount -r ${ROOTFLAGS} ${ROOT} /lower
mount -r ${ROOTFLAGS} ${ROOT} MOUNT_POINT/lower
fi

modprobe overlay || insmod "/lower/lib/modules/$(uname -r)/kernel/fs/overlayfs/overlay.ko"
modprobe overlay || insmod "MOUNT_POINT/lower/lib/modules/$(uname -r)/kernel/fs/overlayfs/overlay.ko"

# Mount a tmpfs for the overlay in /upper
mount -t tmpfs tmpfs /upper
mkdir /upper/data /upper/work
# Mount a tmpfs for the overlay in MOUNT_POINT/upper
mount -t tmpfs tmpfs MOUNT_POINT/upper
mkdir MOUNT_POINT/upper/data MOUNT_POINT/upper/work

# Mount the final overlay-root in $rootmnt
mount -t overlay \
-olowerdir=/lower,upperdir=/upper/data,workdir=/upper/work \
-olowerdir=MOUNT_POINT/lower,upperdir=MOUNT_POINT/upper/data,workdir=MOUNT_POINT/upper/work \
overlay ${rootmnt}
}
EOF
Expand All @@ -2608,7 +2608,9 @@ EOF
fi

# build the new initramfs
update-initramfs -c -k "$KERN"
if ! update-initramfs -c -k "$KERN" ; then
echo "Failed to build the new initramfs ${KERN}"
fi

# rename it so we know it has overlay added
mv /boot/initrd.img-"$KERN" /boot/"$INITRD"
Expand Down Expand Up @@ -2646,7 +2648,11 @@ disable_overlayfs() {

# modify config.txt
sed -i /boot/config.txt -e "/initramfs.*/d"
update-initramfs -d -k "${KERN}-overlay"

# delete the existing initramfs
if ! update-initramfs -d -k "${KERN}-overlay" ; then
echo "Failed to delete initramfs ${KERN}-overlay"
fi

# modify command line
sed -i /boot/cmdline.txt -e "s/\(.*\)boot=overlay \(.*\)/\1\2/"
Expand Down Expand Up @@ -2675,6 +2681,14 @@ disable_bootro() {
}

do_overlayfs() {
if [ "$INTERACTIVE" = False -a ! "$1" ]; then echo '
do_overlayfs status [ writable [ invisible ] ]
"status" can be 0=enable or 1=disable overlayfs (default)
"writable" can be 0=read-only (default) or 1=writable boot partition
"invisible" (used when enabling the overlayfs) can be 0=visible mounts or 1=invisible mounts (default)
'
return 1
fi
DEFAULT=--defaultno
CURRENT=0
STATUS="disabled"
Expand All @@ -2695,7 +2709,26 @@ do_overlayfs() {
else
RET=$1
fi
case "$RET" in ''|*[!01]*) RET=1;; esac
if [ $RET -eq $CURRENT ]; then
MOUNT_POINT="/run"
if [ "$INTERACTIVE" = True -a $RET -eq 0 ]; then
whiptail --yesno "Would you like the mount points of the overlay file system to be visible under '$MOUNT_POINT/upper' (rw) and '$MOUNT_POINT/lower' (ro)?" $DEFAULT 20 60 2
MP=$?
else
MP=$3
fi
case "$MP" in ''|*[!01]*) MP=1;; esac
if [ $MP -eq 1 ]; then
MOUNT_POINT=""
if [ "$INTERACTIVE" = False ]; then
echo "Invisible mount points"
fi
else
if [ "$INTERACTIVE" = False ]; then
echo "Mount points under '$MOUNT_POINT'"
fi
fi
if [ $RET -eq 0 ]; then
if enable_overlayfs; then
STATUS="enabled"
Expand Down Expand Up @@ -2739,19 +2772,26 @@ do_overlayfs() {
whiptail --yesno "Would you like the boot partition to be write-protected?" $DEFAULT 20 60 2
RET=$?
else
RET=$1
RET=$2
fi
case "$RET" in ''|*[!01]*) RET=0;; esac
if [ $RET -eq $CURRENT ]; then
if [ $RET -eq 0 ]; then
if enable_bootro; then
STATUS="read-only"
if [ "$INTERACTIVE" = False ]; then
echo "Boot partition is $STATUS"
fi
ASK_TO_REBOOT=1
else
STATUS="unchanged"
fi
elif [ $RET -eq 1 ]; then
if disable_bootro; then
STATUS="writable"
if [ "$INTERACTIVE" = False ]; then
echo "Boot partition is $STATUS"
fi
ASK_TO_REBOOT=1
else
STATUS="unchanged"
Expand Down