Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

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 ountput is not catched. (maybe it also hat so retrun 0)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.