[build]: enable docker in ram option for small disk device ()

when device disk is small, do not unzip dockerfs.tar.gz on disk.
keep the tar file on the disk, unzip to tmpfs in the initrd phase.

enabled this for 7050-qx32

Signed-off-by: Guohan Lu <gulv@microsoft.com>
This commit is contained in:
lguohan 2019-08-06 23:04:00 -07:00 committed by GitHub
parent 629688b487
commit 2b28d55853
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 44 additions and 19 deletions

View File

@ -164,8 +164,10 @@ extract_image() {
rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3` rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3`
info "Extracting $dockerfs from swi" info "Extracting $dockerfs from swi"
## vfat does not support symbol link ## Unpacking dockerfs delayed
if [ "$rootfs_type" != "vfat" ]; then ## 1. when disk is vfat as it does not support symbolic link
## 2. when disk is small, expand it into ramfs during initrd
if [ "$rootfs_type" != "vfat" -a x"$docker_inram" != x"on" ]; then
mkdir -p "$image_path/{{ DOCKERFS_DIR }}" mkdir -p "$image_path/{{ DOCKERFS_DIR }}"
if [ -n "$install" ]; then if [ -n "$install" ]; then
@ -177,7 +179,7 @@ extract_image() {
else else
## save dockerfs archive in the image directory ## save dockerfs archive in the image directory
unzip -oq "$swipath" "$dockerfs" -d "$image_path" unzip -oq "$swipath" "$dockerfs" -d "$image_path"
info "Unpacking $dockerfs delayed to initrd because $target_path is $rootfs_type" info "Unpacking $dockerfs delayed to initrd because $target_path is $rootfs_type or docker_inram is on"
fi fi
## remove installer since it's not needed anymore ## remove installer since it's not needed anymore
@ -225,7 +227,8 @@ platform_specific() {
if [ "$platform" = "raven" ]; then if [ "$platform" = "raven" ]; then
aboot_machine=arista_7050_qx32 aboot_machine=arista_7050_qx32
flash_size=2000 flash_size=2000
echo "modprobe.blacklist=radeon,sp5100_tco acpi=off" >>/tmp/append docker_inram=on
echo "modprobe.blacklist=radeon,sp5100_tco acpi=off docker_inram=on" >>/tmp/append
fi fi
if [ "$platform" = "crow" ]; then if [ "$platform" = "crow" ]; then
aboot_machine=arista_7050_qx32s aboot_machine=arista_7050_qx32s
@ -343,6 +346,7 @@ write_boot_configs() {
fi fi
fi fi
mkdir -p "$image_path"
cat /tmp/append > $cmdline_image cat /tmp/append > $cmdline_image
[ -e ${target_path}/machine.conf ] || write_machine_config [ -e ${target_path}/machine.conf ] || write_machine_config
} }
@ -441,12 +445,12 @@ if $do_install; then
clean_flash clean_flash
fi fi
info "Installing image under $image_path"
extract_image
info "Generating boot-config, machine.conf and cmdline" info "Generating boot-config, machine.conf and cmdline"
write_boot_configs write_boot_configs
info "Installing image under $image_path"
extract_image
run_hooks post-install run_hooks post-install
else else
info "Using previously installed image" info "Using previously installed image"

View File

@ -130,6 +130,9 @@ for x in "$@"; do
x1="${x#loop=}" x1="${x#loop=}"
image_dir="${x1%/*}" image_dir="${x1%/*}"
;; ;;
docker_inram=*)
docker_inram="${x#docker_inram=}"
;;
SONIC_BOOT_TYPE=warm*|SONIC_BOOT_TYPE=fast*) SONIC_BOOT_TYPE=warm*|SONIC_BOOT_TYPE=fast*)
# Skip this script for warm-reboot and fast-reboot # Skip this script for warm-reboot and fast-reboot
exit 0 exit 0
@ -221,9 +224,11 @@ err_msg="Error: mounting $root_dev to $root_mnt failed"
cmd="mount -t ext4 $root_dev $root_mnt" cmd="mount -t ext4 $root_dev $root_mnt"
run_cmd "$cmd" "$err_msg" run_cmd "$cmd" "$err_msg"
err_msg="Error: extract docker directory" if [ x"$docker_inram" != x"on" ]; then
cmd="[ -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && mkdir -p $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }}" err_msg="Error: extract docker directory"
run_cmd "$cmd" "$err_msg" cmd="[ -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} ] && rm -rf $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && mkdir -p $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && tar xzf $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }} -C $root_mnt/$image_dir/{{ DOCKERFS_DIR }} && rm -f $tmp_mnt/$image_dir/{{ FILESYSTEM_DOCKERFS }}"
run_cmd "$cmd" "$err_msg"
fi
err_msg="Error: copying files form $tmp_mnt to $root_mnt failed" err_msg="Error: copying files form $tmp_mnt to $root_mnt failed"
cmd="cp -a $tmp_mnt/. $root_mnt/" cmd="cp -a $tmp_mnt/. $root_mnt/"

