LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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-17-2022, 05:42 AM   #1
lqmsh
Member
 
Registered: Oct 2021
Posts: 32

Rep: Reputation: Disabled
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.

Last edited by lqmsh; 04-17-2022 at 05:44 AM.
 
Old 04-17-2022, 05:56 AM   #2
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
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.
 
Old 04-17-2022, 06:19 AM   #3
lqmsh
Member
 
Registered: Oct 2021
Posts: 32

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by business_kid View Post
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.

Could you please elaborate a little bit more?

Last edited by lqmsh; 04-17-2022 at 06:20 AM.
 
Old 04-17-2022, 06:37 AM   #4
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,736

Rep: Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920Reputation: 5920
With the drive mounted run the command

chown username:username /home/username/001HDD

(Replace username with your actual username, either su as root or use sudo depending on how your system is configured)
 
Old 04-18-2022, 04:58 AM   #5
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
Quote:
Originally Posted by lqmsh View Post
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.

Could you please elaborate a little bit more?
If you have it listed in /etc/fstab with the 'noauto' option correctly, you don't need sudo.
Code:
/home/username/001HDD[ 2>/dev/null

should do it. I'd leave the '2 >/dev/null' bit out until you checked it so as not to lose errors.
 
Old 04-18-2022, 07:38 PM   #6
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by lqmsh View Post
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.
 
1 members found this post helpful.
Old 04-19-2022, 04:33 AM   #7
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
If a partition mounts on bootup, the owner will always be root.

To get a user as owner, try this approach:
/In /etc/fstab:
Code:
/dev/sdb1 	 /mnt/hd	  ext4	      users,noauto,noatime,diratime	0    0
In ~/.bash_profile:
Code:
mount /mnt/hd 2> /dev/null
That works every morning I boot up - as user. I also have all subdirectories user owned.
 
1 members found this post helpful.
Old 04-19-2022, 10:25 AM   #8
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Quote:
Originally Posted by business_kid View Post
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.
 
Old 04-19-2022, 11:04 AM   #9
business_kid
LQ Guru
 
Registered: Jan 2006
Location: Ireland
Distribution: Slackware, Slarm64 & Android
Posts: 16,356

Rep: Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332Reputation: 2332
Quote:
Originally Posted by computersavvy View Post
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.
 
Old 04-19-2022, 07:45 PM   #10
computersavvy
Senior Member
 
Registered: Aug 2016
Posts: 3,345

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
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.
 
Old 04-19-2022, 09:27 PM   #11
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214Reputation: 2214
Quote:
Originally Posted by computersavvy View Post
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 View Post
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.
 
  


Reply



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
\vi/etc/fstab works fine . vi /etc/fstab throws bash command not found in Rescue mode jsaravana87 Linux - Server 1 05-13-2013 02:08 PM
[SOLVED] How to edit /etc/fstab so that normal user has read/write access to ext4 partitions glupa4e Slackware 2 04-08-2011 12:33 AM
server startup error: "cannot find / in /etc/fstab or /etc/mtab"; /etc/fstab readonly knee-co Linux - Newbie 8 09-12-2010 05:37 PM
fstab problem: mount: can't find dvd in /etc/fstab or /etc/mtab Nikon01 Slackware 5 11-17-2006 06:15 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:41 PM.

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
Open Source Consulting | Domain Registration