LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-24-2014, 01:44 AM   #1
s.verma
Member
 
Registered: Oct 2013
Distribution: Debian Sid, Gentoo, Arch, Debian
Posts: 169
Blog Entries: 4

Rep: Reputation: 24
'mount' command permissions retention


I created a filesystem on file 'file.img' formatted with ext4, a mountpoint 'temp/' in the current directory.

Commands Issued
Code:
$ dd if=/dev/urandom of=file.img bs=1024 count=10000
10000+0 records in
10000+0 records out
10240000 bytes (10 MB) copied, 1.06567 s, 9.6 MB/s
$ mkdir temp
$ ls -l
total 10004
-rw-r--r-- 1 username users 10240000 Apr 24 10:56 file.img
drwxr-xr-x 2 username users     4096 Apr 24 10:57 temp/
$ mkfs.ext4 file.img
mke2fs 1.42.8 (20-Jun-2013)
file.img is not a block special device.
Proceed anyway? (y,n) y
Discarding device blocks: done                            
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
2512 inodes, 10000 blocks
500 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=10485760
2 block groups
8192 blocks per group, 8192 fragments per group
1256 inodes per group
Superblock backups stored on blocks:
        8193

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (1024 blocks): done
Writing superblocks and filesystem accounting information: done
$ sudo mount file.img temp/
$ ls -l
total 1173
-rw-r--r-- 1 username users 10240000 Apr 24 10:59 file.img
drwxr-xr-x 3 root   root      1024 Apr 24 10:59 temp/
As I can not write inside temp/ as normal user, I issued
Code:
$ sudo chmod 757 temp/
$ ls -l
total 1173
-rw-r--r-- 1 username users 10240000 Apr 24 10:59 file.img
drwxr-xrwx 3 root   root      1024 Apr 24 10:59 temp/
Now when I umount it, temp/ returns back to its permissions
Code:
$ sudo umount temp
$ ls -l
total 1176
-rw-r--r-- 1 username users 10240000 Apr 24 11:02 file.img
drwxr-xr-x 2 username users     4096 Apr 24 10:57 temp/
Now when I again mount file.img
Code:
$ sudo mount file.img temp
$ ls -l
total 1173
-rw-r--r-- 1 username users 10240000 Apr 24 11:03 file.img
drwxr-xrwx 3 root   root      1024 Apr 24 10:59 temp/
This time temp/ has retained 757 permission without my changing it. How it happened?
Where mount (or linux) store information what permission to give to a mountpoint when it is mounted?
 
Old 04-24-2014, 09:03 AM   #2
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
When you have mount point, chmod refers to the filesystem so mounted. When dismounted, the file reference returns to what it was BEFORE the mount.

When you remounted the filesystem, the access modes are from the chmod done when it was originally mounted.

One way to think about this is that the directory file reference (in memory) contains two parts - the name, and its location in the directory tree... The other half is an inode reference containing the connection to the contents of the directory (the inode carries the access mode).

When you mount a filesystem onto a directory, the top half (the one with the name and location in the directory tree) remains unchanged... But the other half is replaced by a reference to the now mounted filesystem, which has the inode of the root directory of that filesystem. And that inode has the access mode for the filesystem, which is now visible due to the mount.

The original access mode is covered up. It is still in the system buffers though, so when you dismount the filesystem the original inode reference is restored, and the original access mode is visible again.

When you change the access mode while a filesystem is mounted, the change is done to the inode from that mounted filesystem. So a dismount restores the visibility of the original mode. The inode from the previously mounted filesystem carries the access mode that was changed.

Last edited by jpollard; 04-24-2014 at 09:06 AM.
 
Old 04-24-2014, 09:37 AM   #3
Shadow_7
Senior Member
 
Registered: Feb 2003
Distribution: debian
Posts: 2,326
Blog Entries: 1

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
If you add the mount to /etc/fstab with the option users you can do the mount as the user and it will have the permissions of the user. You can also pass -o users to the mount command as root. Just bear in mind that ext4 is a filesystem who's only default permissions belong to root (aka / + lost+found). So you'd have to mount it, and change the permissions to be written to by the user, before it would be of any use to a user. Also on my system, mkfs.ext4 is not available to userland (debian defaults).
 
Old 04-25-2014, 06:51 AM   #4
s.verma
Member
 
Registered: Oct 2013
Distribution: Debian Sid, Gentoo, Arch, Debian
Posts: 169
Blog Entries: 4

Original Poster
Rep: Reputation: 24
Dear jpollard,

Quote:
chmod refers to the filesystem so mounted.
Quote:
...a reference to the now mounted filesystem, which has the inode of the root directory of that filesystem...
Quote:
...the change is done to the inode from that mounted filesystem...
OK as far as I understood it, I am restating it in my words.
"The temp/ after mount become root of the mounted filesystem, and hence when I am changing permissions after mount then the permissions are changed for the root of file.img, and not the actual temp/ directory created. Hence comes the two different inodes. The inode of file.img is changed, while the inode of temp/ directory before mount is not."

Please let me know if I have got it correctly (as I do not know much about inodes, except that they are some kind of references to files).


Thanks Shadow_7,
But I was just trying to find out how the changed permissions of root of filesystem was retained in second mount which I think is answered by jpollard if I have been able to understand him/her correctly.

Last edited by s.verma; 04-25-2014 at 06:57 AM.
 
Old 04-25-2014, 07:14 AM   #5
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,604

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
The only error is the "inode of file.img" which isn't involved - the inode being modified by the chmod is from the root inode of the filesystem WITHIN the file.img file. The inode data is stored in the file.

The inode OF the "file.img" is not touched other than when mounting the file to locate where the data for the filesystem being mounted resides.
 
1 members found this post helpful.
Old 04-25-2014, 10:15 AM   #6
s.verma
Member
 
Registered: Oct 2013
Distribution: Debian Sid, Gentoo, Arch, Debian
Posts: 169
Blog Entries: 4

Original Poster
Rep: Reputation: 24
OK I got it, it is inode of root inside filesystem and not 'file.img'.

Errata:
Quote:
The inode of file.img is changed,
to be replaced by
Quote:
The inode of root of filesystem contained in file.img
Thanks for the help!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Retention DAT Tape? iwbnwif Linux - Hardware 4 02-07-2014 11:23 AM
[SOLVED] Apache Log retention Iyyappan Linux - Server 12 07-09-2012 09:44 AM
[SOLVED] Processor cooler mount conversion (Scythe Universal Retention Kit?) catkin Linux - Hardware 4 12-23-2011 07:19 AM
Limited retention of files.... GiX Linux - Newbie 3 01-25-2006 03:21 PM
file permissions OK, but command permissions? stabu Linux - General 2 10-05-2005 01:00 PM


All times are GMT -5. The time now is 11:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration