LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 03-16-2017, 07:36 AM   #1
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Rep: Reputation: Disabled
chicken - egg linux boot sequence


Hi,

maybe is a very basic question but me is unclear the following:

Consider for instance a GRUB-based linux boot sequence where GRUB is instructed with kernel boot options

e.g.
Code:
grub> kernel (hd0,1)/boot/vmlinuz-2.6.32.12 root=/dev/hda
here the additional “root=/dev/hda” is in order to instruct the kernel which device has to be mounted as root file system (/)

Now my (chicken - egg) doubt is: how the kernel can find out which disk partition the device /dev/hda represents if the root filesystem is not available yet (because not mounted yet)?

thanks
 
Old 03-16-2017, 07:39 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,475

Rep: Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553Reputation: 1553
The initrd image has enough information to enumerate devices for the kernel
 
Old 03-16-2017, 07:51 AM   #3
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
Maybe. But not required.

If the device and controller support is compiled into the kernel, the kernel can find the device it needs - else, as stated, the initrd has to incorporate the support.
BTW is would be unusual to have a device specified as root=...
Not unknown, but not normal. The kernel doesn't need the root mounted - everybody else does.
 
Old 03-16-2017, 08:25 AM   #4
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
If the device and controller support is compiled into the kernel, the kernel can find the device it needs - else, as stated, the initrd has to incorporate the support.
The kernel doesn't need the root mounted - everybody else does.
ok, thus basically kernel just know that the string '/dev/hda' refers to the first disk of IDE controller and so on...(e.g. /dev/hdb the second IDE controller's attached disk....) and it is not conceived as a path starting from / (because as you pointed out kernel doesn't need root filsystem mounted).

Does it make sense ?
 
Old 03-16-2017, 09:16 AM   #5
cynwulf
Senior Member
 
Registered: Apr 2005
Posts: 2,727

Rep: Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367Reputation: 2367
LILO performs raw mapping, so it loads the kernel by mapping it's location on the disk (this is done when you run lilo and it parses the config file and writes itself to the mbr).

Grub can read some filesystems (particularly ext2/3/4) and can load it's configs and kernels directly.

You usually do need to specify the root filesystem if you've configured to load an initrd/initramfs.
 
Old 03-16-2017, 10:17 AM   #6
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Grub probably has built-in support for the filesystem you are using. It knows how to identify the filesystem and to read the files without relying on the support of an operating system that, of course, does not exist yet.

Notice, however, that it has its own device-numbering system, counting from zero. You must use a form of device reference that is understood by GRUB.

Grub comes-and-goes before the "initrd" step is reached.
 
Old 03-16-2017, 01:22 PM   #7
273
LQ Addict
 
Registered: Dec 2011
Location: UK
Distribution: Debian Sid AMD64, Raspbian Wheezy, various VMs
Posts: 7,680

Rep: Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373Reputation: 2373
Quote:
Originally Posted by cianfa72 View Post
ok, thus basically kernel just know that the string '/dev/hda' refers to the first disk of IDE controller and so on...(e.g. /dev/hdb the second IDE controller's attached disk....) and it is not conceived as a path starting from / (because as you pointed out kernel doesn't need root filsystem mounted).

Does it make sense ?
That's how I always read it -- hence the issues when another HDD is installed at boot and the kernel finds it first.
 
Old 03-17-2017, 03:25 AM   #8
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
Grub probably has built-in support for the filesystem you are using. It knows how to identify the filesystem and to read the files without relying on the support of an operating system that, of course, does not exist yet.
Notice, however, that it has its own device-numbering system, counting from zero. You must use a form of device reference that is understood by GRUB.
As far as can I understand, here you're talking about the boot loader (GRUB in this case) and how it can locate the kernel image + initramfs (eventually) from the boot partition (basically the disk partition with a filesystem on it storing, among other files, the kernel image + initramfs).

My original question was instead how the kernel code itself (loaded in RAM by GRUB for instance) can "interpretate" the 'root=/dev/hda' option passed to it in order to locate and mount as / the filesystem in the disk partition that will become "the root partition".
 
Old 03-17-2017, 08:42 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
That string is called a "boot parameter." See man 7 bootparam for an explanation of how it works.

Another good explanation is found here at kernelnewbies.org.
 
Old 03-17-2017, 12:28 PM   #10
hazel
LQ Guru
 
