Linux - GeneralThis 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
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.
Hello all, I am booting a 2.6 kernel from a USB drive and would like to determine the boot device major and minor numbers or device name from an init script. I'd like to get this information at run-time from the kernel if possible.
I'm actually trying to determine the boot device from within initramfs while executing my init script. No devices have been mounted yet, so I can't do what Lightning has prescribed.
I was hoping there was some file within /proc that I could parse to get this information.
There is the file 'cmdline' which could show the command line options if any such as "root=/dev/sdb1". However, this is not a fool-proof solution. I was hoping for something better...
Look if your distro is booted by Lilo the the root of the Linux is in the "root=" or "boot=" statement inside /etc/lilo.conf.
For Grub it has a "root" statement telling us the partition number j and the disk number i in the (hdi,j) notation. This is the partition where it gets the kernel from but the root "/" may be in a different partition (as often in Red Hat family distros) but the information is always showed as a parameter "root=" in the kernel statement.
Red Hat family like to address the partition reference by a libel.
Ubuntu family distros started to use the UID notation too.
However the actual boot loader is always residing in the partition specified by the "root" statement of /boot/grub/menu.lst as far as Grub is concerned.
The problem I have is that I am trying to boot from a USB drive which uses the GRUB boot loader to load a custom built kernel.
It turns out that the system I am booting on, will likely also have a IDE disk drive that also happens to have GRUB installed.
So as far as GRUB is concerned, I can't really tell the difference were I to browse the files found in /boot/grub.
I'm wanting to mount the correct boot device so that I can detect, partition and format other disks found in the system so that I may install Linux on to the other disk.
I'm trying to avoid re-partitioning and formatting my boot device!
The $ cat /proc/partitions will definitely work for unmounted devices, in fact I have been doing this to see what all devices are available. However, it does not reveal which device is the boot device.
Unfortunately, nothing has been mounted yet since I'm running from initramfs which is sort of like a ram disk managed by the kernel. Hence, nothing will be shown yet in mountstats.
The /proc/partitions file definitely shows all the disk devices and their partitions at this time. I wish it also specified which device the kernel was booted from.
I'm not having any difficulty booting the Linux kernel from GRUB at all. It boots just fine. The problem is that once booted, I can't tell which device I booted from. My system will have multiple devices present. It's important that I know which one I booted from because I do not want to re-install Linux on top of my boot device.
I'd rather not specify the boot device explicitly on the command line because there is always the chance that what's specified on the command line may not necessarily be the device which Linux is booted from.
For example, imagine a system that has multiple USB ports with drives attached. On system A the boot device could be mapped as /dev/sdc1 and another USB drive mapped as /dev/sdd1. On system B, it could be the opposite of this mapping. If I explicitly specify a device name on the Linux command line, it may not always be correct.
I'd like for the Linux install to detect the boot device name rather than be told what it is from the command line. It seems like it would be more robust / less error prone if this were possible.
Now I get it. This is done by knoppix among others. One of the first few lines when booting a knoppix live-cd is something like "Accessing KNOPPIX at /dev/hdd..". IIRC it's the linuxrc file inside minirt.gz.
You would need to boot a knoppix cd and study the linuxrc file.
gunzip /boot/isolinux/minirt.gz
make a mountpoint and mount it with: mount -o loop /path/minirt /your_mountpoint
It's a while since I played with knoppix, so check the paths. /boot could be /cdrom/KNOPPIX/boot or some such.
Knoppix sources are found at http://debian-knoppix.alioth.debian.org/
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.