19

Apparently the answer is here: https://superuser.com/questions/251537/mount-specific-ntfs-directory-on-linux however it is not working as expected.

I have a dual boot system with Windows 7 and Ubuntu 13.04 (upgraded from 12.10), and I want to access my Windows 7 personal folders for both reading and writing. I followed instructions according to the given link and my /etc/fstab file looks like this:

/dev/sda1 /media/windows ntfs ro,umask=0222,defaults 0 0
/media/windows/Users/MyUser/    /home/myuser/Windows    ntfs-3g rbind,user,umask=0222,defaults 0 0
/media/windows/Users/OtherUser/ /home/otheruser/Windows ntfs-3g rbind,user,umask=0222,defaults 0 0

It almost works as expected. My Windows partition is on /media/windows/ with read-only permissions and my Windows personal folder is in ~/Windows. However this personal folder is also read-only.

Note I'm configuring this in a multisession environment, so I need this to work for my session and for other user's sessions. I need that each user can access and be able to write and read their Windows folders from Linux.

2
  • Is there any way I can change and test configurations without having to restart the whole system. So far I have tried changing umask (to 0002), adding uid and gid parameters, etc. with no positive results, but each change requires a system shutdown. Sep 4, 2013 at 16:03
  • I had awarded the 100 bounty to totti for the idea or mounting the partition under /root/ (which is working). My current solution uses the hints provided by falconer, ajThapa, totti and yilmi, none of them is working as expected in the original question (protections are not enough), but it is working (users have rw access to their data). All these mentioned answers were upvoted. Dec 23, 2013 at 16:29

8 Answers 8

10
+100

The above linked super user question is for mounting partition and sub directory in read only mode. You need only the sub-directory (personal folder) to be read-write.

First check your system can mount ntfs partition in read-write mode

mount -t ntfs-3g  -o rw /dev/sda1 /media/windows

Now test if the mounted fs is writable. If not stop here and ask another question in this site.

The problem is an RO mounted partition's sub-directory can't be in RW. So the solution is mount the windows partition in RW in a hidden and inaccessible place. So let's mount it on /root/win which is inaccessible by non-root users (without sudo)

As a root user do following
Steps
1. Mount windows partition in RW

mount -t ntfs-3g -o rw /dev/sda1 /root/win  

2. Bind it

mount --bind /root/win/Users/MyUser/  /home/myuser/Windows  

3. Bind a read only instance of windows partition

mount --bind /root/win /media/windows  
mount -o remount,ro /media/windows

Now everything should be OK. Additionally you can unmount the windows partition but I warn you in some system it will make make the binded one (@home) inaccessible. The code is umount /root/win

Alternatively you can mount the windows partition in RW at /media/windows ( instead of /root/win) and immediately bind mount it at the same mount point (/media/windows) so that no one (even root) can write on the partition (but on the user folder).

5
  • Does it work ? What the problem?
    – totti
    Dec 22, 2013 at 9:53
  • The first part, mounting rw in /media/windows seems to work although it does not report w permissions I can actually touch and edit files. Dec 22, 2013 at 16:05
  • When remounting I get the following error: Remounting is not supported at present. You have to umount volume and then mount it once again. Dec 22, 2013 at 16:56
  • I think its your system's problem. I have this tested successfully in ubuntu 12.10. I never see such error even in ubuntu 10.04. You may try it in a live system(as you seemed to be updated the OS).
    – totti
    Dec 23, 2013 at 9:56
  • Thanks +1 from me, too, for an elegant solution and a very clear explanation. I especially like the trick for mounting the user folder so that one one (even root) can write on other than the user folder. That is indeed the best solution as no OS instance other than the Windows 8.1 instance to which system files belong has any business accessing those system files. Shared data, however, is a different story. Dec 31, 2014 at 1:04
5

