As I understand this is because they don't have write access which is what I want to change.
No, this error message does not mean that they don't have write access. If they didn't have write access, you would not be able to right click and "Move to Trash" or "Delete" a file, or use the Del keyboard button. But since you're getting this error, it means that the users do have access.
After two hours of search, and reproducing this error on my computer, here's what I found out.
Explanation
Permissions (owner, group owner, file and directory permissions) are set at the time of mounting. Only the owner can move files to trash. Why? Because when you move files to trash in an NTFS partition, a folder called .Trash-<uid>
is created in the root directory of the partition, where <uid>
is the uid
of the user, and the folder's owner will be the user that's trying to delete. For example, if the username is daniels
and the uid
is 1000, a folder called .Trash-1000
is created, and daniels
would be the owner.
So, if daniels
is the owner of the partition, he'll be able to do this normally. However, if another user (let's say called alaa
, and uid=1001
) tries to delete something, the system tries to create a .Trash-1001
folder, with the owner alaa
. But, on NTFS, the permissions are set at the time of mounting (example: it was set to daniels
), and the "owner" of any file cannot be changed, and so the system fails to create the .Trash-1001
folder, giving you the prompt Cannot move file to trash, do you want to delete immediately?
.
To test this, try manually creating a folder in the root directory of the partition named .Trash-1001
(the owner will be set to the owner of the partition). You'll find that hitting Del on the keyboard on any file/folder will not do anything, and the option when you right click an item will change from Move to Trash
to Delete
. I can't explain why it changes to Delete
, but this is just to identify that the problem is indeed in the .Trash-1001
folder.
In my opinion, I classify this as a bug.
Solution (soft of...)
Remove all of your uid=
, gid=
, dmask=
, fmask=
, and umask=
options from your mount command, and add permissions
, so I guess your line should be like this:
nosuid,nodev,nofail,x-gvfs-show,nobootwait,permissions
I've tried this on my computer, and it works; both users can move to trash when using the NTFS hard disk.
Here's a demonstration:
alaa@aa-lu:~$ sudo mount -o rw,permissions /dev/sdc2 /media/he
Using default user mapping
alaa@aa-lu:~$ ls /media/he -la
total 104
drwxrwxrwx 1 root root 8192 Sep 24 21:20 .
drwxr-xr-x 6 root root 4096 Sep 24 21:18 ..
drwxrwxrwx 1 root root 4096 Dec 15 2012 Files on my hard disk
drwxrwxrwx 1 root root 4096 Jul 9 12:18 $RECYCLE.BIN
drwx------ 1 root root 0 Jan 22 2012 System Volume Information
Then I went and deleted something using my username alaa
, then logged in as another user aaa
and deleted something too. Both of them could delete, and this is how the NTFS partition looks like:
alaa@aa-lu:~$ ls /media/he -la
total 104
drwxrwxrwx 1 root root 8192 Sep 24 21:20 .
drwxr-xr-x 6 root root 4096 Sep 24 21:18 ..
drwxrwxrwx 1 root root 4096 Dec 15 2012 Files on my hard disk
drwxrwxrwx 1 root root 4096 Jul 9 12:18 $RECYCLE.BIN
drwx------ 1 root root 0 Jan 22 2012 System Volume Information
drwx------ 1 alaa alaa 0 Sep 24 21:20 .Trash-1000
drwx------ 1 aaa aaa 0 Sep 24 21:19 .Trash-1002
I don't know how it manages to do that, but it just does.
I found this page: Ownership and Permissions | Tuxera that explains this, as well as a forum post (http://www.tuxera.com/forum/viewtopic.php?f=2&t=27540) that has some useful information. However, unfortunately I haven't read them yet, so I can't explain exactly what this permissions
option does.
I said "Solution (sort of...)" in the title of this section because now you're not controlling who is the owner of the partition, not group owner, nor the read-write permissions. But, when mounting with the permissions
option, you can see a "Using default user mapping", so as far as I understood, there's a "user mapping" thing that can be created to be used with permissions
, and that mapping will have the owner/permissions that we want to set. I also have not tried mounting using permissions
along with uid=
and all those other options (the Tuxera link I posted should explain that though), but that might also work, by controlling owner/permissions and at the same time give access to Trash.
When I read those links, I'll update my answer.
Best Answer
Since I know you're new to Ubuntu, here's a few general comments.
1. Put that partition in your
/etc/fstab
First off, in your script you use the line
sudo mount -U 80EA3F58EA3F49A4 /media/ubuntu/LENOVO
to mount your NTFS partition. I would suggest to add that partition to your/etc/fstab
and map it to the UID of your partition there. Since you're on a single-user system, you may want to have an entry similar to this in your/etc/fstab
:Most importantly, this tells the system to bind the mount point
/media/ubuntu/LENOVO
to the UID80EA3F58EA3F49A4
. That way, in the future (and thus in your script) you can simply usesudo mount /media/ubuntu/LENOVO
instead ofsudo mount -U 80EA3F58EA3F49A4 /media/ubuntu/LENOVO
. If the UID changes in the future (because you reformat the partition), it's better to have only one central place,/etc/fstab
, to edit rather than 20 scripts you may have lying around.This also mounts the filesystem with various common options for NTFS partitions: read-write mode (
rw
), permit the execution of binaries (exec
), make all files and directories on the file system belong to the user 1000 and group 1000 (uid=1000,gid=1000
) (that's your normal user), set the permissions bits for all files and directories to 775 (umask=0002
), set the character set for filenames to UTF-8 (nls=utf8
), and do not mount the partition automatically (noauto
). Refer to fstab(5) and mount(8) for more information. I personally find it convenient on my single-user system to be able to access all files on my NTFS partitions without having to usesudo
, but of course your mileage may vary.You may also want to drop the
noauto
option. Then, the partition will be mounted whenever the commandmount -a
is run, and in particular, at boot time (and thus, it would typically be mounted the whole time). Then you wouldn't even have to use themount
andumount
commands in your script at all, but I don't know if you want that.2. Don't use
umount
with-l
From umount(8):
So this option is at least rather unusual to use in your case.
Whether you run
umount
with or without-l
, a partition will not be force-unmounted (there's the-f
option for that). Rather, when you don't use-l
and the partition is still busy, the unmount will simply fail and return an error message; when using-l
and the partition is still busy, it will be detached from the filesystem hiearchy now (meaning you cannot access it anymore), but pending I/O operations will be silently completed in the background.Since there shouldn't be any pending I/O operations after you've run
swapoff
, by not using-l
you would at least notice if something is odd, because if the partition is unexpectedly still busy then the unmount command would output an error message.3. Add error handling
You execute all commands in sequence, but don't check whether the previous command worked. So, e.g., if the mounting fails, then the
swapon
command will be nevertheless attempted but fail, and then your game will start even though the swap was not activated.Try this: