]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut-initramfs-restore.sh
Fix a missing space in example configs
[thirdparty/dracut.git] / dracut-initramfs-restore.sh
CommitLineData
449b0e07 1#!/bin/bash
fb67e4aa
HH
2
3set -e
449b0e07 4
25b987fe
HH
5# do some sanity checks first
6[ -e /run/initramfs/bin/sh ] && exit 0
7[ -e /run/initramfs/.need_shutdown ] || exit 0
8
449b0e07
HH
9KERNEL_VERSION="$(uname -r)"
10
0626cbe9
HH
11[[ $dracutbasedir ]] || dracutbasedir=/usr/lib/dracut
12SKIP="$dracutbasedir/skipcpio"
13[[ -x $SKIP ]] || SKIP=cat
14
449b0e07
HH
15[[ -f /etc/machine-id ]] && read MACHINE_ID < /etc/machine-id
16
da5304aa 17mount -o ro /boot &>/dev/null || true
4f0c7fc9 18
449b0e07
HH
19if [[ $MACHINE_ID ]] && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
20 IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
21fi
22[[ -f $IMG ]] || IMG="/boot/initramfs-${KERNEL_VERSION}.img"
23
fb67e4aa 24cd /run/initramfs
449b0e07 25
fb67e4aa 26[ -f .need_shutdown -a -f "$IMG" ] || exit 1
4f0c7fc9 27
0626cbe9 28if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
32bd2fbb 29 rm -f -- .need_shutdown
0626cbe9 30elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
32bd2fbb 31 rm -f -- .need_shutdown
0626cbe9 32elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
149965bd 33 rm -f -- .need_shutdown
7dbadcc7
TPG
34elif $SKIP "$IMG" | zstd -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
35 rm -f -- .need_shutdown
50bc2253
HH
36else
37 # something failed, so we clean up
449b0e07 38 echo "Unpacking of $IMG to /run/initramfs failed" >&2
32bd2fbb 39 rm -f -- /run/initramfs/shutdown
50bc2253
HH
40 exit 1
41fi
42
a60af534
KS
43if [[ -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
50fi
51
76522d58
LN
52if [ -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
55fi
56
50bc2253 57exit 0