LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 05-08-2017, 06:52 AM   #1
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Rep: Reputation: Disabled
Wink Mounting filesystems in /etc/fstab at system boot


Hi,

I've a basic question about the following:

I'm aware of when linux kernel boot it mounts the root filesystem as read-only in order to perform fs check and such. Then it remounts itself as read-write (rw).

As far as I understand (at least for Read Hat/CentOS based distros) that is done into rc.sysint script (using "mount -n -o remount,rw") upon sbin/init runs it once at boot time.

On the other hand there exist /etc/fstab having entries for filesystem to mount automatically including root filesystem (filesystem mounted as /)

Now the question is: when in the boot process /etc/fstab is actually read and referenced filesystems mounted ?

Thanks
 
Old 05-08-2017, 07:56 AM   #2
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
what init stage is the fstab file read
Google says,

https://www.debian.org/doc/manuals/d...e/ch03.en.html

http://www.linuxjournal.com/article/3016

https://www.safaribooksonline.com/li...9/ch04s02.html

http://etutorials.org/Linux+systems/...nitialization/
 
Old 05-11-2017, 03:43 AM   #3
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
I'm working on a custom Red Hat based system using Upstart init (see below)
Code:
bash-3.2# /sbin/init --version
init (upstart 0.6.3)
Copyright (C) 2009 Canonical Ltd.

This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
bash-3.2
At system boot Upstart init runs /etc/rc.d/rc.sysinit shell script (Upstart init is sysvinit compatible). First lines in that script create mountpoints for /proc and such...
Code:
mkdir -p /proc /sys /tmp /var
Now my question is: As far as I know the 'real' root filesystem is mounted at boot time as read-only (ro) (in order to do a fschk for instance ) thus I guess mkdir should get an error when trying to create those directory...right ?

Then rc.sysinit mounts the root filesystem as rw
Code:
if remount_needed ; then
  action $"Remounting root filesystem in read-write mode: " mount -n -o remount,rw /
fi
So my second question is: why mount explicitly the root filesystem in rw when the same option exist in the related entry in /etc/fstab ? We could simply do a mount -a to mount all filesytems referenced in /etc/fstab including remounting the root filesystem in rw, or not ?

Last edited by cianfa72; 05-11-2017 at 05:00 AM.
 
Old 05-11-2017, 05:52 AM   #4
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,597
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
If Red Hat does things in the same order as LFS, then / gets mounted three times. The first mount is read-write. This is when the dynamic filesystem mount points get checked and created if necessary. In most cases they will exist already, but the -p option prevents an error being reported. Then / is remounted read-only for fsck. Then it gets remounted rw. LFS does that in a later script.

I assume / has to be mounted explicitly before "mount -a" is run so that mounts can be logged.
 
Old 05-11-2017, 08:20 AM   #5
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
This is when the dynamic filesystem mount points get checked and created if necessary.
Here with dynamic filesystems do you refer to proc, sys and tmpfs for instance ?

Quote:
In most cases they will exist already, but the -p option prevents an error being reported.
Excuse me I'm a beginner...but why -p option in mkdir would prevent an error being reported ?

Quote:
I assume / has to be mounted explicitly before "mount -a" is run so that mounts can be logged.
Sorry, what do you mean here ?

Last edited by cianfa72; 05-11-2017 at 09:01 AM.
 
Old 05-11-2017, 09:48 AM   #6
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,597
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
Quote:
Originally Posted by cianfa72 View Post
Here with dynamic filesystems do you refer to proc, sys and tmpfs for instance ?
Yes.
Quote:
Excuse me I'm a beginner...but why -p option in mkdir would prevent an error being reported ?
Didn't you read the mkdir man page? It's the obvious place to get this sort of information about how a command behaves. It says there that when the -p option is used, it prevents an error when the directory already exists.
Quote:
Sorry, what do you mean here ?
The system logs are in /var/log, and that is usually on the root partition. So if you want the mounting of other partitions to be recorded in the logs, the root partition must already be mounted read-write.
 
Old 05-11-2017, 11:06 AM   #7
onebuck
Moderator
 
Registered: Jan 2005
Location: Central Florida 20 minutes from Disney World
Distribution: SlackwareŽ
Posts: 13,925
Blog Entries: 44

Rep: Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159Reputation: 3159
Moderator response

