Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build]: enable docker in ram option for small disk device #3279

Merged
merged 9 commits into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions files/Aboot/boot0.j2
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,10 @@ extract_image() {
rootfs_type=`grep " $target_path " /proc/mounts | cut -d' ' -f3`

info "Extracting $dockerfs from swi"
## vfat does not support symbol link
if [ "$rootfs_type" != "vfat" ]; then
## Unpacking dockerfs delayed
## 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 }}"

if [ -n "$install" ]; then
Expand All @@ -177,7 +179,7 @@ extract_image() {
else
## save dockerfs archive in the image directory
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

## remove installer since it's not needed anymore
Expand Down Expand Up @@ -225,7 +227,8 @@ platform_specific() {
if [ "$platform" = "raven" ]; then
aboot_machine=arista_7050_qx32
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
if [ "$platform" = "crow" ]; then
aboot_machine=arista_7050_qx32s
Expand Down Expand Up @@ -343,6 +346,7 @@ write_boot_configs() {
fi
fi

mkdir -p "$image_path"
cat /tmp/append > $cmdline_image
[ -e ${target_path}/machine.conf ] || write_machine_config
}
Expand Down Expand Up @@ -441,12 +445,12 @@ if $do_install; then
clean_flash
fi

info "Installing image under $image_path"
extract_image

info "Generating boot-config, machine.conf and cmdline"
write_boot_configs

info "Installing image under $image_path"
extract_image

run_hooks post-install
else
info "Using previously installed image"
Expand Down
11 changes: 8 additions & 3 deletions files/initramfs-tools/arista-convertfs.j2
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,9 @@ for x in "$@"; do
x1="${x#loop=}"
image_dir="${x1%/*}"
;;
docker_inram=*)
docker_inram="${x#docker_inram=}"
;;
SONIC_BOOT_TYPE=warm*|SONIC_BOOT_TYPE=fast*)
# Skip this script for warm-reboot and fast-reboot
exit 0
Expand Down Expand Up @@ -221,9 +224,11 @@ err_msg="Error: mounting $root_dev to $root_mnt failed"
cmd="mount -t ext4 $root_dev $root_mnt"
run_cmd "$cmd" "$err_msg"

err_msg="Error: extract docker directory"
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"
if [ x"$docker_inram" != x"on" ]; then
err_msg="Error: extract docker directory"
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"
cmd="cp -a $tmp_mnt/. $root_mnt/"
Expand Down
12 changes: 10 additions & 2 deletions files/initramfs-tools/union-mount.j2
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ mount -n -o lowerdir=${rootmnt},upperdir=${rootmnt}/host/$image_dir/rw,workdir=$
[ -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 overlay

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
mkdir -p ${rootmnt}/boot
mount --bind ${rootmnt}/host/$image_dir/boot ${rootmnt}/boot
Expand Down
19 changes: 12 additions & 7 deletions installer/x86_64/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -479,15 +479,20 @@ else
fi

# 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 [ "$install_env" = "onie" ]; then
TAR_EXTRA_OPTION="--numeric-owner"
if [ x"$docker_inram" = x"on" ]; then
# when disk is small, keep dockerfs.tar.gz in disk, expand it into ramfs during initrd
unzip -o $ONIE_INSTALLER_PAYLOAD -d $demo_mnt/$image_dir
else
TAR_EXTRA_OPTION="--numeric-owner --warning=no-timestamp"
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"
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
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

lguohan marked this conversation as resolved.
Show resolved Hide resolved
if [ "$install_env" = "onie" ]; then
# Store machine description in target file system
Expand Down
3 changes: 3 additions & 0 deletions onie-image.conf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ FILESYSTEM_DOCKERFS=dockerfs.tar.gz
## docker directory on the root filesystem
DOCKERFS_DIR=docker

## docker ramfs disk space
DOCKER_RAMFS_SIZE=800M

## Output file name for onie installer
OUTPUT_ONIE_IMAGE=target/sonic-$TARGET_MACHINE.bin

Expand Down