From f64ffe85717f952877876cb0dea889237a03f22b Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Sat, 2 Sep 2017 22:32:31 +0000 Subject: [PATCH] [baseimage]: build root filesystem via overlay fs instead of aufs --- build_debian.sh | 5 +++-- files/initramfs-tools/modules | 2 +- files/initramfs-tools/udev.patch | 10 ++++++++++ files/initramfs-tools/union-mount.j2 | 9 +++++---- 4 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 files/initramfs-tools/udev.patch diff --git a/build_debian.sh b/build_debian.sh index 969ff9f07..c5c1d2305 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -116,7 +116,7 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/initramfs-tools_*.deb || \ sudo dpkg --root=$FILESYSTEM_ROOT -i target/debs/linux-image-${LINUX_KERNEL_VERSION}-amd64_*.deb || \ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y install -f -## Update initramfs for booting with squashfs+aufs +## Update initramfs for booting with squashfs+overlay cat files/initramfs-tools/modules | sudo tee -a $FILESYSTEM_ROOT/etc/initramfs-tools/modules > /dev/null ## Hook into initramfs: change fs type from vfat to ext4 on arista switches @@ -148,6 +148,7 @@ sudo cp files/initramfs-tools/mgmt-intf-dhcp $FILESYSTEM_ROOT/etc/initramfs-tool sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-bottom/mgmt-intf-dhcp sudo cp files/initramfs-tools/union-fsck $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/union-fsck +pushd $FILESYSTEM_ROOT/usr/share/initramfs-tools/scripts/init-bottom && sudo patch -p1 < $OLDPWD/files/initramfs-tools/udev.patch; popd sudo chroot $FILESYSTEM_ROOT update-initramfs -u ## Install latest intel igb driver @@ -273,7 +274,7 @@ sudo sed -i ' ' $FILESYSTEM_ROOT/etc/monit/monitrc sudo tee -a $FILESYSTEM_ROOT/etc/monit/monitrc > /dev/null <<'EOF' -check filesystem root-aufs with path / +check filesystem root-overlay with path / if space usage > 90% for 5 times within 10 cycles then alert check filesystem var-log with path /var/log if space usage > 90% for 5 times within 10 cycles then alert diff --git a/files/initramfs-tools/modules b/files/initramfs-tools/modules index 1bd0eab15..33f28b98b 100644 --- a/files/initramfs-tools/modules +++ b/files/initramfs-tools/modules @@ -1,5 +1,5 @@ squashfs -aufs +overlay vfat nls_cp437 nls_utf8 diff --git a/files/initramfs-tools/udev.patch b/files/initramfs-tools/udev.patch new file mode 100644 index 000000000..38c43dc27 --- /dev/null +++ b/files/initramfs-tools/udev.patch @@ -0,0 +1,10 @@ +--- a/udev 2017-09-02 23:13:45.078773236 +0000 ++++ b/udev 2017-09-02 22:40:08.502773236 +0000 +@@ -1,6 +1,6 @@ + #!/bin/sh -e + +-PREREQS="" ++PREREQS="union-mount" + + prereqs() { echo "$PREREQS"; } + diff --git a/files/initramfs-tools/union-mount.j2 b/files/initramfs-tools/union-mount.j2 index db40d4f08..6369b8449 100644 --- a/files/initramfs-tools/union-mount.j2 +++ b/files/initramfs-tools/union-mount.j2 @@ -11,18 +11,19 @@ case $1 in ;; esac -## Mount the aufs file system: rw layer over squashfs +## Mount the overlay file system: rw layer over squashfs image_dir=$(cat /proc/cmdline | sed -e 's/.*loop=\(\S*\)\/.*/\1/') mkdir -p ${rootmnt}/host/$image_dir/rw -mount -n -o dirs=${rootmnt}/host/$image_dir/rw:${rootmnt}=ro -t aufs root-aufs ${rootmnt} +mkdir -p ${rootmnt}/host/$image_dir/work +mount -n -o lowerdir=${rootmnt},upperdir=${rootmnt}/host/$image_dir/rw,workdir=${rootmnt}/host/$image_dir/work -t overlay root-overlay ${rootmnt} ## Check if the root block device is still there [ -b ${ROOT} ] || mdev -s ## Mount the raw partition again mount ${ROOT} ${rootmnt}/host -## Mount the working directory of docker engine in the raw partition, bypass the aufs +## Mount the working directory of docker engine in the raw partition, bypass the overlay mkdir -p ${rootmnt}/var/lib/docker mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker -## Mount the boot directory in the raw partition, bypass the aufs +## Mount the boot directory in the raw partition, bypass the overlay mkdir -p ${rootmnt}/boot mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot ## Mount loop device for /var/log