Moved: This thread is more suitable in <Red Hat> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 05-12-2017, 04:26 AM   #8
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by hazel View Post
The system logs are in /var/log, and that is usually on the root partition. So if you want the mounting of other partitions to be recorded in the logs, the root partition must already be mounted read-write.
Just to be sure I've understand it correctly...from my understanding when you mount a filesystem (using command "mount" even with options) the command itself does not write to log files.

Instead into init rc scripts (shell scripts under /etc/init.d/rc.d/<>) using for instance the function "action" (defined in /etc/init.d/functions) messages about operations (mounting a filesystem in this case) are written to log files. So, as you pointed out, in order to record in the logs the mounting of other partitions, the root partition itself (where usually /var/log lives) must already be mounted read-write. Does it make sense ?

Last edited by cianfa72; 05-12-2017 at 04:37 AM.
 
Old 05-12-2017, 05:54 AM   #9
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,597
Blog Entries: 19

Rep: Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455Reputation: 4455
That depends on how Red Hat does its logs. I haven't used a Red Hat distro for years. If they log directly to /var/log/messages or /var/log/syslog, then yes, that requires / to be mounted read-write. But some distros create their boot log on /run, which is usually a tmpfs (effectively a ramdisk), and only copy it over to /var/log on completion of the boot process. In that case / could be mounted read-only and it would still work.

This thread was moved into the Red Hat section precisely so that people more experienced with this distro family could chip in and answer your questions. I think I have come to the end of my knowledge.

Last edited by hazel; 05-12-2017 at 05:56 AM.
 
Old 05-12-2017, 07:55 AM   #10
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Quote:
Originally Posted by cianfa72 View Post
Just to be sure I've understand it correctly...from my understanding when you mount a filesystem (using command "mount" even with options) the command itself does not write to log files.
Prior to RHEL 7, /etc/mtab was an ordinary file maintained by the mount command. That command has a "-n" (--no-mtab) option to mount without writing to /etc/mtab, necessary when /etc is on a read-only filesystem.

Starting with RHEL7, /etc/mtab is a symlink to /proc/self/mounts and is not maintained by the mount command.
 
Old 05-12-2017, 10:51 AM   #11
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by rknichols View Post
Starting with RHEL7, /etc/mtab is a symlink to /proc/self/mounts and is not maintained by the mount command.
Sure....also on my system it's a symlink
Code:
[host:/etc]$ file /etc/mtab 
/etc/mtab: symbolic link to `/proc/mounts'
[host:/etc]$
Quote:
Originally Posted by hazel
If Red Hat does things in the same order as LFS, then / gets mounted three times
As said before for LFS, can you confirm that also for Red Hat the 'real' root filesystem / (just to be clear no the initial initrd or iniramfs mounted on /) gets mounted three times ?

Last edited by cianfa72; 05-15-2017 at 06:55 AM.
 
Old 05-15-2017, 11:03 AM   #12
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Smile

Any help ?
 
Old 05-15-2017, 05:12 PM   #13
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
Which RHEL/CentOS version? A lot of things changed in version 7.
 
Old 05-16-2017, 02:02 AM   #14
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Can you consider RHEL 7.2 or just Centos 6.0 (running on another PC).

Thanks
 
Old 05-16-2017, 08:43 AM   #15
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: Rocky Linux
Posts: 4,780

Rep: Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213Reputation: 2213
For RHEL/CentOS 6, it's all in the rc.sysinit file that you mentioned. The reason that /etc/fstab is not consulted for remounting root read/write is because there is a large section of that file devoted to the case of the "readonlyroot" option in the kernel command line, and read/write is assumed without that, regardless of what is in /etc/fstab. Special filesystems critical to the boot sequence (/proc, /sys, ...) get mounted early by the fstab that is in the initrd prior to mounting the real root filesystem. All other non-network filesystems are mounted by a "mount -a" command at about line 525 in rc.sysinit, and that mount command uses /etc/fstab.

For RHEL/CentOS 7, you'll have to talk to a systemd fanboi expert.
 
  


Reply

Tags
/etc/fstab, filesystem, mounting, rootfs



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
mounting root file system at boot: error w/ fstab (not fdisk) Drone4four Linux - General 9 12-14-2011 02:37 PM
`nouser' prevents anyone but root mounting filesystems in the /etc/fstab in linux Frustin AIX 1 07-11-2005 08:27 AM
suse 9.0 - mounting original filesystems from rescue system fredcll Linux - Distributions 1 05-10-2004 02:28 PM
System hangs when Mounting local filesystems, help please!! slopez Linux - General 3 03-05-2004 03:37 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 01:11 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
Open Source Consulting | Domain Registration