Ubuntu: Mounting a Windows folder with writing permissions in Ubuntu



Question:

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.


Solution:1

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


Solution:2

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.


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


Solution:4

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


Solution:5

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

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


Solution:6

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.


Solution:7

I would recommend using sudo chmod.666 ~/Windows

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


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »