LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux From Scratch (https://www.linuxquestions.org/questions/linux-from-scratch-13/)
-   -   Booting LFS from USB stick ? (https://www.linuxquestions.org/questions/linux-from-scratch-13/booting-lfs-from-usb-stick-897465/)

mbzadegan 08-15-2011 02:49 PM

Booting LFS from USB stick ?
 
Hi everybody,
How can boot LFS from usb stick ? in other words i bootabled my usb stick with syslinux and i want to boot LFS from my USB stick ...

kostya 08-16-2011 08:06 AM

Do you mean to boot ALL your LFS installation from a USB stick?

Or do you want to use the USB stick to boot the kernel and then use your LFS which is installed on your HDD?

mbzadegan 08-16-2011 12:34 PM

Dear kostya ,
I have not any HDD and i want to boot from my USB Stick ,
At first i bootabled my usb stick with syslinux and then copy all of LFS_LiveCD files to it ,
I configured syslinux.cfg with :

label linux
kernel linux root=UUID=07E6-1968 init=/sbin/init
append initrd=initramfs_data.cpio.gz

BUT when i booted from it these message was notified !

LFS LiveCD could not find its device.
Dropping you to a shell.
Please load the needed modules and, optionally, make /dev/lfs-cd a symlink pointing to the correct device.

sh: no job control in this shell
sh-3.2#

hoes 08-16-2011 02:18 PM

I've made a bootable USB stick with LFS on it.
I used grub and installed it to the boot sector of the USB stick.
The most important part was however the initial ramdisk.

The key to the success was having the ramdisk run a script to find the root system.
It kept mounint every system until it found the LFS root and changed to this.

I reckon that the shell you get is part of the initial ramdisk.
That means that you have initial ramdisk support and could make a ramdiks to find the root.

I hope you find this quick reply a helpfull start.
Maybe there are better methods (although I saw a similar method on a KNOPPIX CD).
However, if you have some more question, feel free to ask.

mbzadegan 08-16-2011 02:40 PM

Ok , That's right .
It seems that i must definite root.ext2 to the root append of kernel .
How i can do it with syslinux ?

hoes 08-16-2011 04:03 PM

I doubt whether that really is the problem.
I wouldn't mind having a look at the initrd and come up with something.

Can you give a link to the LFS bootable CD website?

mbzadegan 08-16-2011 08:01 PM

ftp://ftp.osuosl.org/pub/lfs-livecd/...-r2145-min.iso

Hint , When i put a LFS-LivCD on my cdrom the booting of USB Stick was TRUE , This means that LFS search for root.ext2 on CD-ROM , We must point it to USB Stick .

kostya 08-17-2011 07:32 AM

The advantage of GRUB2 is that it can actually boot from ISO image. I've done that with a number of images of different LiveCD distros, all of them on one USB stick. I'll try now with LFS one and report back :).

BTW,This HOWTO gives general steps to follow.

mbzadegan 08-17-2011 07:49 AM

Tnx Dear kostya ,

Also , memdisk ( syslinux compatible ) can do it with iso images BUT unfortunately booting directly from iso image (with grub or memdisk) needs more memory .


I don't know how i can mount /dev/hda1 as /dev/lfs-cd on kernel appending ...
If we customize init file and force kernel to append USB stick , Booting will complete .

kostya 08-17-2011 08:46 AM

Didn't work the way I tried it :).

OK, but there's a README on the LiveCD itself.
It says these interesting things:
Quote:

BOOTING FROM ISO IMAGE

If you want to boot this CD on a computer without a CD-ROM drive, follow the steps below.

Store the ISO image of this CD as a file on a partition formatted with one of the following filesystems: vfat, ntfs, ext2, ext3, ext4, jfs, reiserfs, reiser4, xfs

Copy the boot/isolinux/{linux,initramfs_data.cpio.gz} files from the CD to your hard disk

Configure the boot loader to load “linux” as a kernel image and “initramfs_data.cpio.gz” as an initrd. The following parameters have to be passed to the kernel:

rw root=iso:/dev/XXX:/path/to/lfslivecd.iso rootfstype=fs_type

where /dev/XXX is a partition where you stored the LiveCD image, and fs_type is the type of the filesystem on that partition. You may also want to add “rootflags=…” option if mounting this partition requires special flags.

If there is only Windows on the target computer, please use grub4dos as a boot loader. It is available from http://sourceforge.net/projects/grub4dos.
MAKING A BOOTABLE USB DRIVE

Install GRUB on a flash drive, then follow instructions in the “BOOTING FROM ISO IMAGE” above, using a partition on your flash drive. The following tips will ensure that the flash drive is bootable in any computer:

Use the persistent symlink such as “/dev/disk/by-uuid/890C-F46A” to identify the target partition.

Add “rootdelay=20” to the kernel arguments.
from which I derive that we must try, when booting from a USB stick, to supply this argument to our kernel line:
Code:

linux /boot/isolinux/linux rw root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso rootfstype=vfat rootdelay=20
I'll try now and report ;).

kostya 08-17-2011 09:14 AM

Well, it is the worst case possible:
it doesn't work the way the README suggests! In fact, the kernel (linux) doesn't understand not only such complicated command line as
Quote:

root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso
It doesn't even understand the most common command like
Quote:

root=UUID=0451-5cdc
and says it cannot mount any such device.

So I don't know where to move further, only maybe email the developers of the LiveCD and ask them this very question.
Sorry :(.

kostya 08-17-2011 09:52 AM

OK, I managed to boot it this way(part of grub2 config:
Quote:

set root=(hd0,1)
linux /linux64
initrd /initramfs_data64_cpio.gz
append rw root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso rootfstype=vfat rootdelay=20
This way it boots up to the message form init that it can't find its LiveCD and therefore drops me to the shell. Which is strange, because at this stage all the needed devices are here and lfslivecd.iso absolutely available to use as root filesystem. Perhaps some more fine tuning of this process will bring some satisfaction?
We just CAN'T stop at this point where we are almost there ;).

mbzadegan 08-17-2011 11:03 AM

Tnx , very good hints ,

I passed that state with root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso but i hanged on another state :

My New Error :

/init: line 172: mknod: Command not found
mount: special device /dev/root does not exist
Kernel panic - not syncing: Attempted to kill init!


My syslinux.cfg :

label linux
root (hd0,1)
kernel linux
append initrd=initramfs_data.cpio.gz rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20

Another Thanks for your very good hints .

hoes 08-17-2011 11:54 AM

I had a quick galnce at the init file, that creates your error.

It is strange that mknod is ran.
You specified an iso file using "iso:*", which should do the trick.
BTW, are you sure taht initrd should be on the append line as well?
Could you perhaps try this: (that's grublike structure)

root (hd0,1)
initrd initramfs_data.cpio.gz
kernel linux
append rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20


The stupid thing is that mknod is not included in the image.
However, normally this shouldn't bother you, because iso mounting doesn't need it.
But that's just a sidenote.

mbzadegan 08-17-2011 12:48 PM

Unfortunately , it was same error .

kostya 08-17-2011 01:19 PM

Hey, I finally GOT it boot.

Though I was booting from GRUB2 shell, supplying it all line by line as follows:
Quote:

set root='(hd0,1)'
linux /linux64 rw root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso rootfstype=vfat rootdelay=20
initrd /initramfs_data64.cpio.gz
boot
It must be some bugs in this relatively new GRUB2 that it can't boot THE SAME from config file. But this way it does boot it.

So the order, it seems, must be this: kernel, then initrd, and not the other way around.
Just maybe try to supply the bold part right after "linux" and not after "append". Perhaps it will work this way?

Cause normally initrd is the very last thing to supply, so it ignores the rest of the line.
Well try this way, perhaps.

kostya 08-17-2011 01:29 PM

Quote:

Originally Posted by mbzadegan (Post 4445681)
Tnx , very good hints ,

I passed that state with root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso but i hanged on another state :

My New Error :

/init: line 172: mknod: Command not found
mount: special device /dev/root does not exist
Kernel panic - not syncing: Attempted to kill init!


My syslinux.cfg :

label linux
root (hd0,1)
kernel linux
append initrd=initramfs_data.cpio.gz rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20

Another Thanks for your very good hints .

Another option is, perhaps, place the "initrd=..." part in the very end of your "append" command line. That will make sure that the rest of it will be passed to the kernel:
Quote:

append rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso initrd=initramfs_data.cpio.gz
Another interesting bit of information is found HERE and it says:
Quote:

Starting with version 3.71, an initrd can be specified in a separate statement (INITRD) instead of as part of the APPEND statement. This functionally appends "initrd=initrd_file" to the kernel command line.
Which means your configuration can be now like this:
Quote:

kernel ...
initrd ...
append ...(here goes this long kernel argument line about root=iso etc.)

hoes 08-17-2011 01:34 PM

I guess grub just doesn't know the append and the options need to be added to the kernel line.

mbzadegan 08-17-2011 01:54 PM

With changing of post #16 i got same error (post #3)
Therefore i got best result on post #13 config but unfortunately with kernel panic

kostya 08-17-2011 01:58 PM

Quote:

Originally Posted by hoes (Post 4445832)
I guess grub just doesn't know the append and the options need to be added to the kernel line.

Right, the "append" command is no more used there. On the other hand, kernel options to be passed to the kernel are just passed on to it on the same line, just as it always used to be.

What bothers me is that, when it loads from the configuration file, it doesn't even load the initrd, as I can see from the boot message, which ends up in kernel panic, prior to which it says that it "can't mount the device "/dev/disk/by-uuid/...etc." Well if initrd WAS loaded it WOULD find the device with no problem.

And WTH, it DOES boot it all when I exit the menu and supply it all from the command prompt! Perhaps, I should email to the GRUB2 developers about this issue?

kostya 08-17-2011 01:59 PM

Quote:

Originally Posted by mbzadegan (Post 4445849)
With changing of post #16 i got same error (post #3)
Therefore i got best result on post #13 config but unfortunately with kernel panic

How about my last suggestion from post #17?

mbzadegan 08-17-2011 02:50 PM

Dear kostya,
i got same kernel panic with your last suggestion #17 .
I think that i must correct translate of set root='(hd0,1)' into syslinux commands .
because at the start of booting process i got the error of missing root parameters !! ( before kernel loading )

kostya 08-18-2011 12:05 AM

Quote:

Originally Posted by mbzadegan (Post 4445906)
Dear kostya,
i got same kernel panic with your last suggestion #17 .
I think that i must correct translate of set root='(hd0,1)' into syslinux commands .
because at the start of booting process i got the error of missing root parameters !! ( before kernel loading )

Right!
In syslinux syntax it must be, using the new syntax, like this I think:
Code:

root (hd0,0)
kernel /path/to/linux
initrd /path/to/initramfs...gz
append rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20

Because in GRUB2 the partition number in (hd0,1) starts from 1, but in other older bootloaders it starts from "0"! So the 1st partition on the first device will be, not (hd0,1) but (hd0,0) I guess.
Worth trying anyway :).

PS. And reading the documentation is always a good idea ;). Not the whole thing, maybe, but some relevant parts at least.

mbzadegan 08-18-2011 01:37 AM

My syslinux sintax is :

label linux
root (hd0,0)
kernel linux
initrd initramfs_data.cpio.gz
append rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20

And when start boot processes ( before kernel loading ) got me these ERROR :(

unknown keyword in configuration file: root
boot:
Loading linux....
Loading initramfs_data.cpio.gz....................ready
...
...
...
/init: line 172: mknod: command not found
mount: special device /dev/root does not exist
/init: line 293: ./lib/ld-linux.so.2: No such file or directory
/init: line 294: /.root/../lib/ld-linux.so.2: No such file or directory
/init: line 294: exec: /.root/../lib/ld-linux.so.2: No such file or directory

Kernel panic - not syncing: Attempted to kill init!

kostya 08-18-2011 02:45 AM

Right, syslinux doesn't support "root" argument at all...

Very strange, though! From the boot message it is clear that initrd IS loaded because init is running and it is inside initrd. And yet it can't find the ld-linux.so.2, which must be there inside initrd, too.

Which makes us think that either initrd or kernel is defective. We could, of course, suggest that the computer has not enough RAM, which results in losing data, but that's hardly possible in a computer which can boot from a USB stick...
So, what is the md5sum of your initrd and kernel? I will compare with mine then.
This will compare the original initrd with what is on your USB stick
Quote:

diff /path/to/initrd USBSTICK/initrd
And this will calculate the checksum:
Quote:

md5sum initrd
I must also ask, when you're done with initrd, to try this simple config if you haven't done that already:
Code:

label linux
kernel linux
append rw root=iso:/dev/disk/by-uuid/07E6-1968:/lfslivecd.iso rootfstype=vfat rootdelay=20 initrd=initramfs_data.cpio.gz

I'm asking this again, because I tried it in all various combinations with slightest differences before I got it to boot. So I believe every letter may be essential seeing how tricky it is to boot from USB stick. And it will be a pity to drop it when we are so close!

mbzadegan 08-18-2011 09:16 AM

@ first i tested MD5 of every files with original and never seen any different .
Then i tested your simple config and got same kernel panic !!:(
meanwhile,i tested these menu.lst with GRUB and got same kernel panic error !!

title LFS_USB_Booting
set root='(hd0,1)'
kernel /linux rw root=iso:/dev/disk/by-uuid/6E17-68F1:/lfslivecd.iso rootfstype=vfat rootdelay=20
initrd /initramfs_data.cpio.gz
boot


which of your grub config you tested OK ?
Tnx for your hints ...

kostya 08-18-2011 03:49 PM

Which version of GRUB are you using?
I'm using GRUB 1.99 (GRUB2) and the syntax "set root='(hd0,1)'" is for GRUB2. For GRUB it would be "root (hd0,0)".
And in GRUB2 instead of keyword "kernel" it uses "linux" and curly brackets are used for each menu entry.

OK, first here are my md5sums so you can compare what md5sums you got:
Quote:

ae824b594c48bff53399082fea093acd linux
07ddbe3e7d480eef416b17e93659a140 initramfs_data.cpio.gz
b44537e4b5ceb72601cdb4dc7e820828 lfslivecd-x86-6.3-r2145-min.iso
Now here is my GRUB2 config part for LFS LiveCD:
Quote:

menuentry "LFS" {
set root='(hd0,1)'
linux /linux64 rw root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso rootfstype=vfat rootdelay=20
initrd /initramfs_data64_cpio.gz
}
As you can see, this GRUB2 syntax is different from GRUB legacy, for which it must be thus:
Quote:

root (hd0,0)
kernel /linux64 rw root=iso:/dev/disk/by-uuid/0451-5CDC:/lfslivecd.iso rootfstype=vfat rootdelay=20
initrd /initramfs_data64_cpio.gz
(notice that you need not the word "boot" in config, you only need it on command line prompt as described below).

And the last but not the least. It is advisable to escape from the GRUB menu to GRUB prompt and supply these argument line by line. It is better for if device (hd0,0) is wrong, it will tell you so and you'll be able to supply the correct device. Print HELP and it will give you the list of commands. In GRUB 2 the command `ls` shows you all available drives.
You then supply each line (root, kernel, initrd) from your config followed by <Enter>, after the last line followed by <Enter> you type "boot" and press <Enter>.
This was the only way I got it to boot correctly for GRUB2 would only receive full kernel command line from prompt. From config it doesn't seem to notice it or fails to load initrd, don't know why.

So after all these pains I'm a little bit surprised: WHY did you choose the LFS LiveCD at all??
I found it to be rather poor stuff for a live cd, it couldn't even find a driver for my network card. There are other LiveCD distros offering far better functionality either as Desktop or as a rescue kit, and no problems booting them from USB.

mardon86 02-10-2012 03:36 AM

Im aiming to build LFS with LFS-LiveCD as host. But im using a netbook which doesnt have an optical drive. And ive found an easy way to boot LFS-LiveCD from a thumbdrive.
Im using gujin.

1. download and extract the gujin (install-2.8.4.tar.gz)
$wget http://sourceforge.net/projects/guji...ar.gz/download
$tar -xvzf install-2.8.4.tar.gz

2. copy install/gujin to /usr/bin
#cp ./install/gujin /usr/bin

3. install gujin to the iso file.
$gujin lfslivecd-x86-6.3-r2145-min.iso

4. cat the iso file to your thumbdrive
#cat lfslivecd-x86-6.3-r2145-min.iso > /dev/sdc
#sync

5. boot your thumbdrive

6. after the error is occured and the system is falling back to shell, make a symbolic link /dev/lfs-cd to /dev/sdc
#ln -s /dev/sdc /dev/lfs-cd
#exit

jiapei100 01-04-2013 03:49 AM

Hi:


I've got exactly the same difficulty in having a USB flash boot up.

I strictly followed LFS manual and have everything built from scratch on a USB flash. I thought if I could select the correct bootable device, I should be able to boot from that device directly. However, what I obtained is just the following picture:
http://visionopen.com/questions/lfs_...flash_boot.jpg

My configuration /boot/grub/grub.cfg on hd1 (I've got 4 hard drives hd0, hd1, hd2, hd3) of booting LFS is also pasted:
Quote:

menuentry "MyLinux distribution (on /dev/sdd1)" --class gnu-linux --class gnu --class os {
insmod gzio
insmod part_msdos
insmod ext2
set root='(hd3,msdos1)'
search --no-floppy --fs-uuid --set=root a2d0f92a-eca8-4121-a998-99c70d4df67b
echo 'Loading MyLinux ...'
linux /boot/vmlinuz-3.7.1-lfs-SVN-20130102 root=UUID=a2d0f92a-eca8-4121-a998-99c70d4df67b ro recovery nomodeset
echo 'Loading MyLinux ...'
}

1) By strictly following LFS manual, there is no initrd produced, but only vmlinuz .
2) from grub terminal, I can see my device has been correctly configured, say: /dev/sdd1 is just (hd3, msdos1), which is of UUID a2d0f92a-eca8-4121-a998-99c70d4df67b


I seriously have no idea how to make this USB flash (with LFS built) boot up. Please help.
Thank you very much.


Best Regards
Pei

spiky0011 01-04-2013 07:12 AM

Hi

Is this the grub.cfg from lfs or host

jiapei100 01-04-2013 07:43 AM

Hi, spiky0011:

This grub.cfg is from the host. In fact, I've got 4 hard drives:
Quote:

hd0 -- /dev/sda1 -- Windows7
hd1 -- /dev/sdb1 -- Ubuntu 12.04 -- where the grub is put
hd2 -- /dev/sdc1 -- external hard drive, not bootable
hd3 -- /dev/sdd1 -- My LFS
So, any further suggestions? One of my friend said my grub has already been successfully configured, it might have something to do with LFS building.

Quote:

Originally Posted by spiky0011 (Post 4862803)
Hi

Is this the grub.cfg from lfs or host


spiky0011 01-04-2013 07:52 AM

Are you trying to boot off of host grub

spiky0011 01-04-2013 11:16 AM

Hi

I would copy grub.cfg > grub.cfg-old

Then edit grub.cfg
remove "UUID=a2d0f92a-eca8-4121-a998-99c70d4df67b ro recovery nomodeset "

and put root=/dev/sddx root-delay=10 ro

x being the root partition


All times are GMT -5. The time now is 03:49 AM.