net-lib.sh:parse_iscsi_root() fix target parsing
[dracut.git] / dracut-initramfs-restore.sh
blob8b9b80f9cf2c2cbee259072c89a4b6084b691e73
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 if [[ $MACHINE_ID ]] && [[ -d /boot/${MACHINE_ID} || -L /boot/${MACHINE_ID} ]] ; then
18 IMG="/boot/${MACHINE_ID}/${KERNEL_VERSION}/initrd"
20 [[ -f $IMG ]] || IMG="/boot/initramfs-${KERNEL_VERSION}.img"
22 cd /run/initramfs
24 [ -f .need_shutdown -a -f "$IMG" ] || exit 1
25 if $SKIP "$IMG" | zcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
26 rm -f -- .need_shutdown
27 elif $SKIP "$IMG" | xzcat | cpio -id --no-absolute-filenames --quiet >/dev/null; then
28 rm -f -- .need_shutdown
29 elif $SKIP "$IMG" | lz4 -d -c | cpio -id --no-absolute-filenames --quiet >/dev/null; then
30 rm -f -- .need_shutdown
31 else
32 # something failed, so we clean up
33 echo "Unpacking of $IMG to /run/initramfs failed" >&2
34 rm -f -- /run/initramfs/shutdown
35 exit 1
38 exit 0