Red HatThis forum is for the discussion of Red Hat Linux.
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.
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 ?
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 ?
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.
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.
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 ?
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.
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.
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 ?
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.