]> git.ipfire.org Git - thirdparty/dracut.git/blame - dracut-initramfs-restore.sh
refactor(squash): don't record mount points in text file
[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
ba2e760b
JG
19if [[ -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"
23elif [[ -d /boot/loader/entries || -L /boot/loader/entries ]] \
24 && [[ $MACHINE_ID ]] \
25 && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
449b0e07 26 IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
ba2e760b
JG
27else
28 IMG="/boot/initramfs-${KERNEL_VERSION}.img"
449b0e07 29fi
449b0e07 30
fb67e4aa 31cd /run/initramfs
449b0e07 32
fb67e4aa 33[ -f .need_shutdown -a -f "$IMG" ] || exit 1
4f0c7fc9 34
0626cbe9 35if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
32bd2fbb 36 rm -f -- .need_shutdown
0626cbe9 37elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
32bd2fbb 38 rm -f -- .need_shutdown
0626cbe9 39elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
149965bd 40 rm -f -- .need_shutdown
7dbadcc7
TPG
41elif $SKIP "$IMG" | zstd -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
42 rm -f -- .need_shutdown
50bc2253
HH
43else
44 # something failed, so we clean up
449b0e07 45 echo "Unpacking of $IMG to /run/initramfs failed" >&2
32bd2fbb 46 rm -f -- /run/initramfs/shutdown
50bc2253
HH
47 exit 1
48fi
49
a60af534
KS
50if [[ -d squash ]]; then
51 unsquashfs -no-xattrs -f -d . squash/root.img >/dev/null
52 if [ $? -ne 0 ]; then
53 echo "Squash module is enabled for this initramfs but failed to unpack squash/root.img" >&2
54 rm -f -- /run/initramfs/shutdown
55 exit 1
56 fi
57fi
58
76522d58
LN
59if [ -e /etc/selinux/config -a -x /usr/sbin/setfiles ] ; then
60 . /etc/selinux/config
61 /usr/sbin/setfiles -v -r /run/initramfs /etc/selinux/${SELINUXTYPE}/contexts/files/file_contexts /run/initramfs > /dev/null
62fi
63
50bc2253 64exit 0