[SOLVED] mount ext4 partition as user partition in /etc/fstab
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
mount ext4 partition as user partition in /etc/fstab
My computer has SDD and HDD. I install install Arch on SDD. So, all of root and home are on SDD. Now I am trying to mount a partition of HDD with ext4 filesystem to /home/username/001HDD in /etc/fstab.
I want /home/username/001HDD with user permissions as I am in my home directory, /home/username.
My trying in /etc/fstab is
Code:
# /dev/sda1 <-- this is HDD partition I am trying to mount
UUID=63edf43c-b195-49da-bb5c-9f14c4e01570 /home/username/001HDD ext4 rw,user,relatime 0 2
It doesn't work. It still mount the partition with root as owner.
Please help me.
Why don't you mount it from ~/.bash_profile? That's what I do. I also take care with ownerships. So if you have root owned files or directories on that disk, everything will go pear shaped sooner or later.
One other thing: I also have '2 >/dev/null' after the mount command to save it spitting out errors if I log in twice.
Why don't you mount it from ~/.bash_profile? That's what I do. I also take care with ownerships. So if you have root owned files or directories on that disk, everything will go pear shaped sooner or later.
One other thing: I also have '2 >/dev/null' after the mount command to save it spitting out errors if I log in twice.
How do you do that? I mean, should I put
Code:
sudo mount /dev/sda1 /home/username/001HDD
in ~/.bash_profile? If so, how can I type sudo password, I know about editing visudo though.
My computer has SDD and HDD. I install install Arch on SDD. So, all of root and home are on SDD. Now I am trying to mount a partition of HDD with ext4 filesystem to /home/username/001HDD in /etc/fstab.
I want /home/username/001HDD with user permissions as I am in my home directory, /home/username.
My trying in /etc/fstab is
Code:
# /dev/sda1 <-- this is HDD partition I am trying to mount
UUID=63edf43c-b195-49da-bb5c-9f14c4e01570 /home/username/001HDD ext4 rw,user,relatime 0 2
It doesn't work. It still mount the partition with root as owner.
Please help me.
A new partition will always mount with root as owner. Once mounted you can do a chown on the mount point. The device and mount point will then be reset to the owner you have specified and will in the future mount that way.
Thus once mounted the command 'sudo chown -R username:username /home/username/001HDD' will change that mount point and the entire file system under it to be owned by username. As I understand it that is your intent.
The entry you post in fstab is perfectly fine, but note that it must be after the entry for mounting /home since the mount point is under the /home directory.
The user option on that line in fstab is unnecessary unless you want to allow your user to mount or unmount that file system. It has no bearing on ownership of the mount point or file system.
Last edited by computersavvy; 04-18-2022 at 07:44 PM.
If a partition mounts on bootup, the owner will always be root.
Not true with my system.
The partition mounts with ownership as it has been set by the chown command while already mounted at the designated mount point.
A partition that has not been mounted then had ownership changed does always mount as root regardless of the ownership of the mount point, but once mounted and chowned the ownership is retained for future mounts.
Last edited by computersavvy; 04-19-2022 at 07:13 PM.
Not true with my system.
The partition mounts with ownership as it has been set by the chown command while already mounted at the designated mount point.
I tried that here. The kernel runs everything as root, so it just mounts it as root.
This is what happens for me.
The partition, /dev/sdd1 has already been chowned to my user since it is a backup of my /home directory
Code:
[root@raptor mnt]# pwd
/mnt
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 2 root root 4096 Mar 11 09:34 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
[root@raptor mnt]# mount /dev/sdd1 home
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 2 root root 4096 Mar 11 09:34 backup
drwxr-xr-x. 3 jvian jvian 4096 Mar 3 17:25 home
[root@raptor mnt]# ls -l home
total 4
drwxr-xr-x. 102 jvian jvian 4096 Mar 2 14:30 jvian
[root@raptor mnt]# umount home
[root@raptor mnt]# mount /dev/sdd1 backup
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 3 jvian jvian 4096 Mar 3 17:25 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
As you can see, the mount point assumes the ownership of the partition mounted even though the mount point was initially owned by root. All the above was done manually as root.
I also have this line in /etc/fstab and the following is done using that as well
Code:
/dev/sdd1 /mnt/backup ext4 defaults 1 2
Code:
[root@raptor mnt]# umount backup
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 2 root root 4096 Mar 11 09:34 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
[root@raptor mnt]# mount -a
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 3 jvian jvian 4096 Mar 3 17:25 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
Thus even when mounted from fstab the mount point assumes the ownership of the partition mounted there.
Code:
[root@raptor mnt]# chown root:root backup
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 3 root root 4096 Mar 3 17:25 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
[root@raptor mnt]# umount backup
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 2 root root 4096 Mar 11 09:34 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
[root@raptor mnt]# mount -a
[root@raptor mnt]# ls -l
total 8
drwxr-xr-x. 3 root root 4096 Mar 3 17:25 backup
drwxr-xr-x. 4 root root 4096 Mar 11 09:37 home
Last edited by computersavvy; 04-19-2022 at 08:09 PM.
Not true with my system.
The partition mounts with ownership as it has been set by the chown command while already mounted at the designated mount point.
Quote:
Originally Posted by business_kid
I tried that here. The kernel runs everything as root, so it just mounts it as root.
Linux-native and non-linux filesystems behave very differently in that respect. Linux-native filesystems (ext2/3/4, btrfs, xfs, ...) store ownership information within each inode. Once you have used chown to change that, the new ownership will be seen each time that filesystem is mounted, regardless of who mounts it. Non-Linux filesystems have no notion of Linux permissions and ownership, so those are faked for the whole filesytem each time the filesystem is mounted, and you can control that with mount options either on the command line or in /etc/fstab.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.