6

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.

Piotr
  • 63

3 Answers3

4

First of all, you'll need to find the device id using:

sudo fdisk -l

Look for the one that's formatted as NTFS under System, and remember the device id (Should look something like /dev/sda2). Then create the mount directory and mount it.

mkdir Windows
sudo mount -o ro /dev/sdaX Windows

(Replace X with your device id)

1lann
  • 159
  • It isn;t what I meant. I wanted the ubuntu to do all work when it starts. For example using fstab. My bad, I haven't said it precociously – Piotr Nov 02 '13 at 14:29
1

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..

Saurav Kumar
  • 14,916
  • I tried it before but it didn't help. I now have tried it once again and nothing changed. – Piotr Nov 02 '13 at 15:42
  • Yes, you are right, I've also tried it in my brother's laptop. It doesn't work. Let me find some other way. I'll return with my answer. – Saurav Kumar Nov 02 '13 at 15:52
  • @Piotr: Sorry for late reply, I was little occupied. I have edited my answer hope it will work now. – Saurav Kumar Nov 04 '13 at 16:20
  • It doesn't work, but when I create script and run it from script then it works fine. But in rc.local it doesn't mount filesystem in ro mode. It only try to mount filesystem in rw mode. – Piotr Nov 04 '13 at 20:20
  • 1
    rc.local doesn't tolerate errors.

    rc.local doesn't provide a way to intelligently recover from errors. If any command fails, it stops running. The first line, #!/bin/sh -e, causes it to be executed in a shell invoked with the -e flag. The -e flag is what makes a script (in this case, rc.local) stop running the first time a command fails within it.

    – Piotr Nov 04 '13 at 20:33
  • 1
    is it a good idea to change #!/bin/sh -e ti #!/bin/sh ? – Piotr Nov 04 '13 at 20:35
  • I just created a new script, and just add one line to the rc.local file to run that script. And it works! Tell me if that isn't the best practice and I should have not done that. Thank you. – Piotr Nov 04 '13 at 20:53
  • @Piotr: No there is nothing wrong.. But it would be good if you just edit my answer and mention the changes you done. It would help others also to get the answer. :) – Saurav Kumar Nov 05 '13 at 06:41
0

This is my solution, it isn't the best one.

I just add the second entry to the fstab with nobootwait option. If first entry doesn't work then second entry works and no message is reported by system. If first entry works then second entry doesn't work because of first entry. We'll see if it will work properly :D

#/dev/sda7
UUID=D0B43178B43161E0 /media/Dane           ntfs    defaults,nobootwait,errors=remount-ro 0        1
UUID=D0B43178B43161E0 /media/Dane           ntfs   suid,dev,exec,auto,nouser,async,nobootwait,ro    0       2
Piotr
  • 63