I doubt that the linked superuser answer is a working one. (Though I can't try it.) From man mount:

Note that the filesystem mount options will remain the same as those on the original mount point, and cannot be changed by passing the -o option along with --bind/--rbind. The mount options can be changed by a separate remount command, for example:

mount --bind olddir newdir
mount -o remount,ro newdir

I also doubt that it is possible to --rbind a part of a file system with a different file system driver (ntfs vs ntfs-3g).

When you rbind the mount command ignores every option, so nothing will become read-write. And because the kernel ntfs driver does not support writes, obviously the rw option won't help with that one either. Use the ntfs-3g driver.

Basically what you should do is this (in a terminal):

mount -t ntfs-3g -o ro /dev/sda1 /media/windows
mount --bind /media/windows/Users/MyUser/    /home/myuser/Windows
mount -o remount,rw /home/myuser/Windows

(I think that --rbind is also unnecessary, --bind should be enough.)

And regarding the comment under the question: Of course you don't have to restart the system for testing, just use the mount command as I did above. (And unmount with the umount command.)

After you confirmed that this works as intended, you just modify the mount and add the options you want: uid, gid,umask, etc.

3
  • Well, I can test using mount, however when I find the working configuration, I will want to do it automatically, either by /etc/fstab or by any other means. (With the Ob Question: how do I translate mount commands into fstab parameters?) Dec 22, 2013 at 16:25
  • @CarlosEugenioThompsonPinzón The fstab is just a file which is parsed sequentially by the mount command on startup. But I think Ubuntu doesn't use mount but mountall at startup, which may not run the commands in fstab sequentially. So yes, putting these command parameters simply to fstab might not work. But you can always put simply the working mount commands into a startup script (e.g /etc/rc.local) or make an upstart job from those. The more important thing in your case is to find out a working mount scheme, making it automount on startup is an easy job.
    – falconer
    Dec 22, 2013 at 16:37
  • @CarlosEugenioThompsonPinzón Oops I missed the last question from you comment. So how the mount commands translate to fstab? You can look it up in man mount or here. Short story: first field: device to mount, second field: mount point, third field: fs-type (more precisely fs driver), fourth field: mount options, the other field are less importat now. So form the mount command the string we wrote behind -t goes in the third field, the string we wrote behind -o goes into the fourth field.
    – falconer
    Dec 22, 2013 at 17:25
3

See if this helps...

If sda1 is already mounted to /media/windows, you could unmount it with:

sudo umount /media/windows

Next create the directory windows in /media/:

sudo mkdir /media/windows

Edit the /etc/fstab as below:

/dev/sda1  /media/windows ntfs-3g  rw,nodev,noexec,auto,nouser,async,locale=en_US.utf8,uid=1000,gid=1000,umask=0002 0 0

/media/windows/Users/MyUser/  /home/myuser/Windows  ntfs-3g rbind,user,rw,nodev,noexec,auto,async,uid=1000,gid=1000,umask=0002 0 0

/media/windows/Users/OtherUser/  /home/otheruser/Windows  rbind,user,rw,nodev,noexec,auto,async,uid=1001,gid=1001,umask=0002 0 0

(Note: change uid and gid values as for the user. To get the uid and gid of a user you can use the command id -u username and id -g username resp.)

Now you can mount these with the command:

sudo mount -a

Now go to the rebinded directories and see if you can edit the file. And you should be done.

4
  • Okay, I have rw permissions on /media/windows (not reported in ls, but I can edit files) as root, however in the local directories I need to sudo in order to modify the files. Dec 22, 2013 at 16:16
  • ... and now all mounted directories are belonging to me (user 1000), from /media/windows to /home/someotheruser/Windows. Dec 22, 2013 at 16:41
  • I guess now you and other users can make and save works in the resp. mount-points in the users' $HOME... if the rest of users still aren't able to have RW access, add them to your group (probably with the gid 1000)
    – rusty
    Dec 22, 2013 at 17:16
  • Currently I have a group to which all local users are attached, and I'm granting write permissions to that group. This solves the “each user has rw access to their own data” but the whole partition and other user's data is not protected. Dec 23, 2013 at 16:20
3

Do all your testing before editing your fstab configuration file.

Well, you probably know that ntfs filesystem is automatically mounted in read-only if filessystem is flagged as dirty. What you have to do first before trying any of the answers is to mount disk in windows and run chkdsk before trying to mount it again.

Also, if mounting in rw still failing, you should try mounting with different mount type options such as sudo mount -t ntfs or sudo mount -t ntfs-3g

Once fs is mounted in rw you can do the following :

mount --bind /media/MOUNTPOINT/TARGETFOLDER /home/SHAREDDIRECTORY/ mount -o remount,ro /home/SHAREDDIRECTORY/

or

sudo gksu nautilus or sudo gksu dolphin to open an explorer with su rights

1
  • Thank you for the chkdsk. There was indeed some corruptions in the NTFS partition, and now I can write to the mounted drive with sudo. Dec 22, 2013 at 16:19
2

Why not trying to mount it with read and write attribute : rw ?

/dev/sda1 /media/windows ntfs rw,umask=0222,defaults 0 0

2
  • I will check, however I would rather have the whole partition read-only and only some specific folders as read-write. Sep 2, 2013 at 20:46
  • Didn't work. Both the partition and the folders are still read-only. The only difference is that chmod and chown do not fail reporting a read-only error: they just don't operate. Sep 2, 2013 at 20:55
2

I am not quite sure however, can you try this please. After the drive is mounted, give the following command on the terminal

sudo gksu nautilus

enter your administrative password and in the graphical window that open, you should be able to click the drive and change read/write permissions.

Let me know if this works. There is help available for use of nautilus with graphical interface with root privileges.

1
  • This would allow access to the files and they could be copied off as well, but the read-only permissions might not be changed, as non-unix filesystems are mounted as read only...
    – Wilf
    Dec 17, 2013 at 13:12
1

I would recommend using sudo chmod.666 ~/Windows

https://help.ubuntu.com/community/FilePermissions

2
  • 1
    I can neither change permission or owner (even with sudo). It rejects the command saying that the system is read-only. Not even in /media/windows/ which is the whole partition (and which would not be the expected behavior) Sep 2, 2013 at 18:50
  • I'm probably wrong, but sometimes sudo doesn't have permissions that root would have. Try running sudo su then chmod
    – virtualxtc
    Dec 16, 2013 at 23:52
1

The easiest way to mount Windows as read-write is to simply reboot it or do a full shut down. The NTFS partition hibernates when "fast shut down" is used. This principle is covered in greater detail at this link.

You must log in to answer this question.

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