Allow opt-out of full ramdisk pruning

While aggressively pruning ramdisk contents reduces the size, it can
break packages that depend on any of the pruned directories existing.
Allow anyone impacted by that case to opt out.

Change-Id: I1b5a65a56d151a26ee44446c20c6df31bb695223
This commit is contained in:
Jay Faulkner 2021-08-09 14:51:52 -07:00
parent 8ba630fb22
commit 5c8fc6fd31
2 changed files with 53 additions and 25 deletions

View File

@ -3,3 +3,12 @@ ironic-ramdisk-base
This is a base element for ironic ramdisks. It does not install anything, just This is a base element for ironic ramdisks. It does not install anything, just
takes the prepared images and extract kernel/ramdisk from it. takes the prepared images and extract kernel/ramdisk from it.
Configurable Environment Variables
----------------------------------
- `DIB_IPA_COMPRESS_COMMAND` defaults to `gzip`, may be set to any valid
compression program usable for an initramfs
- `DIB_IPA_MINIMAL_PRUNE` defaults to `0` (false). If set to `1`, will skip
most ramdisk size optimizations. This may be helpful for use of packages
with IPA that require otherwise-pruned directories or files.

View File

@ -24,31 +24,50 @@ echo "#disabled" > ./tmp/fstab.new
sudo mv ./tmp/fstab.new ./etc/fstab sudo mv ./tmp/fstab.new ./etc/fstab
sudo ln -s ./sbin/init ./ sudo ln -s ./sbin/init ./
# Note: The pci.ids, which is used by lshw, locate on Ubuntu # Note(JayF): to anyone trying to make this more configurable in the future,
# in /usr/share/misc. Therefore we are removing only the # there are significant hurdles around shell quoting if you try to put these
# ./usr/share/misc/m* (will remove the magic and magic.mgc files). # find commands into variables for making them more configurable.
# on RHEL pci.ids is locate on /usr/share/hwdata/pci.ids. if [ "${DIB_IPA_MINIMAL_PRUNE:-0}" -gt 0 ]; then
sudo find . -xdev \ # Operator opted out of full ramdisk pruning; do not proactively remove
-path './sys/*' -prune -o \ # directories that may be in use by other elements/packages
-path './tmp/*' -prune -o \ sudo find . -xdev \
-path './boot/*' -prune -o \ -path './sys/*' -prune -o \
-path './root/.cache' -prune -o \ -path './tmp/*' -prune -o \
-path "*site-packages/babel/locale-data/*" -prune -o \ -path './boot/*' -prune -o \
-path './usr/include/*' -prune -o \ -path './root/.cache' -prune -o \
-path './usr/lib/locale/*' -prune -o \ -name '*.pyc' -prune -o \
-path './usr/share/doc/*' -prune -o \ -name '*.pyo' -prune -o \
-path './usr/share/man/*' -prune -o \ -print | sudo cpio -o -H newc | ${DIB_IPA_COMPRESS_CMD} > ${IMAGE_PATH}.initramfs
-path './usr/share/GeoIP/*' -prune -o \ else
-path './usr/share/info/*' -prune -o \ # This performs a full prune, leading to the smallest possible ramdisk
-path './usr/share/licenses/*' -prune -o \ # size. This may break operator-configured packages or elements that
-path './usr/share/locale/*' -prune -o \ # depend on pruned paths.
-path './usr/share/misc/m*' -prune -o \ # Note: The pci.ids, which is used by lshw, are located on Ubuntu
-path './usr/src/kernels/*' -prune -o \ # in /usr/share/misc. Therefore we are removing only the
-path './var/cache/*' -prune -o \ # ./usr/share/misc/m* (will remove the magic and magic.mgc files).
-path './var/log/*' -prune -o \ # on RHEL pci.ids is locate on /usr/share/hwdata/pci.ids.
-name '*.pyc' -prune -o \ sudo find . -xdev \
-name '*.pyo' -prune -o \ -path './sys/*' -prune -o \
-print | sudo cpio -o -H newc | ${DIB_IPA_COMPRESS_CMD} > ${IMAGE_PATH}.initramfs -path './tmp/*' -prune -o \
-path './boot/*' -prune -o \
-path './root/.cache' -prune -o \
-path "*site-packages/babel/locale-data/*" -prune -o \
-path './usr/include/*' -prune -o \
-path './usr/lib/locale/*' -prune -o \
-path './usr/share/doc/*' -prune -o \
-path './usr/share/man/*' -prune -o \
-path './usr/share/GeoIP/*' -prune -o \
-path './usr/share/info/*' -prune -o \
-path './usr/share/licenses/*' -prune -o \
-path './usr/share/locale/*' -prune -o \
-path './usr/share/misc/m*' -prune -o \
-path './usr/src/kernels/*' -prune -o \
-path './var/cache/*' -prune -o \
-path './var/log/*' -prune -o \
-name '*.pyc' -prune -o \
-name '*.pyo' -prune -o \
-print | sudo cpio -o -H newc | ${DIB_IPA_COMPRESS_CMD} > ${IMAGE_PATH}.initramfs
fi
select_boot_kernel_initrd $TARGET_ROOT select_boot_kernel_initrd $TARGET_ROOT
sudo cp $BOOTDIR/$KERNEL ${IMAGE_PATH}.kernel sudo cp $BOOTDIR/$KERNEL ${IMAGE_PATH}.kernel