From 9989e3261a1618d6052a3eae67ae95a72ecb020d Mon Sep 17 00:00:00 2001 From: paavaanan Date: Mon, 29 Jan 2018 14:12:56 +0530 Subject: [PATCH 1/4] Reduce SONiC migration partition from 8G to 1G. --- build_debian.sh | 4 +++- build_image.sh | 32 +++++++++++++++++++++++++------- files/initramfs-tools/varlog | 6 ++++++ onie-image.conf | 5 ++++- 4 files changed, 38 insertions(+), 9 deletions(-) diff --git a/build_debian.sh b/build_debian.sh index 6a27bd5d237f..a23e0449eb15 100755 --- a/build_debian.sh +++ b/build_debian.sh @@ -217,7 +217,9 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in unzip \ gdisk \ sysfsutils \ - grub2-common + grub2-common \ + dosfstools \ + parted sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y download \ grub-pc-bin diff --git a/build_image.sh b/build_image.sh index ee7fb8a75823..2a234a28a1eb 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 @@ -67,14 +67,32 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then exit 1 } - gzip $OUTPUT_RAW_IMAGE + if [ $CHUNK_SIZE = "0" ]; then + # Create a single compressed partition dump + gzip $OUTPUT_RAW_IMAGE - [ -r $OUTPUT_RAW_IMAGE.gz ] || { - echo "Error : gzip $OUTPUT_RAW_IMAGE failed!" - exit 1 - } + [ -r $OUTPUT_RAW_IMAGE.gz ] || { + echo "Error : gzip $OUTPUT_RAW_IMAGE failed!" + exit 1 + } + + mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE + else + # Split the partition dump into chunks, compress each chunk + # and tar the chunks to be used as the raw image + split -a 4 -b "$CHUNK_SIZE"M -d $OUTPUT_RAW_IMAGE sonic-$TARGET_MACHINE-chunk + rm $OUTPUT_RAW_IMAGE + gzip sonic-$TARGET_MACHINE-chunk* + tar -cf sonic-$TARGET_MACHINE.tar --remove-files sonic-$TARGET_MACHINE-chunk* + + [ -r sonic-$TARGET_MACHINE.tar ] || { + echo "Error : tar sonic-$TARGET_MACHINE.tar failed!" + exit 1 + } + + mv sonic-$TARGET_MACHINE.tar $OUTPUT_RAW_IMAGE + fi - mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE echo "The compressed raw image is in $OUTPUT_RAW_IMAGE" ## Use 'aboot' as target machine category which includes Aboot as bootloader diff --git a/files/initramfs-tools/varlog b/files/initramfs-tools/varlog index d1340eaa9d8b..5bd5815100f9 100644 --- a/files/initramfs-tools/varlog +++ b/files/initramfs-tools/varlog @@ -17,6 +17,12 @@ for x in "$@"; do case "$x" in varlog_size=*) varlog_size="${x#varlog_size=}" + ;; + resize2fs-host) + resize_dev=`cat /proc/mounts | ${rootmnt}/bin/grep "/root/host" | ${rootmnt}/usr/bin/cut -d' ' -f1` + [ -z "$resize_dev" ] && exit 0 + ${rootmnt}/sbin/resize2fs $resize_dev + ;; esac done diff --git a/onie-image.conf b/onie-image.conf index b6564feb1a41..bf25e5658040 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -31,7 +31,10 @@ 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 + +### Chunk size in MB (0 => single chunk) +CHUNK_SIZE=8 ## Output file name for aboot installer OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi From f8bde0e57015338841558b0e028a11f76eeaeadf Mon Sep 17 00:00:00 2001 From: paavaanan Date: Thu, 1 Feb 2018 14:54:53 +0530 Subject: [PATCH 2/4] Changes to create 1G partition with ability to resize post migration. --- build_debian.sh | 8 +++++--- build_image.sh | 32 +++++++---------------------- files/initramfs-tools/mke2fs | 1 + files/initramfs-tools/resize-rootfs | 24 ++++++++++++++++++++++ onie-image.conf | 3 --- 5 files changed, 37 insertions(+), 31 deletions(-) create mode 100644 files/initramfs-tools/resize-rootfs diff --git a/build_debian.sh b/build_debian.sh index a23e0449eb15..2326f29e12e6 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) @@ -217,9 +221,7 @@ sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y in unzip \ gdisk \ sysfsutils \ - grub2-common \ - dosfstools \ - parted + grub2-common sudo LANG=C DEBIAN_FRONTEND=noninteractive chroot $FILESYSTEM_ROOT apt-get -y download \ grub-pc-bin diff --git a/build_image.sh b/build_image.sh index 2a234a28a1eb..757ea026f16d 100755 --- a/build_image.sh +++ b/build_image.sh @@ -67,32 +67,14 @@ elif [ "$IMAGE_TYPE" = "raw" ]; then exit 1 } - if [ $CHUNK_SIZE = "0" ]; then - # Create a single compressed partition dump - gzip $OUTPUT_RAW_IMAGE - - [ -r $OUTPUT_RAW_IMAGE.gz ] || { - echo "Error : gzip $OUTPUT_RAW_IMAGE failed!" - exit 1 - } - - mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE - else - # Split the partition dump into chunks, compress each chunk - # and tar the chunks to be used as the raw image - split -a 4 -b "$CHUNK_SIZE"M -d $OUTPUT_RAW_IMAGE sonic-$TARGET_MACHINE-chunk - rm $OUTPUT_RAW_IMAGE - gzip sonic-$TARGET_MACHINE-chunk* - tar -cf sonic-$TARGET_MACHINE.tar --remove-files sonic-$TARGET_MACHINE-chunk* - - [ -r sonic-$TARGET_MACHINE.tar ] || { - echo "Error : tar sonic-$TARGET_MACHINE.tar failed!" - exit 1 - } - - mv sonic-$TARGET_MACHINE.tar $OUTPUT_RAW_IMAGE - fi + gzip $OUTPUT_RAW_IMAGE + [ -r $OUTPUT_RAW_IMAGE.gz ] || { + echo "Error : gzip $OUTPUT_RAW_IMAGE failed!" + exit 1 + } + + mv $OUTPUT_RAW_IMAGE.gz $OUTPUT_RAW_IMAGE echo "The compressed raw image is in $OUTPUT_RAW_IMAGE" ## Use 'aboot' as target machine category which includes Aboot as bootloader diff --git a/files/initramfs-tools/mke2fs b/files/initramfs-tools/mke2fs index a67162199cf1..1a444de83d8c 100644 --- a/files/initramfs-tools/mke2fs +++ b/files/initramfs-tools/mke2fs @@ -20,6 +20,7 @@ esac copy_exec /sbin/mke2fs copy_exec /sbin/sfdisk copy_exec /sbin/fdisk +copy_exec /sbin/resize2fs fstypes="ext4 ext3" diff --git a/files/initramfs-tools/resize-rootfs b/files/initramfs-tools/resize-rootfs new file mode 100644 index 000000000000..c9318a8f9fc0 --- /dev/null +++ b/files/initramfs-tools/resize-rootfs @@ -0,0 +1,24 @@ +#!/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_dev="${x#root=}" + ;; + resize-rootfs) + [ -z "$root_dev" ] && exit 0 + resize2fs -f $root_dev + if [ $? != 0 ]; then + echo "ERROR: Unable to resize the root file system. Manual intervention needed to fix the issue." + fi + ;; + esac +done diff --git a/onie-image.conf b/onie-image.conf index bf25e5658040..0ffc9914c732 100644 --- a/onie-image.conf +++ b/onie-image.conf @@ -33,9 +33,6 @@ OUTPUT_RAW_IMAGE=target/sonic-$TARGET_MACHINE.raw ### Raw image size in MB RAW_IMAGE_DISK_SIZE=1024 -### Chunk size in MB (0 => single chunk) -CHUNK_SIZE=8 - ## Output file name for aboot installer OUTPUT_ABOOT_IMAGE=target/sonic-aboot-$TARGET_MACHINE.swi From bd8903db56f3da325000225bd25a00d64bee822f Mon Sep 17 00:00:00 2001 From: paavaanan Date: Thu, 1 Feb 2018 15:05:50 +0530 Subject: [PATCH 3/4] Remove redundant changes in varlog --- files/initramfs-tools/varlog | 6 ------ 1 file changed, 6 deletions(-) diff --git a/files/initramfs-tools/varlog b/files/initramfs-tools/varlog index 5bd5815100f9..d1340eaa9d8b 100644 --- a/files/initramfs-tools/varlog +++ b/files/initramfs-tools/varlog @@ -17,12 +17,6 @@ for x in "$@"; do case "$x" in varlog_size=*) varlog_size="${x#varlog_size=}" - ;; - resize2fs-host) - resize_dev=`cat /proc/mounts | ${rootmnt}/bin/grep "/root/host" | ${rootmnt}/usr/bin/cut -d' ' -f1` - [ -z "$resize_dev" ] && exit 0 - ${rootmnt}/sbin/resize2fs $resize_dev - ;; esac done From 6958898a8be5cc45b0597196df5990637dab8e1c Mon Sep 17 00:00:00 2001 From: padman Date: Tue, 6 Feb 2018 09:38:28 -0500 Subject: [PATCH 4/4] Use findfs to interpret root. Move resize in case cmdline params are reordered --- files/initramfs-tools/mke2fs | 1 + files/initramfs-tools/resize-rootfs | 27 +++++++++++++++++++++------ 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/files/initramfs-tools/mke2fs b/files/initramfs-tools/mke2fs index 1a444de83d8c..52933d644a87 100644 --- a/files/initramfs-tools/mke2fs +++ b/files/initramfs-tools/mke2fs @@ -21,6 +21,7 @@ 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 index c9318a8f9fc0..17ffcb94e693 100644 --- a/files/initramfs-tools/resize-rootfs +++ b/files/initramfs-tools/resize-rootfs @@ -11,14 +11,29 @@ set -- $(cat /proc/cmdline) for x in "$@"; do case "$x" in root=*) - root_dev="${x#root=}" + root_val="${x#root=}" ;; resize-rootfs) - [ -z "$root_dev" ] && exit 0 - resize2fs -f $root_dev - if [ $? != 0 ]; then - echo "ERROR: Unable to resize the root file system. Manual intervention needed to fix the issue." - fi + 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