Skip to content
Snippets Groups Projects
Commit fef37d59 authored by maximilian attems's avatar maximilian attems
Browse files

hooks: Add resume hook instead of hardcoding RESUME once on preinst


This logic is better run every time on update-initramfs,
as swap partition of a system might change.
Also there are scenarios where the preinstall picks up
a wrong value that stays wrongly hardcoded.
This results in a 5s useless wait on boot.

The biggest swap partition is used as valid guess.
This was previously the logic and is the logic used by ubiquity
(Ubuntu live installer) too.

Closes: #565225, LP 50437.

Thanks-to: Dmitrijs Ledkovs <launchpad@surgut.co.uk>
Reviewed-by: default avatarMartin Pitt <martin.pitt@ubuntu.com>
Reviewed-by: default avatarMichael Prokop <mika@debian.org>
Signed-off-by: default avatarmaximilian attems <maks@debian.org>
parent 90f4cdb7
No related branches found
No related tags found
No related merge requests found
#!/bin/sh
set -e
chrooted() {
# borrowed from udev's postinst
if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
# the devicenumber/inode pair of / is the same as that of
# /sbin/init's root, so we're *not* in a chroot and hence
# return false.
return 1
fi
return 0
}
case "$1" in
install)
mkdir -p /etc/initramfs-tools/conf.d
# First time install. Can we autodetect the RESUME partition?
if [ -r /proc/swaps ]; then
RESUME=$(grep ^/dev/ /proc/swaps | sort -rk3 \
| head -n 1 | cut -d " " -f 1)
if command -v blkid >/dev/null 2>&1; then
UUID=$(blkid -s UUID -o value "$RESUME" || true)
# FIXME: post-Wheezy remove vol_id invocations
elif command -v vol_id >/dev/null 2>&1; then
UUID=$(vol_id -u "$RESUME" || true)
elif [ -x /lib/udev/vol_id ]; then
UUID=$(/lib/udev/vol_id -u "$RESUME" || true)
fi
if [ -n "$UUID" ]; then
RESUME="UUID=$UUID"
fi
fi
# write conf.d/resume if not in a chroot
if [ -n "${RESUME}" ] && ! chrooted; then
echo "RESUME=${RESUME}" > /etc/initramfs-tools/conf.d/resume
fi
;;
esac
#DEBHELPER#
#!/bin/sh
PREREQ=""
prereqs()
{
echo "$PREREQ"
}
case $1 in
# get pre-requisites
prereqs)
prereqs
exit 0
;;
esac
# we need to be able to read the listed swap partitions
if [ ! -r /proc/swaps ]; then
exit 0
fi
# borrowed from udev's postinst
chrooted() {
if [ "$(stat -c %d/%i /)" = "$(stat -Lc %d/%i /proc/1/root 2>/dev/null)" ]; then
# the devicenumber/inode pair of / is the same as that of
# /sbin/init's root, so we're *not* in a chroot and hence
# return false.
return 1
fi
return 0
}
# Try to autodetect the RESUME partition, using biggest swap?
RESUME=$(grep ^/dev/ /proc/swaps | sort -rk3 | head -n 1 | cut -d " " -f 1)
if command -v blkid >/dev/null 2>&1; then
UUID=$(blkid -s UUID -o value "$RESUME" || true)
if [ -n "$UUID" ]; then
RESUME="UUID=$UUID"
fi
fi
# write conf.d/resume if not in a chroot
if [ -n "${RESUME}" ] && !chrooted; then
echo "RESUME=${RESUME}" > ${DESTDIR}/conf/conf.d/resume
fi
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment