2

I have configured to automount my ntfs data partition on boot:

# /media/Win8 was on /dev/sda5 during installation
UUID=A47A42FF7A42CDAC /media/Win8     ntfs    defaults,umask=007,gid=46 0       0

this works fine, as long as the partition is cleanly unmounted and windows didn't go to suspend with it (which could be avoided if you wish).

If it is in suspend state it is still safe to mount it readonly with

sudo mount -o ro /media/Win8

How can I tell ubuntu to do this automatically if it cannot mount it rw?

rubo77
  • 32,486

1 Answers1

0

You can run this script that will try to remount it read-only if a mount like ordered in /etc/fstab fails:

nano /usr/local/bin/mount-c-ro

and enter

#!/bin/bash
# mount this device
DEVICE=/dev/sda5
# any folder that exists on that device 
CHECK=/media/Win8/Windows/

echo try to mount $DEVICE...
sudo mount $DEVICE

if [ -d $CHECK ]; then 
    echo $DEVICE is mounted by /etc/fstab
    echo occurrences in fstab:
    sudo grep $DEVICE /etc/fstab
else
    echo mounting $DEVICE read-only...
    sudo mount -o ro $DEVICE
    echo done
fi
echo mount status is:
mount |grep $DEVICE

then give it execute right:

chmod +x /usr/local/bin/mount-c-ro

Maybe you can run this automatically at the end of your boot process, but I don't know how and it probably will be a problem that its output is not catched. (maybe it also hat so return 0)

rubo77
  • 32,486