]> git.ipfire.org Git - thirdparty/dracut.git/blob - dracut-initramfs-restore.sh
iscsi: always popd, even if there is no iscsi device
[thirdparty/dracut.git] / dracut-initramfs-restore.sh
1 #!/bin/bash
2
3 set -e
4
5 # do some sanity checks first
6 [ -e /run/initramfs/bin/sh ] && exit 0
7 [ -e /run/initramfs/.need_shutdown ] || exit 0
8
9 KERNEL_VERSION="$(uname -r)"
10
11 [[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
12 SKIP="$dracutbasedir/skipcpio"
13 [[ -x $SKIP ]] || SKIP=cat
14
15 [[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
16
17 mount -o ro /boot &>/dev/null || true
18
19 if [[ $MACHINE_ID ]] && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
20 IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
21 fi
22 [[ -f $IMG ]] || IMG="/boot/initramfs-${KERNEL_VERSION}.img"
23
24 cd /run/initramfs
25
26 [ -f .need_shutdown -a -f "$IMG" ] || exit 1
27
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 elif $SKIP "$IMG" | zstd -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
35 rm -f -- .need_shutdown
36 else
37 # something failed, so we clean up
38 echo "Unpacking of $IMG to /run/initramfs failed" >&2
39 rm -f -- /run/initramfs/shutdown
40 exit 1
41 fi
42
43 if [[ -d squash ]]; then
44 unsquashfs -no-xattrs -f -d . squash/root.img >/dev/null
45 if [ $? -ne 0 ]; then
46 echo "Squash module is enabled for this initramfs but failed to unpack squash/root.img" >&2
47 rm -f -- /run/initramfs/shutdown
48 exit 1
49 fi
50 fi
51
52 if [ -e /etc/selinux/config -a -x /usr/sbin/setfiles ] ; then
53 . /etc/selinux/config
54 /usr/sbin/setfiles -v -r /run/initramfs /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts /run/initramfs > /dev/null
55 fi
56
57 exit 0