]>
git.ipfire.org Git - thirdparty/dracut.git/blob - dracut-initramfs-restore.sh
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 -r MACHINE_ID
< /etc
/machine-id
17 mount
-o ro
/boot
&> /dev
/null || true
19 if [[ -d /efi
/loader
/entries ||
-L /efi
/loader
/entries
]] \
20 && [[ $MACHINE_ID ]] \
21 && [[ -d /efi
/${MACHINE_ID} ||
-L /efi
/${MACHINE_ID} ]]; then
22 IMG
="/efi/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
23 elif [[ -d /boot
/loader
/entries ||
-L /boot
/loader
/entries
]] \
24 && [[ $MACHINE_ID ]] \
25 && [[ -d /boot
/${MACHINE_ID} ||
-L /boot
/${MACHINE_ID} ]]; then
26 IMG
="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
28 IMG
="/boot/initramfs-${KERNEL_VERSION}.img"
33 [ -f .need_shutdown
-a -f "$IMG" ] ||
exit 1
35 if $SKIP "$IMG" | zcat |
cpio -id --no-absolute-filenames --quiet > /dev
/null
; then
36 rm -f -- .need_shutdown
37 elif $SKIP "$IMG" | xzcat |
cpio -id --no-absolute-filenames --quiet > /dev
/null
; then
38 rm -f -- .need_shutdown
39 elif $SKIP "$IMG" | lz4
-d -c |
cpio -id --no-absolute-filenames --quiet > /dev
/null
; then
40 rm -f -- .need_shutdown
41 elif $SKIP "$IMG" | zstd
-d -c |
cpio -id --no-absolute-filenames --quiet > /dev
/null
; then
42 rm -f -- .need_shutdown
44 # something failed, so we clean up
45 echo "Unpacking of $IMG to /run/initramfs failed" >&2
46 rm -f -- /run
/initramfs
/shutdown
50 if [[ -d squash
]]; then
51 if ! unsquashfs
-no-xattrs -f -d . squash-root.img
> /dev
/null
; then
52 echo "Squash module is enabled for this initramfs but failed to unpack squash-root.img" >&2
53 rm -f -- /run
/initramfs
/shutdown
58 if [ -e /etc
/selinux
/config
-a -x /usr
/sbin
/setfiles
]; then
60 /usr
/sbin
/setfiles
-v -r /run
/initramfs
/etc
/selinux
/"${SELINUXTYPE}"/contexts
/files
/file_contexts
/run
/initramfs
> /dev
/null