View File

@ -47,9 +47,17 @@ mount -n -o lowerdir=${rootmnt},upperdir=${rootmnt}/host/$image_dir/rw,workdir=$
[ -b ${ROOT} ] || mdev -s [ -b ${ROOT} ] || mdev -s
## Mount the raw partition again ## Mount the raw partition again
mount ${ROOT} ${rootmnt}/host mount ${ROOT} ${rootmnt}/host
## Mount the working directory of docker engine in the raw partition, bypass the overlay
mkdir -p ${rootmnt}/var/lib/docker mkdir -p ${rootmnt}/var/lib/docker
mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker if [ -f ${rootmnt}/host/$image_dir/{{ FILESYSTEM_DOCKERFS }} ]; then
## mount tmpfs and extract docker into it
mount -t tmpfs -o rw,nodev,size={{ DOCKER_RAMFS_SIZE }} tmpfs ${rootmnt}/var/lib/docker
tar xz --numeric-owner -f ${rootmnt}/host/$image_dir/{{ FILESYSTEM_DOCKERFS }} -C ${rootmnt}/var/lib/docker
else
## Mount the working directory of docker engine in the raw partition, bypass the overlay
mount --bind ${rootmnt}/host/$image_dir/{{ DOCKERFS_DIR }} ${rootmnt}/var/lib/docker
fi
## Mount the boot directory in the raw partition, bypass the overlay ## Mount the boot directory in the raw partition, bypass the overlay
mkdir -p ${rootmnt}/boot mkdir -p ${rootmnt}/boot
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot

View File

@ -479,15 +479,20 @@ else
fi fi
# Decompress the file for the file system directly to the partition # Decompress the file for the file system directly to the partition
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir if [ x"$docker_inram" = x"on" ]; then
# when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd
if [ "$install_env" = "onie" ]; then unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
TAR_EXTRA_OPTION="--numeric-owner"
else else
unzip -o $ONIE_INSTALLER_PAYLOAD -x "$FILESYSTEM_DOCKERFS" -d $demo_mnt/$image_dir
if [ "$install_env" = "onie" ]; then
TAR_EXTRA_OPTION="--numeric-owner"
else
TAR_EXTRA_OPTION="--numeric-owner --warning=no-timestamp" TAR_EXTRA_OPTION="--numeric-owner --warning=no-timestamp"
fi
mkdir -p $demo_mnt/$image_dir/$DOCKERFS_DIR
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
fi fi
mkdir -p $demo_mnt/$image_dir/$DOCKERFS_DIR
unzip -op $ONIE_INSTALLER_PAYLOAD "$FILESYSTEM_DOCKERFS" | tar xz $TAR_EXTRA_OPTION -f - -C $demo_mnt/$image_dir/$DOCKERFS_DIR
if [ "$install_env" = "onie" ]; then if [ "$install_env" = "onie" ]; then
# Store machine description in target file system # Store machine description in target file system

View File

@ -24,6 +24,9 @@ FILESYSTEM_DOCKERFS=dockerfs.tar.gz
## docker directory on the root filesystem ## docker directory on the root filesystem
DOCKERFS_DIR=docker DOCKERFS_DIR=docker
## docker ramfs disk space
DOCKER_RAMFS_SIZE=800M
## Output file name for onie installer ## Output file name for onie installer
OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin