3

I have a very basic question and still failed to find the answer after ~10 google requests and skimming through my unix textbook, so:

Consider a system with 2 hard drives, having root file system at /dev/sda1 and /home partition at /dev/sdb1. Now, a process with UID=1000:GID=1000 wants to mount /dev/sdb1 file system at /mnt/backup. I can imagine 2 scenarios of how it happens:

enter image description here

I wonder, under what UIDs and GIDs he freshly mounted file system is visible:

1. The UIDs and GIDs might be preserved, as on the picture.

enter image description here

2. The UIDs and GIDs on the mounted file system might be set to the mounting process's UID and GID=1000. If there were no UIDs and GIDs in the file system at all, this case takes place:

enter image description here

My questions are:

  1. In what situations cases 1 and 2 take place? What parameters of mount system call determine, which of them takes place?
  2. In case 2, how do I determine the actual UIDs and GIDs of the files. In my example both /mnt/backup/john and /mnt/backup/jane in the mounted filesystem are set to UID=1000, but in fact their UIDs were 1002 and 1003. How do I know them?
  3. In case 1 what happens if the Jane's UID=1003 doesn't exist on the system?
  • UID are not converted. Besides, normal user can't mount, it has to gain superuser or cap_mount priviledges to do so. – BatchyX May 24 '13 at 21:34
  • @BatchyX I've expressed my thoughts in wrong words, sorry. Fixed it. Normal users can mount at least if it's allowed in /etc/fstab. Hm, google doesn't answer, what is cap_mount. What are cap_mount priviledges? – Boris Burkov May 24 '13 at 21:36
  • 1
    Normal users can't mount. normal users must use a SUID program like /sbin/mount (which may allow or refuse, depending on the content of /etc/fstab) to temporarily gain priviledges to mount things. And my mistake, it's not cap_mount, but cap_sys_admin – BatchyX May 25 '13 at 9:13
  • @BatchyX I see, thanks, reading about capabilities now. lwn.net/Articles/486306 – Boris Burkov May 25 '13 at 16:04
3

If you use the command ls -n you can see the UIDs on a given mounted disk/partition.

$ ls -n
total 24
drwxrwxr-x 2 500 501  4096 May 24 15:44 bin
-rw-rw-r-- 1 500 501 11650 May 24 15:44 bouncer.log
drwxrwxr-x 5 500 501  4096 May 23 14:56 testdata
drwxrwxr-x 5 500 501  4096 May 24 14:55 testresults

You can also use the stat command to see more details about a given file's UID/GID:

$ stat bouncer.log 
  File: `bouncer.log'
  Size: 11650       Blocks: 24         IO Block: 4096   regular file
Device: fd02h/64770d    Inode: 11023682    Links: 1
Access: (0664/-rw-rw-r--)  Uid: (  500/    saml)   Gid: (  501/    saml)
Access: 2013-05-24 15:44:17.322878327 -0400
Modify: 2013-05-24 15:44:25.484211596 -0400
Change: 2013-05-24 15:44:25.484211596 -0400

The UIDs are absolute. They're what's on the system. The names are mapped in by the various tools such as ls by looking in the system's /etc/passwd and /etc/group files.

If a number isn't represented in either of these files then the UID/GID number that's on the disk is what's displayed.

It's the responsibility of the sysadmin to make sure that similar UIDs/GIDs across disks are truly the same user and/or group. Unix doesn't provide any mechanism to guarantee this for you.

  • Thank you, slm, very helpful and detailed answer. So, mostly when we deal with portable media, such as flash drives and CDs, their file systems just don't contain UIDs at all, that's why I've never stumbled upon this problem. – Boris Burkov May 24 '13 at 23:23
  • If they're FAT, FAT32, NTFS file systems then yes, they don't contain UIDs/GIDs such as Unix file systems like ext3/ext4. – slm May 24 '13 at 23:26
  • And ISOs too (without Rock Ridge). Got it, thanks. – Boris Burkov May 24 '13 at 23:27
3

User IDs are stored as a part of the file for unix compatible filesystems. There is no conversion. For non unix filesystems, such as fat, you specify what ID to use for all files when you mount it. If the stored ID maps to the wrong user or no user at all, then they will appear to have the wrong ownership.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.