summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndy Piper <andy.piper@arcticwolf.com>2021-11-22 10:13:42 -0500
committerAndy Piper <andy.piper@arcticwolf.com>2021-11-22 10:26:17 -0500
commit470b0a05ad7717139897f08e24f48d6fedc2a8d6 (patch)
treef3079ce008142c961856b398c3a7bf3b61f63756
parent2a641739075e9907f5c87f705cf7121ab50d339b (diff)
downloadvmdb2-470b0a05ad7717139897f08e24f48d6fedc2a8d6.tar.gz
Add zerofree_plugin.py
The `zerofree` utility zeroes out unused disk space on `ext[2-4]` filesystems and is much faster than using `dd`. This enables better compression of the output disk image when being packaged as a OVA or a Vagrant Box, etc.
-rw-r--r--README.md2
-rw-r--r--amd64-uefi.vmdb2
-rw-r--r--amd64.vmdb2
-rw-r--r--ansible.vmdb2
-rw-r--r--arm64-uefi.vmdb2
-rw-r--r--armhf-uefi.vmdb2
-rw-r--r--i386-uefi.vmdb2
-rw-r--r--i386.vmdb2
-rw-r--r--lvm2.vmdb2
-rw-r--r--pc.vmdb2
-rw-r--r--ppc64el.vmdb2
-rw-r--r--smoke-amd64.vmdb2
-rw-r--r--smoke-i386.vmdb2
-rw-r--r--smoke-pc.vmdb2
-rw-r--r--smoke-ppc64el.vmdb2
-rw-r--r--smoke-uefi-amd64.vmdb2
-rw-r--r--smoke-uefi-arm64.vmdb2
-rw-r--r--smoke-uefi-armhf.vmdb2
-rw-r--r--smoke-uefi-i386.vmdb2
-rw-r--r--smoke-uefi.vmdb2
-rw-r--r--uefi.vmdb2
-rw-r--r--vmdb/plugins/zerofree.mdwn13
-rw-r--r--vmdb/plugins/zerofree_plugin.py38
-rw-r--r--without-tests1
24 files changed, 94 insertions, 0 deletions
diff --git a/README.md b/README.md
index 59c6867..d05eea4 100644
--- a/README.md
+++ b/README.md
@@ -63,6 +63,7 @@ The following tools are used by vmdb2 (Debian package names in brackets).
* `parted` [`parted`, mklabel command]
* `qemu-img` [`qemu-utils`, mkimg command]
* `qemu-user-static` [`qemu-user-static`, qemu-debootstrap command]
+* `zerofree` [`zerofree`, zerofree command]
The following Python modules are used by vmdb2 (Debian package names in brackets).
@@ -97,6 +98,7 @@ You probably need the following installed to run the smoke tests:
- ovmf-ia32
- qemu-efi-aarch64
- qemu-efi-arm
+- zerofree
Tutorial
diff --git a/amd64-uefi.vmdb b/amd64-uefi.vmdb
index 872de16..4fbd85c 100644
--- a/amd64-uefi.vmdb
+++ b/amd64-uefi.vmdb
@@ -61,3 +61,5 @@ steps:
- grub: uefi
tag: /
efi: efi
+
+ - zerofree: /
diff --git a/amd64.vmdb b/amd64.vmdb
index e8efe72..4b110a5 100644
--- a/amd64.vmdb
+++ b/amd64.vmdb
@@ -54,3 +54,5 @@ steps:
- grub: bios
tag: /
quiet: false
+
+ - zerofree: /
diff --git a/ansible.vmdb b/ansible.vmdb
index 55c09cc..24e13ee 100644
--- a/ansible.vmdb
+++ b/ansible.vmdb
@@ -49,3 +49,5 @@ steps:
- grub: bios
tag: /
+
+ - zerofree: /
diff --git a/arm64-uefi.vmdb b/arm64-uefi.vmdb
index 2a72100..f125b2a 100644
--- a/arm64-uefi.vmdb
+++ b/arm64-uefi.vmdb
@@ -61,3 +61,5 @@ steps:
- grub: uefi
tag: /
efi: efi
+
+ - zerofree: /
diff --git a/armhf-uefi.vmdb b/armhf-uefi.vmdb
index 85235a0..b8fb6c9 100644
--- a/armhf-uefi.vmdb
+++ b/armhf-uefi.vmdb
@@ -62,3 +62,5 @@ steps:
tag: /
efi: efi
console: serial
+
+ - zerofree: /
diff --git a/i386-uefi.vmdb b/i386-uefi.vmdb
index e898d6a..bbd05ce 100644
--- a/i386-uefi.vmdb
+++ b/i386-uefi.vmdb
@@ -61,3 +61,5 @@ steps:
- grub: uefi
tag: /
efi: efi
+
+ - zerofree: /
diff --git a/i386.vmdb b/i386.vmdb
index 239b58e..2bd9437 100644
--- a/i386.vmdb
+++ b/i386.vmdb
@@ -54,3 +54,5 @@ steps:
- grub: bios
tag: /
quiet: false
+
+ - zerofree: /
diff --git a/lvm2.vmdb b/lvm2.vmdb
index 8eea87a..084a5a5 100644
--- a/lvm2.vmdb
+++ b/lvm2.vmdb
@@ -73,3 +73,5 @@ steps:
tag: rootfs
image-dev: "{{ image }}"
console: serial
+
+ - zerofree: /
diff --git a/pc.vmdb b/pc.vmdb
index 59aeb9e..58dd646 100644
--- a/pc.vmdb
+++ b/pc.vmdb
@@ -53,3 +53,5 @@ steps:
- grub: bios
tag: /
quiet: false
+
+ - zerofree: /
diff --git a/ppc64el.vmdb b/ppc64el.vmdb
index 5bc4cba..5d28b54 100644
--- a/ppc64el.vmdb
+++ b/ppc64el.vmdb
@@ -59,3 +59,5 @@ steps:
tag: /
prep: prep
console: serial
+
+ - zerofree: /
diff --git a/smoke-amd64.vmdb b/smoke-amd64.vmdb
index ba337ac..ccaff46 100644
--- a/smoke-amd64.vmdb
+++ b/smoke-amd64.vmdb
@@ -70,3 +70,5 @@ steps:
- grub: bios
tag: rootfs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-i386.vmdb b/smoke-i386.vmdb
index 8f769d9..7028505 100644
--- a/smoke-i386.vmdb
+++ b/smoke-i386.vmdb
@@ -70,3 +70,5 @@ steps:
- grub: bios
tag: rootfs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-pc.vmdb b/smoke-pc.vmdb
index ec521f9..62fe20b 100644
--- a/smoke-pc.vmdb
+++ b/smoke-pc.vmdb
@@ -69,3 +69,5 @@ steps:
- grub: bios
tag: rootfs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-ppc64el.vmdb b/smoke-ppc64el.vmdb
index 1111de5..2dc9f53 100644
--- a/smoke-ppc64el.vmdb
+++ b/smoke-ppc64el.vmdb
@@ -71,3 +71,5 @@ steps:
tag: rootfs
prep: prep
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-uefi-amd64.vmdb b/smoke-uefi-amd64.vmdb
index 3044801..74bf8aa 100644
--- a/smoke-uefi-amd64.vmdb
+++ b/smoke-uefi-amd64.vmdb
@@ -74,3 +74,5 @@ steps:
tag: rootfs
efi: efifs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-uefi-arm64.vmdb b/smoke-uefi-arm64.vmdb
index 95e4c4b..bc461b6 100644
--- a/smoke-uefi-arm64.vmdb
+++ b/smoke-uefi-arm64.vmdb
@@ -74,3 +74,5 @@ steps:
tag: rootfs
efi: efifs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-uefi-armhf.vmdb b/smoke-uefi-armhf.vmdb
index 0906dcc..102e13f 100644
--- a/smoke-uefi-armhf.vmdb
+++ b/smoke-uefi-armhf.vmdb
@@ -74,3 +74,5 @@ steps:
tag: rootfs
efi: efifs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-uefi-i386.vmdb b/smoke-uefi-i386.vmdb
index f04d74a..fe3806b 100644
--- a/smoke-uefi-i386.vmdb
+++ b/smoke-uefi-i386.vmdb
@@ -74,3 +74,5 @@ steps:
tag: rootfs
efi: efifs
console: serial
+
+ - zerofree: rootfs
diff --git a/smoke-uefi.vmdb b/smoke-uefi.vmdb
index 2c8545a..72a38cb 100644
--- a/smoke-uefi.vmdb
+++ b/smoke-uefi.vmdb
@@ -74,3 +74,5 @@ steps:
tag: rootfs
efi: efifs
console: serial
+
+ - zerofree: rootfs
diff --git a/uefi.vmdb b/uefi.vmdb
index a29c394..d7405cb 100644
--- a/uefi.vmdb
+++ b/uefi.vmdb
@@ -58,3 +58,5 @@ steps:
- grub: uefi
tag: /
efi: efi
+
+ - zerofree: /
diff --git a/vmdb/plugins/zerofree.mdwn b/vmdb/plugins/zerofree.mdwn
new file mode 100644
index 0000000..5c5baf9
--- /dev/null
+++ b/vmdb/plugins/zerofree.mdwn
@@ -0,0 +1,13 @@
+Step: zerofree
+-----------------------------------------------------------------------------
+
+Executes `zerofree` to zero out unused space in a ext2/3/4 filesystem
+
+Step keys:
+
+* `zerofree` &mdash; REQUIRED; value is the tag for the filesystem on which to
+ zero out free space.
+
+Example (in the .vmdb file):
+
+ - zerofree: root
diff --git a/vmdb/plugins/zerofree_plugin.py b/vmdb/plugins/zerofree_plugin.py
new file mode 100644
index 0000000..a22fa46
--- /dev/null
+++ b/vmdb/plugins/zerofree_plugin.py
@@ -0,0 +1,38 @@
+# Copyright 2021 Andy Piper
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# =*= License: GPL-3+ =*=
+
+import vmdb
+
+
+class ZerofreePlugin(vmdb.Plugin):
+ def enable(self):
+ self.app.step_runners.add(ZerofreeStepRunner())
+
+
+class ZerofreeStepRunner(vmdb.StepRunnerInterface):
+ def get_key_spec(self):
+ return {"zerofree": str}
+
+ def run(self, values, settings, state):
+ tag = values["zerofree"]
+ dev = state.tags.get_dev(tag)
+ mount_point = state.tags.get_builder_mount_point(tag)
+ try:
+ vmdb.runcmd(["mount", "-o", "remount,ro", mount_point])
+ vmdb.runcmd(["zerofree", "-v", dev])
+ finally:
+ vmdb.runcmd(["mount", "-o", "remount,rw", mount_point])
diff --git a/without-tests b/without-tests
index 49079d0..17ce589 100644
--- a/without-tests
+++ b/without-tests
@@ -27,6 +27,7 @@ vmdb/plugins/shell_plugin.py
vmdb/plugins/unpack_rootfs_plugin.py
vmdb/plugins/vgcreate_plugin.py
vmdb/plugins/virtualfs_plugin.py
+vmdb/plugins/zerofree_plugin.py
vmdb/runcmd.py
vmdb/state.py
vmdb/version.py