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
|
export PATH=/usr/bin:/usr/sbin:/bin:/sbin
|
||||||
MOUNTPOINT=/root
|
MOUNTPOINT=/root
|
||||||
TMPFS_MOUNT=/mnt
|
SQUASHFS_MOUNT=/mnt/squashfs
|
||||||
|
OVERLAY_TMPFS=/mnt/overlay
|
||||||
|
|
||||||
# Hook functions for initramfs-tools boot script integration
|
# Hook functions for initramfs-tools boot script integration
|
||||||
netboot_top()
|
netboot_top()
|
||||||
@@ -125,51 +126,59 @@ mountroot() {
|
|||||||
if echo "${FILE_NAME}" | grep -q squashfs; then
|
if echo "${FILE_NAME}" | grep -q squashfs; then
|
||||||
log_begin_msg "Setting up SquashFS with overlay"
|
log_begin_msg "Setting up SquashFS with overlay"
|
||||||
|
|
||||||
# Mount read-only SquashFS
|
# Setup overlay if requested - need separate mount points
|
||||||
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
|
|
||||||
if [ -n "${OVERLAYROOT}" ]; then
|
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
|
# 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"
|
log_failure_msg "Failed to mount tmpfs for overlay"
|
||||||
umount "${MOUNTPOINT}"
|
umount "${SQUASHFS_MOUNT}"
|
||||||
rm -f "${FILE_PATH}"
|
rm -f "${FILE_PATH}"
|
||||||
return ${rc}
|
return ${rc}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create overlay structure
|
# 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 \
|
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
|
overlay_root "${MOUNTPOINT}"; then
|
||||||
log_failure_msg "Failed to mount overlay filesystem"
|
log_failure_msg "Failed to mount overlay filesystem"
|
||||||
umount "${TMPFS_MOUNT}"
|
umount "${OVERLAY_TMPFS}"
|
||||||
umount "${MOUNTPOINT}"
|
umount "${SQUASHFS_MOUNT}"
|
||||||
rm -f "${FILE_PATH}"
|
rm -f "${FILE_PATH}"
|
||||||
return ${rc}
|
return ${rc}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
log_end_msg
|
log_end_msg
|
||||||
log_begin_msg "Overlay mounted successfully"
|
log_begin_msg "Overlay mounted at ${MOUNTPOINT} (lower=${SQUASHFS_MOUNT})"
|
||||||
log_end_msg
|
log_end_msg
|
||||||
|
|
||||||
# Clean up downloaded image as it's now mounted
|
# Clean up downloaded image as it's now mounted
|
||||||
rm -f "${FILE_PATH}"
|
rm -f "${FILE_PATH}"
|
||||||
rc=0
|
rc=0
|
||||||
else
|
else
|
||||||
# Direct SquashFS mount without overlay
|
# Direct SquashFS mount without overlay - mount directly to /root
|
||||||
log_begin_msg "Mounted SquashFS without overlay"
|
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
|
log_end_msg
|
||||||
rc=0
|
rc=0
|
||||||
fi
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user