dracut-initramfs-restore.sh: try to mount /boot
[dracut.git] / dracut-initramfs-restore.sh
blob0e6a1a88a76499e81ad7958ad26d956cae3294ef
1 #!/bin/bash
3 set -e
5 # do some sanity checks first
6 [ -e /run/initramfs/bin/sh ] && exit 0
7 [ -e /run/initramfs/.need_shutdown ] || exit 0
9 KERNEL_VERSION="$(uname -r)"
11 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
12 SKIP="$dracutbasedir/skipcpio"
13 [[ -x $SKIP ]] || SKIP=cat
15 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
17 mount -o ro /boot &>/dev/null
19 if [[ $MACHINE_ID ]] && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
20 IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
22 [[ -f $IMG ]] || IMG="/boot/initramfs-${KERNEL_VERSION}.img"
24 cd /run/initramfs
26 [ -f .need_shutdown -a -f "$IMG" ] || exit 1
28 if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
29 rm -f -- .need_shutdown
30 elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
31 rm -f -- .need_shutdown
32 elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
33 rm -f -- .need_shutdown
34 else
35 # something failed, so we clean up
36 echo "Unpacking of $IMG to /run/initramfs failed" >&2
37 rm -f -- /run/initramfs/shutdown
38 exit 1
41 exit 0