Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The problem of using a filesystem like ext4 on a USB stick or memory card is that when it's mounted into another system the disk's UID/GID might not be present.

Can this be fixed with a mount option?

share|improve this question
    
Similar question: askubuntu.com/questions/12009/… –  jofel May 10 '12 at 10:39

1 Answer 1

up vote 11 down vote accepted

I assume you're hoping to find an equivalent of the uid=N and gid=N options supported by some of the other filesystems Linux's mount command knows about. Sorry, but no, ext4 doesn't have that option.

These other filesystems have such an option in order to give permissions to files for a filesystem that may not have useful POSIX permissions. You're looking to take permissions away — or at least, reassign them — which is a bad idea from a security standpoint, which is doubtless why these options don't exist.

When you use a filesystem like ext4 on removable media, you're saying that you care about things like POSIX permissions. That means you have to take the same sort of steps to synchronize user and group IDs as you would for, say, NFS.

If you don't actually care about permissions, there is probably a more appropriate filesystem for your situation.

I tried UDF as a candidate for such a filesystem after the commentary below, but alas, it won't work:

  • If you create a UDF filesystem on one Linux box, add files to it, change their permissions, and mount them on another Linux box, it will obey the permissions it finds there, even if you give uid=N,gid=N. You have to sync UIDs and GIDs here, as with NFS.

  • Mac OS X behaves as hoped: it believes it owns everything on a UDF filesystem created on a Linux box. But, add a file to the disk, and it will set the UID and GID of the file, which a Linux box will then obey.

  • If you then try to mount that filesystem on a FreeBSD box, it yells invalid argument. I assume this is because the kernel devs didn't realize UDF could appear on non-optical media, simply because I couldn't find any reports of success online. Perhaps there is a magic incantation I have missed.

  • It is reportedly possible to get a UDF hard drive to work on Windows, but it is very picky about the way it is created. If you need this to work, it's probably best to format from within Windows. From the command line:

    format /fs:udf x:

    Don't use /q: that creates a filesystem that is less likely to mount on other OSes.

    Note that UDF is only read/write on Vista and newer. XP will mount a UDF hard drive created on Vista, but won't be able to write to it.

Some form of FAT is probably the best option here. If you are avoiding that because of the FAT32 4 GB file size limit, you might wish to look into exFAT. There is a free FUSE version available.

NTFS might also work, if you're using recent enough Linux distros that they include reliable read/write support for NTFS.

share|improve this answer
    
I did some fixing of these options on udf a while back and adding them to ext[234] has been on my todo list for a while. It seems silly that you can do this with udf, and macs can do it with their hfsplus, but linux still can not with its preferred fs. –  psusi May 10 '12 at 14:41
2  
Actually UDF does have posix permissions. If you don't specify the uid/gid options, it stores ownership and permissions just like ext[234] or any other posix fs. If you specify an id, the default is to translate that id to -1 when writing to the disc, and translate -1 to that id when reading from the disc. This makes it easy for a normal user to move files between systems where their id is different. A few years back I added "ignore" as a value to apply the id always, not just when it is -1 on disc, and "forget" always writes -1 to disc, whether the owner matched the default id or not. –  psusi May 10 '12 at 14:58
    
I suspect the reason they allow this for UDF is that UDF is normally used with CD-RW and DVD. That makes it a "mobile" filesystem, so applying missing ownership permissions will be a common need. Besides, it's probably rare to see a UDF filesystem that includes user and group permissions. I still think adding such an option to ext4 would be a potential security hole. But, if that doesn't matter to you, maybe UDF is a good alternative to ext4 in this case. –  Warren Young May 10 '12 at 15:52
    
So UDF is a great solution for devices to be used among different operating systems, rather vfat. –  Marc May 11 '12 at 11:29
    
@Marc: Alas, no. See update above. –  Warren Young May 11 '12 at 13:37

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.