From cf1cb624d74422f64fb68c28fa99039b9f716c9c Mon Sep 17 00:00:00 2001 From: Luke Yelavich Date: Tue, 8 Apr 2008 16:52:23 +1000 Subject: update-initramfs: Initramfs generation reliability fixes. Attached is a patch to improve the way update-initramfs handles the generating of new or updated initramfs images for kernels. It puts in place a few measures to ensure that if there is not enough disk space on /boot, a previous initramfs is still in tact, to allow the booting of that kernel. The patch applies against current git head. See the Ubuntu specification found at the following URL for more information: https://wiki.ubuntu.com/HardyInitramfsErrorHandling This patch does the following: * When generating a new initramfs, instead of copying the old initramfs to a backup file, it hard links it instead, so no more space is used than necessary. it only copies to the backup file in the event that the filesystem on /boot doesn't support hard links, eg FAT32 partitions. * A new file is used to generate the initramfs. If the generation succeeds, it is moved to the original initramfs's location, ready to use. If it fails, the original initramfs is not affected, allowing it to be used at boot. [ wrap on long line -maks ] --- update-initramfs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'update-initramfs') diff --git a/update-initramfs b/update-initramfs index 6e8e7aa..a4947bf 100755 --- a/update-initramfs +++ b/update-initramfs @@ -100,7 +100,8 @@ backup_initramfs() [ ! -r "${initramfs}" ] && return 0 initramfs_bak="${initramfs}.dpkg-bak" [ -r "${initramfs_bak}" ] && rm -f "${initramfs_bak}" - mv -f "${initramfs}" "${initramfs_bak}" + ln -f "${initramfs}" "${initramfs_bak}" \ + || cp -a "${initramfs}" "${initramfs_bak}" verbose "Keeping ${initramfs_bak}" } @@ -143,8 +144,8 @@ backup_booted_initramfs() restore_initramfs() { [ -z "${initramfs_bak}" ] && return 0 + rm -f "${initramfs_bak}" verbose "Restoring ${initramfs_bak}" - mv -f "${initramfs_bak}" "${initramfs}" } @@ -155,11 +156,13 @@ generate_initramfs() if [ "${verbose}" = 1 ]; then OPTS="-v ${OPTS}" fi - if mkinitramfs ${OPTS} "${initramfs}" "${version}"; then + if mkinitramfs ${OPTS} "${initramfs}.new" "${version}"; then + mv -f "${initramfs}.new" "${initramfs}" set_sha1 else mkinitramfs_return="$?" restore_initramfs + rm -f "${initramfs}.new" if [ "$mkinitramfs_return" = "2" ]; then # minversion wasn't met, exit 0 exit 0 -- cgit v1.2.3