I am hibernating from Linux (Pop_OS) in a dualboot setup, and I have one partition shared between the two systems. I hibernate using a script that ensures the shared partition is unmounted first:
#!/bin/bash
# ~/bin/hibernate
shared=ABCDE12345 # partition UUID
device=$(blkid -U "$shared")
if ! df | grep -q $device || sudo umount UUID=$shared ; then
# unmount the shared partition unless already unmounted
sudo systemctl hibernate
exit 0
fi
exit 1
I then have the following in /usr/lib/systemd/system-sleep
, which runs when resuming from hibernation.
#!/bin/bash
# /usr/lib/systemd/system-sleep/hibernate
shared=ABCDE12345
device=$(blkid -U "$shared")
logfile=/var/log/hibernate.log
if [ $2 == "hibernate" ] ; then
if [ $1 == "post" ] ; then
if ! df | grep -q $device ; then
echo "shared drive not mounted..." >> $logfile
cat /proc/partitions &>> $logfile
# tried adding a sleep delay after mount failed without
sleep 5
echo "mounting..." >> $logfile
/usr/bin/mount UUID=$shared &>> $logfile
fi
fi
fi
I can confirm (via the log file) that everything in /usr/lib/systemd/system-sleep/hibernate
runs when resuming from hibernation. cat /proc/partitions
even lists the shared partition. However, the partition is still unmounted after resuming, and the mount
command outputs nothing to the log file. I have also tried running mount
using the device path, and running mount --all
with no success. After resuming, I can manually remount the shared partition using mount
or a GUI with no problem.
Why isn't this working? Is there anything else I can try to automatically remount this partition after hibernation?
Update
The issue seems related to this drive being formatted as an NTFS file system. I have created a test exFAT partition that mounts reliably using the above method. I also found the following in the system log when resuming from hibernation:
ntfs-3g[822185]: Version 2021.8.22 integrated FUSE 28
ntfs-3g[822185]: Mounted /dev/nvme0n1p4 (Read-Write, label "Shared", NTFS 3.1)
ntfs-3g[822185]: Cmdline options: rw,nosuid,nodev,nofail
ntfs-3g[822185]: Mount options: nosuid,nodev,nofail,allow_other,nonempty,relatime,rw,fsname=/dev/nvme0n1p4,blkdev,blksize=4096
ntfs-3g[822185]: Ownership and permissions disabled, configuration type 7
ntfs-3g[822185]: Unmounting /dev/nvme0n1p4 (Shared)
The partition seems to quietly unmount for unclear reasons after being mounted on startup. This could be related to this systemd issue, which has been patched in a version that has not made it to Pop_OS yet. It could also be an issue with ntfs-3g but I haven't found anything useful there yet.