initramfs-pre-shutdown-hook 1.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/sh

# This script is installed by /usr/share/initramfs-tools/hooks/shutdown
# into the initramfs, as /lib/systemd/system-shutdown/tails. It's run by the
# copy of systemd-shutdown that runs (as /shutdown) from inside
# the unpacked initramfs, immediately before executing the requested action
# (halt/poweroff/reboot).

set -x

### Unmount relevant filesystems

13 14 15
# Wait for lazy unmounts to finish
sync

16
# Debugging
17
/bin/mount
18

19
# Otherwise we can't drop caches.
20
# This may also help for tracking remaining mounts.
21
/bin/mount -o remount,rw /proc
22 23

# Otherwise we can't create new mountpoints in /mnt
24
/bin/mount -o remount,rw /
25 26 27

# Move /oldroot/* mountpoints out of the way
mkdir -p /mnt/live/squashfs
28
/bin/mount --move \
29 30 31
      /oldroot/lib/live/mount/rootfs/filesystem.squashfs \
      /mnt/live/squashfs
mkdir -p /mnt/live/medium
32
/bin/mount --move \
33 34
      /oldroot/lib/live/mount/medium \
      /mnt/live/medium
35
mkdir -p /mnt/live/dev
36
/bin/mount --move \
37 38 39
      /oldroot/dev \
      /mnt/live/dev
mkdir -p /mnt/live/run
40
/bin/mount --move \
41 42
      /oldroot/run \
      /mnt/live/run
43 44

# Finally, really unmount relevant filesystems
45
/bin/umount /oldroot
46 47

# Debugging
48
/bin/mount
49 50 51 52 53 54 55 56 57

### Ensure any remaining disk cache is erased by Linux' memory poisoning
echo 3 > /proc/sys/vm/drop_caches

### Pause if the test suite wants us to
if [ -e /tails_shutdown_debugging ] ; then
    echo "Going to sleep 2 minutes. Happy dumping!"
    sleep 120
fi