1

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.

1 Answer 1

1

It could be that the mount was carried out in a volatile manner, i.e. it received a termination signal as the script process got terminated and was automatically "re-unmounted". Not sure about that since you state that mount doesn't output anything to the log. Either way, a more robust way to go would be using a Systemd Service. Perhaps a bit (too?) late but try this:

  1. Create a bash script somewhere in your home directory and name it "remount.sh" (e.g. ~/bin/remount.sh). Add to it the following commands:
#!/bin/bash

shared=ABCDE12345 # ***YOUR*** filesystem UUID
device=$(blkid -U "$shared")

# mount the shared partition unless already mounted
if ! df | grep -q $device ; then
    if mount UUID=$shared ; then
        exit 0
    fi
    exit 1
fi
exit 0
  1. Make the above script executable: chmod u+x ~/bin/remount.sh

  2. Create a plain text file somewhere in your home directory and name it "remount.service" (e.g. ~/bin/remount.service). Add to it the following directives:

[Unit]
Description=Remount partition on resume from hibernate or hybrid-sleep
After=hybrid-sleep.target
After=hibernate.target
#After=suspend.target

[Service]
KillMode=process
ExecStart=~/bin/remount.sh

[Install]
WantedBy=hybrid-sleep.target
WantedBy=hibernate.target
#WantedBy=suspend.target
  1. Run the following commands from a terminal:
sudo mv ~/bin/remount.service /etc/systemd/system/
systemctl enable remount.service

This is it. Now, your partition should be remounted every time you resume from hibernate or hybrid-sleep.

1
  • Sorry to unselect: this actually didn't end up working. The partition seems to quietly unmount after being mounted by the service file. After doing some more digging this may be a bigger systemd issue. It also seems to only affect this partition specifically and may have something to do with it being an NTFS file system.
    – dawaltco
    Commented Jan 31 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .