Question

I copied files from a partition of bootable pendrive using

sudo cp -Rrf --preserve=all /media/Necktwi/BOOT/* BOOT/

I could able copy back as it is using sudo cp -Rrf --preserve=all BOOT* /media/Necktwi/BOOT/ when ubuntu mounts the partition.

But when I mount using

sudo mount -w /dev/sdc1 /mnt/boot

and try to copy back all its contents I get cp: failed to preserve ownership for each file being copied.

the /etc/mtab entry for the partition when ubuntu mounts it is

/dev/sdc1 /media/Necktwi/boot vfat rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2 0 0

the /etc/mtab entry for the partion when I mount with mount command above is

/dev/sdc1 /mnt/boot vfat rw 0 0

so I think I should specify some extra options in my mount command. My partition is fat16. How to avoid the cp: failed to preserve ownership error?

Was it helpful?

Solution

The FAT file system has no support for ownership. So what Linux does is it simulated the owner and group fields of the file by passing uid=1000,gid=1000 to mount which says: "Every file and directory is owned by 1000 and group 1000."

To find out what these IDs mean, use getent:

getent passwd 1000

gives you the owner (user) and

getent group 1000

gives you the group.

To fix the error, use

sudo mount -o uid=1000,gid=1000 /dev/sdc1 /mnt/boot

but the other options work around other, important issues with FAT and Linux so a better solution is to take all of them and mount via a script.

#!/bin/bash
options="rw,nosuid,nodev,uid=1000,gid=1000,shortname=mixed,dmask=0077,utf8=1,showexec,flush,uhelper=udisks2"
mount -o "$options" /dev/sdc1 /mnt/boot

and invoke the script with sudo.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top