Fix overlay mount: use separate mount points for squashfs and overlay
The overlay mount was failing because it tried to mount overlay onto /root while also using /root as the lowerdir source. This is invalid - you cannot overlay-mount a directory onto itself. Fix: Mount squashfs to /mnt/squashfs, tmpfs to /mnt/overlay, then mount overlay onto /root using the squashfs mount as lowerdir.
This commit is contained in:
@@ -3,7 +3,8 @@
|
||||
|
||||
export PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
||||
MOUNTPOINT=/root
|
||||
TMPFS_MOUNT=/mnt
|
||||
SQUASHFS_MOUNT=/mnt/squashfs
|
||||
OVERLAY_TMPFS=/mnt/overlay
|
||||
|
||||
# Hook functions for initramfs-tools boot script integration
|
||||
netboot_top()
|
||||
@@ -125,51 +126,59 @@ mountroot() {
|
||||
if echo "${FILE_NAME}" | grep -q squashfs; then
|
||||
log_begin_msg "Setting up SquashFS with overlay"
|
||||
|
||||
# Mount read-only SquashFS
|
||||
if ! mount -t squashfs "${FILE_PATH}" "${MOUNTPOINT}" -o ro; then
|
||||
log_failure_msg "Failed to mount SquashFS at ${MOUNTPOINT}"
|
||||
rm -f "${FILE_PATH}"
|
||||
return ${rc}
|
||||
fi
|
||||
log_begin_msg "SquashFS mounted at ${MOUNTPOINT}"
|
||||
log_end_msg
|
||||
|
||||
# Setup overlay if requested
|
||||
# Setup overlay if requested - need separate mount points
|
||||
if [ -n "${OVERLAYROOT}" ]; then
|
||||
log_begin_msg "Mounting ${OVERLAYROOT} for overlay"
|
||||
# Create mount points
|
||||
mkdir -p "${SQUASHFS_MOUNT}" "${OVERLAY_TMPFS}"
|
||||
|
||||
# Mount read-only SquashFS to separate location
|
||||
if ! mount -t squashfs "${FILE_PATH}" "${SQUASHFS_MOUNT}" -o ro; then
|
||||
log_failure_msg "Failed to mount SquashFS at ${SQUASHFS_MOUNT}"
|
||||
rm -f "${FILE_PATH}"
|
||||
return ${rc}
|
||||
fi
|
||||
log_begin_msg "SquashFS mounted at ${SQUASHFS_MOUNT}"
|
||||
log_end_msg
|
||||
|
||||
log_begin_msg "Mounting tmpfs for overlay upper/work"
|
||||
|
||||
# Create tmpfs for upper and work directories
|
||||
if ! mount -o size=2G -t "${OVERLAYROOT}" tmpfs_overlay "${TMPFS_MOUNT}"; then
|
||||
if ! mount -t tmpfs -o size=2G tmpfs_overlay "${OVERLAY_TMPFS}"; then
|
||||
log_failure_msg "Failed to mount tmpfs for overlay"
|
||||
umount "${MOUNTPOINT}"
|
||||
umount "${SQUASHFS_MOUNT}"
|
||||
rm -f "${FILE_PATH}"
|
||||
return ${rc}
|
||||
fi
|
||||
|
||||
# Create overlay structure
|
||||
mkdir -p "${TMPFS_MOUNT}/upper" "${TMPFS_MOUNT}/work"
|
||||
mkdir -p "${OVERLAY_TMPFS}/upper" "${OVERLAY_TMPFS}/work"
|
||||
|
||||
# Mount overlay combining read-only lower + writable upper
|
||||
# Mount overlay combining read-only lower + writable upper onto /root
|
||||
if ! mount -t overlay \
|
||||
-o "lowerdir=${MOUNTPOINT},upperdir=${TMPFS_MOUNT}/upper,workdir=${TMPFS_MOUNT}/work" \
|
||||
-o "lowerdir=${SQUASHFS_MOUNT},upperdir=${OVERLAY_TMPFS}/upper,workdir=${OVERLAY_TMPFS}/work" \
|
||||
overlay_root "${MOUNTPOINT}"; then
|
||||
log_failure_msg "Failed to mount overlay filesystem"
|
||||
umount "${TMPFS_MOUNT}"
|
||||
umount "${MOUNTPOINT}"
|
||||
umount "${OVERLAY_TMPFS}"
|
||||
umount "${SQUASHFS_MOUNT}"
|
||||
rm -f "${FILE_PATH}"
|
||||
return ${rc}
|
||||
fi
|
||||
|
||||
log_end_msg
|
||||
log_begin_msg "Overlay mounted successfully"
|
||||
log_begin_msg "Overlay mounted at ${MOUNTPOINT} (lower=${SQUASHFS_MOUNT})"
|
||||
log_end_msg
|
||||
|
||||
# Clean up downloaded image as it's now mounted
|
||||
rm -f "${FILE_PATH}"
|
||||
rc=0
|
||||
else
|
||||
# Direct SquashFS mount without overlay
|
||||
log_begin_msg "Mounted SquashFS without overlay"
|
||||
# Direct SquashFS mount without overlay - mount directly to /root
|
||||
if ! mount -t squashfs "${FILE_PATH}" "${MOUNTPOINT}" -o ro; then
|
||||
log_failure_msg "Failed to mount SquashFS at ${MOUNTPOINT}"
|
||||
rm -f "${FILE_PATH}"
|
||||
return ${rc}
|
||||
fi
|
||||
log_begin_msg "Mounted SquashFS without overlay at ${MOUNTPOINT}"
|
||||
log_end_msg
|
||||
rc=0
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user