Ubuntu – How to automatically mount hibernated NTFS to read-only

filesystemfstabntfs

Is there any way to set up Ubuntu this way:

If I can't mount the filesystem in rw mode, then mount it in ro mode in the same directory.

In result I should not come across the notification that the system can't mount the filesystem (Skip or manual fix notification). SO when I start the system I should have my ntfs partitions mounted either in rw or ro mode depends if the windows is hibernated.

fstab entry:

#/dev/sda7
UUID=D0B43178B43161E0 /media/Dane           ntfs    defaults,errors=remount-ro 0        1

"mount -a" result:

The disk contains an unclean file system (0, 0).
Metadata kept in Windows cache, refused to mount.
Failed to mount '/dev/sda7': Operation not permitted
The NTFS partition is in an unsafe state. Please resume and shutdown
Windows fully (no hibernation or fast restarting), or mount the volume
read-only with the 'ro' mount option.

I have ubuntu 13.10 and win8. I use uefi secure boot.

Best Answer

I've found a way to mount a hibernated windows partition in read-only mode when any error occurs

I hope it would work for you too. I'm describing below how to do it.

  • Open /etc/rc.local file with root privileges in any editor.

    sudo gedit /etc/rc.local
    
  • Now add following lines at last:

    sudo mount /dev/sda7 /media/Dane
    if [ $? -eq 14 ]
    then
      sudo mount -o ro /dev/sda7 /media/Dane
    fi
    exit 0
    

    If exit 0 is already written then delete the duplicate. Be sure that /etc/sda7 is your windows partition that you're going to mount when error occurs and also there is already a directory, named Dane created in /media. If not then change /dev/sdaX accordingly and crate the directory.

  • Now update using following command:

    sudo update-rc.d -f /etc/rc.local
    

    I'm not sure whether this command is needed or not, but just execute it what every message it gives.

  • Now finally restart your system when Windows is hibernated.

A little description:

The command written in file /etc/rc.local actually executes before and after system boots, thus acts as a startup. The first command in script will try to mount the partition and get the error code it returns. so $? is 14 when any error occurs. $? is 16 when partition is already mounted and trying to mount it again...

Reply if something goes wrong. I'll be waiting for your reply..

Related Question