Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

The way I understand it, initramfs is responsible for loading the "real" root filesystem.

Now, there are two places where we define that root. First we put an entry in /etc/fstab. Second, we put the device on the kernel boot commands e.g. root=/dev/sda1.

Which one does initramfs use to determine where is the root filesystem? If it uses the root kernel parameter, why do we have an entry in /etc/fstab? The second option, (it reads /etc/fstab), is quite illogical because the /etc/fstab file is on the very root device that initramfs is trying to mount in the first place.

Very confusing stuff.

share|improve this question

3 Answers 3

up vote 4 down vote accepted

As you stated, the purpose of initramfs is to get the "real" root filesystem mounted (it can do other things too, but this is the common task).

Without an initramfs, the kernel will normally mount a partition up as read-only and then pass control over to /sbin/init. An initramfs just takes over this task from the kernel, usually when the root filesystem isn't a normal partition (mdraid, lvm, encrypted, etc).

Now, aside from the background on initramfs, your /etc/fstab resides on your root filesystem. As such, when initramfs is launched, that root filesystem isn't there, and so it can't get to the fstab (chicken and egg problem).
Instead we have to pass a parameter into the kernel boot arguments for the initramfs to use. Normally this is something like root=/dev/sdX. However it might also do something to automatically figure out where your root device is, and so there's no parameter at all. Since it's just software (generally a script), it can really do anything it wants for mounting the root device.

Now, as stated earlier, the kernel will mount the real root as read-only. The initramfs should do exactly this. Once the initramfs is done, the system proceeds booting exactly as if there were no initramfs at all, and /sbin/init starts up. This init then starts all your normal boot scripts, and it's the job of one of these scripts to read /etc/fstab, switch root to read-write, and mount all your other filesystems.

share|improve this answer
    
So, you are saying that /sbin/init inside the real root filesystem would again remount root using the options in the /etc/fstab? –  Ahmed Ghonim Sep 28 '13 at 13:32
2  
Yes. Usually via a simple mount -o remount,rw /. It won't change the device that is mounted, but it will change the options on the mount. From man page: After this call mount reads fstab (or mtab) and merges these options with options from command line –  Patrick Sep 28 '13 at 18:00

You can consider /etc/fstab as static mounting, it's only a way of doing such a task, but not the only, in fact, run the command mount, and you see a lot of filesystems that are missing in fstab. Service such a udev and udisk manage much of the "automounting" ignoring the /etc/fstab file...

So, if something is mounted or not often it has nothing to do with /etc/fstab.

initramfs it's only a temporary rootfs used during the boot process until the "true" rootfs is mounted, so why should initramfs be on /etc/fstab ?

share|improve this answer

It may or it may not. As the Initramfs can be constructed in various ways (the kernel just loads it and runs /init which does whatever). However, using a parameter is more common, as it allows more flexibility - i.e. if something changes you can just edit the boot entry and things keep working. With a builtin hardcoded root, this would not necessarily be possible.

The fstab entry may still be required either way as it also determines other things, such as mount options (some of which can be changed on the go) and fsck order. Also even if it was entirely superfluous (and if the Initramfs handles it, it may work without), I'd still keep the entry in there simply for completeness sake.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.