Registered: Mar 2016
Location: Harrow, UK
Distribution: LFS, AntiX, Slackware
Posts: 7,573
Blog Entries: 19

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
I'm puzzled by all the references to /dev/hda. That's the designation for a drive, not a partition. The root partition should have the name /dev/hda[1..4] (or more likely these days /dev/sda[1..4]).

As far as I know, the kernel assigns the disk device name when it detects the disk. It then goes to the partition table of the disk and finds out where that particular numbered partition begins and ends. It mounts that partition on /.

If there's an initrd, it gets loaded onto a ramdisk and that becomes the root device until it calls pivotroot to switch to the real thing.
 
1 members found this post helpful.
Old 03-22-2017, 04:13 AM   #11
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
I'm puzzled by all the references to /dev/hda. That's the designation for a drive, not a partition. The root partition should have the name /dev/hda[1..4] (or more likely these days /dev/sda[1..4]).

As far as I know, the kernel assigns the disk device name when it detects the disk. It then goes to the partition table of the disk and finds out where that particular numbered partition begins and ends. It mounts that partition on /.
Sure, maybe it is just a typo: basically you are saying the kernel just "knows" for instance the string '/dev/hda1' (passed as 'root=' boot parameter by GRUB to it) refers to the first partition of the disk it has detected and named as /dev/hda1'. Then, if there is not initrd, that partition will be mounted as /.

Now, if that is right, next point is: when the content of fstab file is read and the filesystems referred there are mounted as specified ?

thanks.

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

Rep: Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452Reputation: 4452
You need to know that disk nomenclature has changed over the past 2-3 years. Under the old system, the kernel named IDE disks according to their location: the master drive on the first controller was hda and the slave was hdb. For the second controller the names were hdc and hdd. SCSI drives were sda, etc, named in the order in which they were detected.

No modern kernel does this. The modern disk driver handles IDE and SCSI disks identically and calls them all sd*. To avoid random device name changes during boot, the udev daemon enforces fixed names and informs the kernel about them.

Mounting filesystems other than root is done by one of the init scripts. It's usually called something like mountfs.
 
Old 03-22-2017, 07:54 AM   #13
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Also: the only thing that Grub does is to provide a string to the kernel in an agreed-upon location before it forever hands-over the car keys. Grub does not know, nor does it care, what the string might mean to Linux. Interpretation of the string, including deciding just what /dev/foobar means to the kernel, is entirely up to the kernel ... and Grub is long gone by then. It's entirely up to you to provide the "correct" string. Grub knows nothing about them except, "the human told me to give you this."

Grub uses its own device-id scheme, counting from zero, for its own purposes. It is able to determine which device the computer was booted from, and it is capable of reading several common file systems so it is able to find and read its configuration files. (It's really a very "smart" program by now.) Grub reads these files and must correctly interpret them. Linux knows nothing about them except that they are there.

Last edited by sundialsvcs; 03-22-2017 at 07:57 AM.
 
Old 03-22-2017, 08:25 AM   #14
cianfa72
LQ Newbie
 
Registered: Dec 2016
Posts: 27

Original Poster
Rep: Reputation: Disabled
Quote:
But this has nothing to do with the content of the parameter-string, if any, that Grub provides to the kernel that it is loading.
ok, thanks for the clarification...

Quote:
Grub uses its own device-id scheme, counting from zero, for its own purposes. It is able to determine which device the computer was booted from
Thus, for instance, does GRUB enable the user to find out which device the computer is/was booted from ?
 
Old 03-22-2017, 08:59 PM   #15
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940Reputation: 3940
Quote:
Originally Posted by cianfa72 View Post
Thus, for instance, does GRUB enable the user to find out which device the computer is/was booted from ?
I do not know the answer to that question.
 
  


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 On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Linux bootup chicken-egg problem understanding jeffmonte Linux - Newbie 5 09-26-2013 08:15 AM
chicken-Egg problem in booting sequence ashishravande Linux - Newbie 11 03-16-2013 11:43 AM
[SOLVED] The Chicken and the Egg... ButterflyMelissa Linux - Software 6 09-04-2011 02:20 PM
The chicken, or the egg...... ErrorBound General 9 06-19-2007 05:56 AM
Which came first...the chicken of the egg? ugenn Linux - Newbie 3 04-13-2002 09:17 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:08 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