18

This is a problem I'm having when using Ubuntu: I have two computers that have Ubuntu installed on them (comp1 and comp2). I create a document with Ubuntu on comp1 and then copy the file onto a FAT formatted USB flash drive. Via the flash drive I paste the document onto comp2. The problem is that the file-permissions are never preserved during the transfer. I'm assuming because the FAT is not supporting the permissions.

Is there a solution to this? Should I continue to use FAT file system for USB flash drives (because FAT is best for flash drives) and just live with this permissions issue? Or is it recommended to reformat my flash drive with a more "Ubuntu Friendly" file system that will preserve the permissions?

5 Answers 5

11

ext4 is a journalling filesystem which means that if the device is unplugged prematurely it stands more of a chance of recovering the damaged filesystem. The journal part of the write contains information about what is about to be done and it gets cleared after the operation is completed. If it is found that there is an uncompleted journal on a device when it is mounted, the filesystem can be reverted to it's previous state thereby preserving its integrity.

While there is some extra overhead in terms of space involved in having a journalling filesystem on a USB stick, it's actually a good choice for most things.

Obviously, if you need a device that can also plug into any computer at any time then FAT would be the way to go. If you want a device that needs to be plugged into one Windows computer only occasionally, then it's possible to install ext2 device drivers in Windows that will allow it to read any and all ext(x) drives. Of course, since Windows doesn't know about Linux permissions and ownership these will not be handled as well.

2
  • I could not have said it better. +1 Commented Dec 24, 2012 at 3:09
  • The Ext2 driver for Windows should be able to read Ext4 filesystems as well - it will simply ignore the journal. Commented Oct 14, 2013 at 19:42
8

When using a filesystem which preserves user IDs on a USB drive you may face problems caused by the fact that user IDs are assigned in the order user accounts are created, and the filesystem actually stores numeric IDs of file owners, not usernames. So if, say, machine A has alice and bob accounts, and machine B has bruce, zoe and alice accounts then it likely that when Alice copies her files to an ext(2/3/4)-formatted USB drive, walks to machine B and tries to access the files she will discover that the files are all owned by bruce and are read-only for alice.

Of course, if you only have one user on both machines then this won't be a problem.

Transferring files packed in a tar archive, as proposed by @FSMaxB may solve this problem because when you unpack an archive the files will be created owned by your user ID.

8

You can try formatting your drive as UDF(Universal Disk Format). It is the format for use on CD's and DVD's. Most modern OSes will be able to read and write to it.

Right now, looking at my data on UDF formatted drive, Linux file permissions seem to be preserved. So far, it's worked for me.

Another good thing about UDF formatted drive is that it can store a single large file of up to 16 Exabyte(correct me if I'm wrong.), whereas Fat32 can only store a file of size 4GB or less and MAX partition size for FAT32 is only 2TB.

It works good on Win7 and 8. For older Windows OSes like XP and 2000, you can read from the drive but you have to install some sort of driver to write to it.

For Mac, OS X 10.5 and above has full compatibility. Here's a full compatibility chart. UDF Compatibility Chart

On Ubuntu, follow these steps to format a drive as UDF.

sudo apt-get update
sudo apt-get install udftools

Okay, now you want to delete the current partitions in the target drive. You can either use a GUI tool like Disk Utility, or do the following.

sudo blkid

Find your drive in the output. (they look something like /dev/sdb or /dev/sdc) Now do the following, but replace the 'x' in /dev/sdx to point to the drive that you want to clear its partition. Do this for both lines of code.

sudo dd if=/dev/zero of=/dev/sdx bs=1M count=1
sudo mkudffs -b 512 --media-type=hd --utf8 --lvid=DriveLabel --vid=DriveLabel --fsid=DriveLabel  /dev/sdx

You could alter where it says 'DriveLabel' to your liking.

That should be it.

Actually, I do this slightly differently, but decided that this method was easier to follow. I referenced this method from this site.

I hope this helps someone out there.

2
  • doesn't work for me : error when mounting the usb drive
    – Louis
    Commented Dec 24, 2015 at 12:48
  • 1
    Thank you, very interesting approach.Works perfectly for desktop OS'es (tested for Ubuntu 15.10+, Windows 7+), but not for mobile (definitely not work for Android up to 8.x). I expect much less write impact to flash drive comparing to journaling file system. Here's a one-liner for this: CreateUdfFlash(){ sudo wipefs "$1" ; sudo mkudffs --utf8 -b 512 --media-type=hdd --lvid="$2" --vid="$2" --fsid="$2" "$1" ; } ; CreateUdfFlash "/dev/sdX" "Some Disk Label"
    – dess
    Commented Sep 28, 2018 at 12:36
0

If you use your flash drive only with linux systems, you may use one of the ext-filesystems e.g. ext4 but when using with other systems, FAT is the only compatible file system.

One way of using FAT and preserving permissions (not ownership) would be the usage of tar-Archives!

10
  • 1
    unpacking a tar archive as root preserves ownership of files, so archives themselves do store user IDs. However, doing that on different machines is not really recommended because user IDs may differ.
    – Sergey
    Commented Dec 24, 2012 at 0:51
  • Thanks. I think I will try the TAR solution for now. Question: is there a way to create the TAR and have it be created on the flash drive? I nav to directory where file is I want to TAR and when I run TAR command the archive is created in that directory. Can I get the archive to be created on the Flash Drive instead?
    – Greg
    Commented Dec 24, 2012 at 0:52
  • creating TAR requires BASH right? Or is there a GUI way to do it?
    – Greg
    Commented Dec 24, 2012 at 0:53
  • If you use a normal ubuntu, you can rightclick on files or directories and click on "compress" (don`t know if it is called like this, because I use a german system)
    – FSMaxB
    Commented Dec 24, 2012 at 1:00
  • I didn't try tar from the gui but used tar.bz2 to compress from the gui and the bash with "tar -xf" to decompress, which preserved my permissions.
    – FSMaxB
    Commented Dec 24, 2012 at 1:08
0

I'm using reiserfs for years on USB-Sticks without problems. Well - just that they aren't readable from windows systems which might not be bad, if they get lost.

If you partition a stick, to use parts with Windows for data exchange, make sure the windowspartition is the first one - else it won't be identified (at least for XP I made the experience).

You can build a fat-filesystem (aren't they pretty limited for todays stick sizes?) and add an big but empty file to it, and mount that file as a loop device in Ubuntu. Then you will be able to preserve your file permissions, and to increase or decrease the reserved space without partitioning or formatting.

As already mentioned: Tars, Zips and so on are another possibility.

You must log in to answer this question.

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