From f3413b473d216af7a1e595efe565241b5ec3d929 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Mon, 9 Sep 2013 16:12:44 -0700 Subject: [PATCH 1/3] feat(build_library): generate squashfs in cpio squashfs is more efficient and plays well with namespaces. Switch to generating a cpio with a single squashfs files. --- build_library/vm_image_util.sh | 43 +++++++++++++++++----------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index ce4f088845..b666ef9314 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -336,21 +336,20 @@ _write_vmdk_scsi_disk() { # the cpio is a little complicated because everything gets put into one # ramfs. So, it does a lot more work at the write disk step. _write_cpio_disk() { + local cpio_target="${VM_TMP_DIR}/rootcpio" if [ -f "$2" ]; then rm $2 fi + # Create the cpio with squashfs embedded + _write_squashfs_root ${cpio_target} + + # Create the cpio and gzip it local cpio=${VM_TMP_DIR}/root.cpio - _write_base_cpio_disk $1 ${cpio} $2 - _write_overlay_cpio_disk $1 ${cpio} - - # Copy the oem partition in - local oem_mnt="${VM_TMP_DIR}/oem" - _write_dir_to_cpio ${oem_mnt} ${cpio} - sudo rm -R "${VM_TMP_DIR}/oem" - + _write_dir_to_cpio "${cpio_target}" "${cpio}" gzip < ${cpio} > $2 + rm -rf "${cpio_target}" } _write_dir_to_cpio() { @@ -364,31 +363,33 @@ _write_dir_to_cpio() { popd >/dev/null } -_write_base_cpio_disk() { +_write_squashfs_root() { + local cpio_target="$1" local root_mnt="${VM_TMP_DIR}/rootfs" + local root_build="${VM_TMP_DIR}/rootbuild" local dst_dir=$(_dst_dir) local vmlinuz_name="$(_dst_name ".vmlinuz")" mkdir -p "${root_mnt}" + mkdir -p "${root_build}" + mkdir -p "${cpio_target}" - # Roll the rootfs into the CPIO + # Roll the rootfs into the build dir sudo mount -o loop,ro "${TEMP_ROOTFS}" "${root_mnt}" - _write_dir_to_cpio "${root_mnt}" "$2" + sudo cp -Ra "${root_mnt}"/. "${root_build}" cp "${root_mnt}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}" sudo umount "${root_mnt}" - rm -rf "${root_mnt}" -} -_write_overlay_cpio_disk() { - local root_overlay="${VM_TMP_DIR}/rootoverlay" - mkdir -p "${root_overlay}" + # Roll the OEM into the build dir + local oem_mnt="${VM_TMP_DIR}/oem" + sudo cp -Ra "${oem_mnt}" "${root_build}" + sudo rm -R "${VM_TMP_DIR}/oem" - # HACK(philips): keep dracut from initing our system by sylinking here. - ln -s sbin/init ${root_overlay}/init + # Build the squashfs + sudo mksquashfs "${root_build}" "${cpio_target}"/newroot.squashfs + ls -la ${cpio_target} - _write_dir_to_cpio "${root_overlay}" "$2" - - sudo rm -rf "${root_overlay}" + sudo rm -rf "${root_mnt}" "${root_build}" } # If a config format is defined write it! From 2605c6ca952ec8d2a05e7673132c53ed3d3e18ca Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Mon, 9 Sep 2013 17:47:10 -0700 Subject: [PATCH 2/3] feat(vm_image_util): use bind mounts for pxe oem solid cleanup idea from marineam to use bind mounts instead of copying to generate the desired root layout. --- build_library/vm_image_util.sh | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index b666ef9314..66695a07db 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -366,30 +366,27 @@ _write_dir_to_cpio() { _write_squashfs_root() { local cpio_target="$1" local root_mnt="${VM_TMP_DIR}/rootfs" - local root_build="${VM_TMP_DIR}/rootbuild" + local oem_mnt="${VM_TMP_DIR}/oem" local dst_dir=$(_dst_dir) local vmlinuz_name="$(_dst_name ".vmlinuz")" mkdir -p "${root_mnt}" - mkdir -p "${root_build}" mkdir -p "${cpio_target}" # Roll the rootfs into the build dir sudo mount -o loop,ro "${TEMP_ROOTFS}" "${root_mnt}" - sudo cp -Ra "${root_mnt}"/. "${root_build}" - cp "${root_mnt}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}" - sudo umount "${root_mnt}" # Roll the OEM into the build dir - local oem_mnt="${VM_TMP_DIR}/oem" - sudo cp -Ra "${oem_mnt}" "${root_build}" - sudo rm -R "${VM_TMP_DIR}/oem" - + sudo mount --bind "${oem_mnt}"/usr/share/oem "${root_mnt}"/usr/share/oem # Build the squashfs - sudo mksquashfs "${root_build}" "${cpio_target}"/newroot.squashfs - ls -la ${cpio_target} + sudo mksquashfs "${root_mnt}" "${cpio_target}"/newroot.squashfs - sudo rm -rf "${root_mnt}" "${root_build}" + cp "${root_mnt}"/boot/vmlinuz "${dst_dir}/${vmlinuz_name}" + + sudo umount "${root_mnt}"/usr/share/oem + sudo umount "${root_mnt}" + + sudo rm -rf "${root_mnt}" } # If a config format is defined write it! From 05a4974836ded2ae4922d2837b2b662fe7a51c08 Mon Sep 17 00:00:00 2001 From: Brandon Philips Date: Mon, 9 Sep 2013 18:06:17 -0700 Subject: [PATCH 3/3] fix(vm_image_util): remove /usr/share/oem prefix remove this prefix from the PARTIIONED=0 builds --- build_library/vm_image_util.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/build_library/vm_image_util.sh b/build_library/vm_image_util.sh index 66695a07db..778c88c467 100644 --- a/build_library/vm_image_util.sh +++ b/build_library/vm_image_util.sh @@ -257,7 +257,7 @@ install_oem_package() { # Install directly to root if this is not a partitioned image if [[ $(_get_vm_opt PARTITIONED_IMG) -eq 0 ]]; then - emerge_oem_package "${oem_mnt}/usr/share/oem" + emerge_oem_package "${oem_mnt}" return 0 fi @@ -377,7 +377,7 @@ _write_squashfs_root() { sudo mount -o loop,ro "${TEMP_ROOTFS}" "${root_mnt}" # Roll the OEM into the build dir - sudo mount --bind "${oem_mnt}"/usr/share/oem "${root_mnt}"/usr/share/oem + sudo mount --bind "${oem_mnt}" "${root_mnt}"/usr/share/oem # Build the squashfs sudo mksquashfs "${root_mnt}" "${cpio_target}"/newroot.squashfs