From 0d0752e09980cbf105be7642ad9c39dc63f2c8f5 Mon Sep 17 00:00:00 2001 From: padmanarayana Date: Wed, 7 Feb 2018 19:37:01 +0530 Subject: [PATCH] Reduce SONiC migration partition from 8G to 1G. (#1343) * Reduce SONiC migration partition from 8G to 1G. * Changes to create 1G partition with ability to resize post migration. * Remove redundant changes in varlog * Use findfs to interpret root. Move resize in case cmdline params are reordered --- build_debian.sh | 4 +++ build_image.sh | 2 +- files/initramfs-tools/mke2fs | 2 ++ files/initramfs-tools/resize-rootfs | 39 +++++++++++++++++++++++++++++ onie-image.conf | 2 +- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 files/initramfs-tools/resize-rootfs diff --git a/build_debian.sh b/build_debian.sh index 2e0f7f152b51..2edb356d3d3e 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -133,6 +133,10 @@ sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/hooks/setfacl sudo cp files/initramfs-tools/arista-net $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/arista-net +# Hook into initramfs: resize root partition after migration from another NOS to SONiC on Dell switches +sudo cp files/initramfs-tools/resize-rootfs $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs +sudo chmod +x $FILESYSTEM_ROOT/etc/initramfs-tools/scripts/init-premount/resize-rootfs + ## Hook into initramfs: after partition mount and loop file mount ## 1. Prepare layered file system ## 2. Bind-mount docker working directory (docker aufs cannot work over aufs rootfs) diff --git a/build_image.sh b/build_image.sh index ee7fb8a75823..757ea026f16d 100755 --- a/build_image.sh +++ b/build_image.sh @@ -56,7 +56,7 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then echo "Creating SONiC raw partition : $OUTPUT_RAW_IMAGE of size $RAW_IMAGE_DISK_SIZE MB" fallocate -l "$RAW_IMAGE_DISK_SIZE"M $OUTPUT_RAW_IMAGE - ## Generate a compressed 8GB partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer + ## Generate a partition dump that can be used to 'dd' in-lieu of using the onie-nos-installer ## Run the installer ## The 'build' install mode of the installer is used to generate this dump. sudo chmod a+x $OUTPUT_ONIE_IMAGE diff --git a/files/initramfs-tools/mke2fs b/files/initramfs-tools/mke2fs index a67162199cf1..52933d644a87 100644 --- a/files/initramfs-tools/mke2fs +++ b/files/initramfs-tools/mke2fs @@ -20,6 +20,8 @@ esac copy_exec /sbin/mke2fs copy_exec /sbin/sfdisk copy_exec /sbin/fdisk +copy_exec /sbin/resize2fs +copy_exec /sbin/findfs fstypes="ext4 ext3" diff --git a/files/initramfs-tools/resize-rootfs b/files/initramfs-tools/resize-rootfs new file mode 100644 index 000000000000..17ffcb94e693 --- /dev/null +++ b/files/initramfs-tools/resize-rootfs @@ -0,0 +1,39 @@ +#!/bin/sh + +case $1 in + prereqs) + exit 0 + ;; +esac + +# Extract kernel parameters +set -- $(cat /proc/cmdline) +for x in "$@"; do + case "$x" in + root=*) + root_val="${x#root=}" + ;; + resize-rootfs) + need_resize=1 + ;; + esac +done + +if [ -n "$need_resize" ]; then + if [ -z "$root_val" ]; then + echo "ERROR: resize required but unable to get root location from command line" + exit 1 + fi + + root_dev=$(findfs $root_val) + if [ $? != 0 ]; then + echo "ERROR: resize required but findfs failed" + exit 1 + fi + + resize2fs -f $root_dev + if [ $? != 0 ]; then + echo "ERROR: Unable to resize the root file system. Manual intervention needed to fix the issue." + exit 1 + fi +fi diff --git a/onie-image.conf b/onie-image.conf index b6564feb1a41..0ffc9914c732 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -31,7 +31,7 @@ OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin OUTPUT_RAW_IMAGE=target/sonic-$TARGET_MACHINE.raw ### Raw image size in MB -RAW_IMAGE_DISK_SIZE=8192 +RAW_IMAGE_DISK_SIZE=1024 ## Output file name for aboot installer OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi