-
Notifications
You must be signed in to change notification settings - Fork 397
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(squash): structure in a cleaner way
Simplify the squash mount layout. Instead of overlay on each top directory (/etc, /usr), just mount and switch_root into the squash image, with a overlay on top of it. Also install the binaries and setup scripts separately, so the squash setup code and the squash image content is independent of each other, all squash setup script and binaries can be deleted safely upon switch_root. With this change, previous squash clean up service and other tricky implementations are all gone. This commit depends on systemd commits from: systemd/systemd#18124 Previouly systemd doesn't recognize non-ramfs initramfs, now this is doable with SYSTEMD_IN_INITRD=lenient Signed-off-by: Kairui Song <kasong@redhat.com>
- Loading branch information
Showing
7 changed files
with
42 additions
and
117 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,29 @@ | ||
#!/bin/bash | ||
#!/bin/sh | ||
PATH=/bin:/sbin | ||
|
||
SQUASH_IMG=/squash/root.img | ||
SQUASH_MNT=/squash/root | ||
# Basic mounts for mounting a squash image | ||
mkdir /proc /sys /dev /run | ||
mount -t proc -o nosuid,noexec,nodev proc /proc | ||
mount -t sysfs -o nosuid,noexec,nodev sysfs /sys | ||
mount -t devtmpfs -o mode=755,noexec,nosuid,strictatime devtmpfs /dev | ||
mount -t tmpfs -o mode=755,nodev,nosuid,strictatime tmpfs /run | ||
|
||
# Following mount points are neccessary for mounting a squash image | ||
|
||
[ ! -d /proc/self ] && \ | ||
mount -t proc -o nosuid,noexec,nodev proc /proc | ||
|
||
[ ! -d /sys/kernel ] && \ | ||
mount -t sysfs -o nosuid,noexec,nodev sysfs /sys | ||
|
||
[ ! -e /dev/loop-control ] && \ | ||
mount -t devtmpfs -o mode=0755,noexec,nosuid,strictatime devtmpfs /dev | ||
|
||
# Need a loop device backend, overlayfs, and squashfs module | ||
# Load required modules | ||
modprobe loop | ||
if [ $? != 0 ]; then | ||
echo "Unable to setup loop module" | ||
fi | ||
|
||
modprobe squashfs | ||
if [ $? != 0 ]; then | ||
echo "Unable to setup squashfs module" | ||
fi | ||
|
||
modprobe overlay | ||
if [ $? != 0 ]; then | ||
echo "Unable to setup overlay module" | ||
fi | ||
|
||
[ ! -d "$SQUASH_MNT" ] && \ | ||
mkdir -m 0755 -p $SQUASH_MNT | ||
|
||
# Mount the squashfs image | ||
mount -t squashfs -o ro,loop $SQUASH_IMG $SQUASH_MNT | ||
|
||
if [ $? != 0 ]; then | ||
echo "Unable to mount squashed initramfs image" | ||
fi | ||
|
||
for file in $SQUASH_MNT/*; do | ||
file=${file#$SQUASH_MNT/} | ||
lowerdir=$SQUASH_MNT/$file | ||
workdir=/squash/overlay-work/$file | ||
upperdir=/$file | ||
mntdir=/$file | ||
|
||
mkdir -m 0755 -p $workdir | ||
mkdir -m 0755 -p $mntdir | ||
# Mount the squash image | ||
mount -t ramfs ramfs /squash | ||
mkdir -p /squash/root /squash/overlay/upper /squash/overlay/work | ||
mount -t squashfs -o ro,loop /squash-root.img /squash/root | ||
|
||
mount -t overlay overlay -o\ | ||
lowerdir=$lowerdir,upperdir=$upperdir,workdir=$workdir $mntdir | ||
done | ||
# Setup new root overlay | ||
mkdir /newroot | ||
mount -t overlay overlay -o lowerdir=/squash/root,upperdir=/squash/overlay/upper,workdir=/squash/overlay/work/ /newroot/ | ||
|
||
exec /init.orig | ||
# Move all mount points to new root to prepare chroot | ||
mount --move /squash /newroot/squash | ||
|
||
echo "Something went wrong when trying to exec original init!" | ||
exit 1 | ||
# Jump to new root and clean setup files | ||
SYSTEMD_IN_INITRD=lenient exec switch_root /newroot /init |
This file contains 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
This file was deleted.
Oops, something went wrong.