From 14a86429e2d43bd76d4ac5ac7fc74ca3f6a3542b Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Tue, 4 Apr 2017 09:32:12 +0000 Subject: [PATCH 1/2] [aboot]: add varlog limit file in aboot image --- files/Aboot/boot0.j2 | 2 +- files/initramfs-tools/arista-convertfs.j2 | 27 ++++++++++++++++++++++- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index 0905faad4c5d..c7aafe188bd8 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -47,7 +47,6 @@ extract_image() { rm -rf "$target_path/$f" fi done - ## Unzip the image unzip -oq "$swipath" -x boot0 -d "$target_path" @@ -102,6 +101,7 @@ platform_specific() { if [ "$platform" = "raven" ]; then aboot_machine=arista_7050_qx32 echo "modprobe.blacklist=radeon" >>/tmp/append + echo "varlog_size=100" >>/tmp/append fi if [ "$platform" = "crow" ]; then aboot_machine=arista_7050_qx32s diff --git a/files/initramfs-tools/arista-convertfs.j2 b/files/initramfs-tools/arista-convertfs.j2 index 8847bc69bdfa..4d182b9e7718 100644 --- a/files/initramfs-tools/arista-convertfs.j2 +++ b/files/initramfs-tools/arista-convertfs.j2 @@ -82,6 +82,24 @@ run_cmd() { fi } +create_varlog_file() { + [ -z "$varlog_size" ] && exit 0 + mkdir -p "$root_mnt" + mount -t ext4 "$root_dev" "$root_mnt" + # exit when the var_log.ext4 exists and the size matches + if [ -e "$root_mnt/disk-img/var-log.ext4" ]; then + cur_varlog_size=$(ls -l $root_mnt/disk-img/var-log.ext4 | awk '{print $5}') + if [ $cur_varlog_size == $((1024*1024*$varlog_size)) ]; then + exit 0 + fi + fi + local err_msg="Error: create var-log ext4 file" + local cmd="[ -n $varlog_size ] && mkdir -p $root_mnt/disk-img && dd if=/dev/zero of=$root_mnt/disk-img/var-log.ext4 count=$((2048*$varlog_size)) && mke2fs -t ext4 -q -F $root_mnt/disk-img/var-log.ext4" + run_cmd "$cmd" "$err_msg" + umount "$root_mnt" + exit 0 +} + # Extract kernel parameters set -- $(cat /proc/cmdline) for x in "$@"; do @@ -91,6 +109,9 @@ for x in "$@"; do ;; Aboot=*) aboot_flag="${x#Aboot=}" + ;; + varlog_size=*) + varlog_size="${x#varlog_size=}" esac done root_dev="$ROOT" @@ -105,8 +126,8 @@ if ! wait_for_root_dev; then echo "Error: timeout in waiting for $root_dev" exit 1 fi -blkid | grep "$root_dev.*vfat" -q || exit 0 +blkid | grep "$root_dev.*vfat" -q || create_varlog_file # Get flash dev name if [ -z "$block_flash" ]; then @@ -171,3 +192,7 @@ run_cmd "$cmd" "$err_msg" err_msg="Error: copying files form $tmp_mnt to $root_mnt failed" cmd="cp -a $tmp_mnt/. $root_mnt/" run_cmd "$cmd" "$err_msg" + +err_msg="Error: create var-log ext4 file" +cmd="[ -n $varlog_size ] && mkdir -p $root_mnt/disk-img && dd if=/dev/zero of=$root_mnt/disk-img/var-log.ext4 count=$((2048*$varlog_size)) && mke2fs -t ext4 -q -F $root_mnt/disk-img/var-log.ext4" +run_cmd "$cmd" "$err_msg" From 7cd263c1ee55fdb18841300f233d768d293d68af Mon Sep 17 00:00:00 2001 From: Guohan Lu Date: Fri, 7 Apr 2017 18:52:43 +0000 Subject: [PATCH 2/2] add more comments, unify the create_varlog --- files/Aboot/boot0.j2 | 1 + files/initramfs-tools/arista-convertfs.j2 | 17 ++++++++++------- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/files/Aboot/boot0.j2 b/files/Aboot/boot0.j2 index c7aafe188bd8..6460ddbbecfc 100644 --- a/files/Aboot/boot0.j2 +++ b/files/Aboot/boot0.j2 @@ -101,6 +101,7 @@ platform_specific() { if [ "$platform" = "raven" ]; then aboot_machine=arista_7050_qx32 echo "modprobe.blacklist=radeon" >>/tmp/append + # set varlog size to 100MB echo "varlog_size=100" >>/tmp/append fi if [ "$platform" = "crow" ]; then diff --git a/files/initramfs-tools/arista-convertfs.j2 b/files/initramfs-tools/arista-convertfs.j2 index 4d182b9e7718..6e3f2d633bff 100644 --- a/files/initramfs-tools/arista-convertfs.j2 +++ b/files/initramfs-tools/arista-convertfs.j2 @@ -83,6 +83,12 @@ run_cmd() { } create_varlog_file() { + local err_msg="Error: create var-log ext4 file" + local cmd="[ -n $varlog_size ] && mkdir -p $root_mnt/disk-img && dd if=/dev/zero of=$root_mnt/disk-img/var-log.ext4 count=$((2048*$varlog_size)) && mke2fs -t ext4 -q -F $root_mnt/disk-img/var-log.ext4" + run_cmd "$cmd" "$err_msg" +} + +mount_and_create_varlog_file() { [ -z "$varlog_size" ] && exit 0 mkdir -p "$root_mnt" mount -t ext4 "$root_dev" "$root_mnt" @@ -93,9 +99,7 @@ create_varlog_file() { exit 0 fi fi - local err_msg="Error: create var-log ext4 file" - local cmd="[ -n $varlog_size ] && mkdir -p $root_mnt/disk-img && dd if=/dev/zero of=$root_mnt/disk-img/var-log.ext4 count=$((2048*$varlog_size)) && mke2fs -t ext4 -q -F $root_mnt/disk-img/var-log.ext4" - run_cmd "$cmd" "$err_msg" + create_varlog_file umount "$root_mnt" exit 0 } @@ -127,7 +131,8 @@ if ! wait_for_root_dev; then exit 1 fi -blkid | grep "$root_dev.*vfat" -q || create_varlog_file +# mount, create varlog file and exit when the root is ext4 +blkid | grep "$root_dev.*vfat" -q || mount_and_create_varlog_file # Get flash dev name if [ -z "$block_flash" ]; then @@ -193,6 +198,4 @@ err_msg="Error: copying files form $tmp_mnt to $root_mnt failed" cmd="cp -a $tmp_mnt/. $root_mnt/" run_cmd "$cmd" "$err_msg" -err_msg="Error: create var-log ext4 file" -cmd="[ -n $varlog_size ] && mkdir -p $root_mnt/disk-img && dd if=/dev/zero of=$root_mnt/disk-img/var-log.ext4 count=$((2048*$varlog_size)) && mke2fs -t ext4 -q -F $root_mnt/disk-img/var-log.ext4" -run_cmd "$cmd" "$err_msg" +create_varlog_file