Date: Fri, 20 Mar 2015 19:40:20 +0000 (UTC) From: Colin Percival <cperciva@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r280299 - in head/release: scripts tools Message-ID: <201503201940.t2KJeKxH015914@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: cperciva Date: Fri Mar 20 19:40:19 2015 New Revision: 280299 URL: https://svnweb.freebsd.org/changeset/base/280299 Log: When creating VM images, copy the contents of the created filesystem into a new filesystem before packaging it into a disk image. This prevents "remnants" of deleted files from showing up in the VM images, and reduces their compressed size (by about 10% for the cloudware images) as a result. Looks good to: gjb Modified: head/release/scripts/mk-vmimage.sh head/release/tools/vmimage.subr Modified: head/release/scripts/mk-vmimage.sh ============================================================================== --- head/release/scripts/mk-vmimage.sh Fri Mar 20 19:29:59 2015 (r280298) +++ head/release/scripts/mk-vmimage.sh Fri Mar 20 19:40:19 2015 (r280299) @@ -102,6 +102,7 @@ main() { vm_extra_pre_umount vm_extra_pkg_rmcache cleanup + vm_copy_base vm_create_disk || return 0 vm_extra_create_disk Modified: head/release/tools/vmimage.subr ============================================================================== --- head/release/tools/vmimage.subr Fri Mar 20 19:29:59 2015 (r280298) +++ head/release/tools/vmimage.subr Fri Mar 20 19:40:19 2015 (r280299) @@ -67,6 +67,35 @@ vm_create_base() { return 0 } +vm_copy_base() { + # Creates a new UFS root filesystem and copies the contents of the + # current root filesystem into it. This produces a "clean" disk + # image without any remnants of files which were created temporarily + # during image-creation and have since been deleted (e.g., downloaded + # package archives). + + mkdir -p ${DESTDIR}/old + mdold=$(mdconfig -f ${VMBASE}) + mount /dev/${mdold} ${DESTDIR}/old + + truncate -s ${VMSIZE} ${VMBASE}.tmp + mkdir -p ${DESTDIR}/new + mdnew=$(mdconfig -f ${VMBASE}.tmp) + newfs -j /dev/${mdnew} + mount /dev/${mdnew} ${DESTDIR}/new + + tar -cf- -C ${DESTDIR}/old . | tar -xf- -C ${DESTDIR}/new + + umount /dev/${mdold} + rmdir ${DESTDIR}/old + mdconfig -d -u ${mdold} + + umount /dev/${mdnew} + rmdir ${DESTDIR}/new + mdconfig -d -u ${mdnew} + mv ${VMBASE}.tmp ${VMBASE} +} + vm_install_base() { # Installs the FreeBSD userland/kernel to the virtual machine disk.
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201503201940.t2KJeKxH015914>