diff options
author | cperciva <cperciva@FreeBSD.org> | 2015-03-20 19:40:19 +0000 |
---|---|---|
committer | cperciva <cperciva@FreeBSD.org> | 2015-03-20 19:40:19 +0000 |
commit | f1bd255f86352b07d53eb60ade18228291abe5cf (patch) | |
tree | 7e1d639597ef636c5b0745b3c01cdd6f6842d7aa | |
parent | 19f36523e1d1ff76a010b5b0d5da02023a49d37e (diff) | |
download | FreeBSD-src-f1bd255f86352b07d53eb60ade18228291abe5cf.zip FreeBSD-src-f1bd255f86352b07d53eb60ade18228291abe5cf.tar.gz |
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
-rwxr-xr-x | release/scripts/mk-vmimage.sh | 1 | ||||
-rw-r--r-- | release/tools/vmimage.subr | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/release/scripts/mk-vmimage.sh b/release/scripts/mk-vmimage.sh index 16c33c8..d5985ce 100755 --- a/release/scripts/mk-vmimage.sh +++ b/release/scripts/mk-vmimage.sh @@ -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 diff --git a/release/tools/vmimage.subr b/release/tools/vmimage.subr index 6207440..828db35 100644 --- a/release/tools/vmimage.subr +++ b/release/tools/vmimage.subr @@ -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. |