LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   LFS 7.8 Setting up grub to boot from flash drive (https://www.linuxquestions.org/questions/linux-from-scratch-13/lfs-7-8-setting-up-grub-to-boot-from-flash-drive-4175572965/)

skender1234 02-22-2016 07:41 PM

LFS 7.8 Setting up grub to boot from flash drive
 
Hallo guys,

I built LFS 7.8 completely on a flash drive without any problems. Those only occur as I get to the booting part. I'm not quite sure what to write to the grub.cfg as my drive (sda, sdb...) changes whenever I plug the flash drive into another hardware configuration.

Code:

set root=(hd0,2) // what should I set here?

menuentry "GNU/Linux, Linux 4.2-lfs-7.8" {
        linux  /boot/vmlinuz-4.2-lfs-7.8 root=/dev/sda2 ro //and here for sda2
}

When I try to boot from usb I only get the grub commandline. I managed to boot the system by issuing:

Code:

set root=(hd0,1)
linux /boot/vmlinuz... root=/dev/sdb1 ??
boot

if the root (/dev/sdb1 here) is nonexistent boot fails. If it exists some boot messages appear but after about two seconds there is some kernel panic and the only thing I can see is the end of a stack trace.

I would be very grateful if someone could help me here. Even telling where to find the boot log would be very helpful. I looked in /var/log but all the files are empty :/

Thanks in advance.

stoat 02-23-2016 03:02 PM

Here are the things that I do in order to boot my BLFS system from an external USB drive...

1. Compile a kernel to build in USB support (for core, port, and storage drivers) and initial RAM filesystem support (for booting with UUID or LABEL).
a. USB support...
Code:

...[*] USB support ---> (CONFIG_USB_SUPPORT=y)
        |
        |...<*> Support for Host-side USB (CONFIG_USB=y)
        |...<*> EHCI HCD (USB 2.0) support (CONFIG_USB_EHCI_HCD=y)
        |...<*> Generic EHCI driver for a platform device (CONFIG_USB_EHCI_HCD_PLATFORM=y)
        |...<*> OHCI HCD (USB 1.1) support (CONFIG_USB_OHCI_HCD=y)
        |...<*>  OHCI support for PCI-bus USB controllers (CONFIG_USB_OHCI_HCD_PCI=y)
        |...<*>  Generic OHCI driver for a platform device (CONFIG_USB_OHCI_HCD_PLATFORM=y)
        |...<*> UHCI HCD (most Intel and VIA) support (CONFIG_USB_UHCI_HCD=y)
        |...<*> USB Mass Storage support (CONFIG_USB_STORAGE=y)

NOTE: The HCD port drivers usually are EHCI for high-speed USB plus either OHCI or UHCI for a fallback to legacy USB.
b. SCSI device support (CONFIG_SCSI) also should be built in (required by USB support)...
Code:

...    SCSI device support --->
        |
        |...-*- SCSI device support (CONFIG_SCSI=y)
        |...<*> SCSI disk support (CONFIG_BLK_DEV_SD=y)
        |...<*> SCSI CDROM support (CONFIG_BLK_DEV_SR=y)
        |...<*> SCSI generic support (CONFIG_CHR_DEV_SG=y)

c. Initial RAM filesystem and RAM disk support...
Code:

....General setup --->
    |
    |...[*]Initial RAM filesystem and RAM disk (initramfs/initrd) support (CONFIG_BLK_DEV_INITRD=y)

...Device Drivers --->
    |
    |...[*] Block devices ---> (CONFIG_BLK_DEV=y)
              |
              |...<*> RAM block device support (CONFIG_BLK_DEV_RAM=y)
              |...(16)  Default number of RAM disks (CONFIG_BLK_DEV_RAM_COUNT=<integer>)
              |...(4096) Default RAM disk size (kbytes) (CONFIG_BLK_DEV_RAM_SIZE=<integer>)

2. Use UUIDs or LABELs for partitions instead of device names which may not be consistent (as you found out).
NOTE: See the swaplabel command for finding or changing a swap partition’s UUID. If swaplabel or Gparted fail work for setting a label or UUID for the swap partition, then use mkswap to recreate the swap area with the -L option to set a label which also will assign a UUID to the new swap partition.
3. Boot the system in the usual way with GRUB 2 but add the kernel parameter rootdelay=5 to avoid a kernel panic caused by the slower response of the USB drive.

4. To boot the USB system directly from the BIOS splashscreen menu (instead of from another system's GRUB), install GRUB in the master boot record of the USB drive in the usual way with grub-install. Edit the USB system’s grub.cfg file for the root filesystem and to add the rootdelay kernel parameter. To boot with UUID or LABEL (a good idea with a hot-plugable USB drive), see the BLFS book chapter on initial RAM filesystems, creating the initrd image file, and editing grub.cfg for the initrd command line. Also replace the typical set root command line with a search command line that uses UUID. My current example...
Code:

# Begin /boot/grub/grub.cfg

set default=0
set timeout=5

menuentry “Linux From Scratch” {
insmod search_fs_uuid
search --no-floppy --fs-uuid --set=root 98790171-5ab5-45c6-9764-096c056918cf
linux /boot/vmlinuz root=UUID=98790171-5ab5-45c6-9764-096c056918cf ro rootfstype=ext4 rootdelay=5
initrd /boot/initrd.img
}

# End /boot/grub/grub.cfg

This stuff is from my notes. The actual locations and/or wording of the kernel config stuff may have changed some, but the idea is still valid.

skender1234 02-23-2016 03:59 PM

Thanks for the fast reply, I will try that.

TxLonghorn 02-23-2016 05:01 PM

Quote:

set root=(hd0,2) // what should I set here?
I have gotten better results with "set root=(hd0,msdos2)"

Quote:

menuentry "GNU/Linux, Linux 4.2-lfs-7.8" {
linux /boot/vmlinuz-4.2-lfs-7.8 root=/dev/sda2 ro //and here for sda2
Here you can change "root=/dev/sda2" to "root=UUID=a2cd308e-2307-4bb4-8382-b54b792b8a79"
(edit for the correct UUID number.)

skender1234 02-23-2016 08:53 PM

I have not looked into BLFS so far but the "rootfstype=ext4 rootdelay=5" seems to resolve my issue right now. I am still stuck with /dev paths at the moment but it is finally booting. Thanks all. This can be closed/marked solved.

stoat 02-24-2016 04:50 PM

Quote:

Originally Posted by skender1234

I have not looked into BLFS so far but the "rootfstype=ext4 rootdelay=5" seems to resolve my issue right now.

Well, okay. But those two don't do anything about the original issue of unpredictable USB drive enumeration. Your system would boot normally without rootfstype=ext4, but having it shaves a second off of booting by the kernel not having to figure out the filesystem. The rootdelay=5 parameter really is important to boot a system on a USB drive. Different values for it can be used or may be necessary. I started with 10 and settled on 5 without trying to push it farther.

Anyway, if you ever want to boot the USB system with UUIDs or LABELs to avoid the drive enumeration issue, just read the BLFS section "About initramfs". It's easy to create an initial ram filesystem following those instructions. You have to install cpio (easy, no dependencies). Then install the two scripts found there and run the mkinitramfs command as described. I have a BLFS system on a USB drive that boots directly from BIOS, often with other USB drives also running. So I need this UUID business to boot it.


All times are GMT -5. The time now is 06:01 AM.