Boot FreeBSD ISO from Grub2 USB stick

I have a USB stick with a grub2 bootloader installed. Great tool when you want boot an iso without burning CD's.

I now want to boot the FreeBSD installer from the stick and have disc1.iso on an ext2 partition of the stick. I chose to use disc1.iso because I figured FreeBSD memstick.iso would install the FreeBSD bootloader on the stick and remove grub2. My menu entry in grub.cfg is:
Code:
insmod loopback
insmod iso9660
insmod ufs2
insmod zfs
search --no-floppy --fs-uuid --015e657c-etc..
menuentry "FreeBSD 8.1 iso" {
	set isofile="/boot/FreeBSD-8.1-RELEASE-amd64-disc1.iso"
	loopback loop (hd0,1)$isofile
	freebsd  (loop)/boot/kernel/kernel
	freebsd_loadenv  (loop)/boot/device.hints
	set FreeBSD.vfs.root.mountfrom=cd9660:/dev/ad1s1
	set FreeBSD.vfs.root.mountfrom.options=rw
}
Boot process moves along fine until it gets to mounting root (/). Here it drops to the [CMD=""]mountroot>[/CMD] prompt where "? = list valid disk boot devices". In my menu entry I have also tried to change
[CMD=""]set FreeBSD.vfs.root.mountfrom=cd9660:/dev/ad1s1[/CMD]
to
[CMD=""]set FreeBSD.vfs.root.mountfrom=ufs:/dev/ad1s1[/CMD]
with no result (obviously). The ? option at the command line does list available slices on the USB stick!

Question is: Given that grub has completed its job and passed command the FreeBSD bootloader, what would be the correct menu entry for successful boot to the setup menu? Of course, I may also be missing a line in grub like ramdisk= or such...

Unrelated but for the record, grub did not recognize the kfreebsd command but worked alright with the freebsd command. Whereas when booting from my already working hdd, the command grub is using is kfreebsd.
 
Does grub's loopback mount create a device that can even be seen by the FreeBSD bootloader? If it does, what kind of device does it pretend to be: IDE hard disk (ad), IDE CD (acd), SCSI (da)?
 
I just realized that the loopback command which grub uses probably does not get passed to the FreeBSD loader. The [CMD=""]mountroot> ?[/CMD] option lists (stick has 2 partns):
Code:
msdosfs/kng32, ext2fs/kng1, ad1s2, ad1s1, ad2
where kng32 and kng1 are the linux labels for the partns. Curiously, it does not list any partns of the hdd => loopback command is limiting the drives available to Geom? But under loopback the root fs is not [Cfile]something:/dev/ad1s1[/file], its ---/ads1/boot/FreeBSD-8.1-RELEASE-amd64-disc1.iso so I conclude that I need to pass this info to the fBSD bootloader somehow.
 
Unless grub is creating an emulated device in RAM, it seems unlikely to work. Something would have to remain to handle reading the ext2 filesystem underneath the CD image. And all of that goes away when the FreeBSD loader takes over, unless grub has created something that sticks around. The FreeBSD loader should be able to see the USB stick as da0, but then it would have to be able to understand ext2, and then mdconfig(8) and mount the CD image.

syslinux can copy CD images to RAM and make them bootable, but of course it eats RAM. It wasn't successful when I first tried it, but might be better now.
 
I have thought about your comments and I disagree. I think loopback creates an iso9660 fs in memory. Without that, the FreeBSD installer would not start at all - the FreeBSD installer starts because it thinks its on a cd (iso9660 fs) - and that is what sticks around. If my premise is correct, ext2 fs is irrelevant.
 
Looks like you're right. loopback in grub2 creates a RAM-backed "drive".

When you say the installer starts, you mean the loader, right? If sysinstall runs, then the filesystem is being read.
 
Yes, I do mean the loader. Load process stops at
Code:
ROOT MOUNT ERROR:
If you have invalid mount options, reboot, and first try the following from the loader prompt:
     set vfs.root.mountfrom.options=rw
and then remove invalid mount options from /etc/fstab.
some other stuff and at the end and waits at
[CMD=""]mountroot>[/CMD]
Like I stated, ? curiously lists only the partitions on the stick and none of the hdd slices...
 
This thread is marked [Solved] but I don't see any successful reports of booting a FreeBSD iso image file from grub2. Am I missing something?

I would love to show more people FreeBSD. It would be useful if the kernel was able to do the right thing when booted from a Grub2 USB stick that contains other files.
 
@ grantbow:
Threads a lot of times get marked "solved" just for having been on the forum for a while. "Solved" also, in a sense means closed regardless whether a solution exists or not.

Re your question about booting from usb, FreeBSD is bootable from a usb and there are many howto's about that (one such exhaustive sample here). My post, as you know, was about getting it to work with the iso file intact, which saves space on the usb and additionally, switching the menu for other iso's in grub is very easy. Currently no solution to this (that I have found) and I suspect the issue has to do with grub's loopback compatibility with FreeBSD's memory device handling.

Hope this helps!
 
Hello @Beeblebrox, thanks for your reply and the link. You and @wblock seem to have narrowed down many of the unknowns. As USB sticks get larger and larger the requirement to use a whole stick for an OS seems more and more wasteful to me. Grub2's feature is one seemingly attractive way around this limitation.

Is there currently no way for the FreeBSD kernel with an appropriate parameter to recognize the "RAM-backed drive" created by grub2 & mount this as it's root volume? What missing functionality seems to be required?
 
Recently, I found that syslinux could PXE boot a FreeBSD install CD. Maybe there's an equivalent for grub2? Or use syslinux instead of grub2.
Code:
label freebsd-install
  menu label FreeBSD Install
  kernel memdisk
  initrd tftp://192.168.1.1/images/freebsd-install/bootonly.iso
  append iso raw

For syslinux, just changing the initrd to have a path to the ISO image should be enough. (Untested.)
Code:
label freebsd-install
  menu label FreeBSD Install
  kernel memdisk
  initrd bootonly.iso
  append iso raw
 
What I meant by:
I suspect the issue has to do with grub's loopback compatibility with FreeBSD's memory device handling.
is that FreeBSD does not use loopback, it is essentially a linux command. The comparable process in FreeBSD, if you wanted to mount an iso would be:
[CMD=""]1. mdconfig -a -t vnode -f /path/to-image.iso -u 1[/CMD]
[CMD=""]2. mount -t cd9660 /dev/md0 /mountpoint[/CMD]

Granted, grub already has mounted the iso as a memory device, hence no need for mdconfig etc. However, I just wonder whether FreeBSD recognizes the loopback'ed device in the manner necessary to continue with the boot process, and whether there is a mis-communication because of how the memory devices are specified/handled?
 
I tried to do the same as Beeblebrox. Got the same problem. The boot process stops with a rootmount prompt. I have absolutely no idea how Grub2 works and what's behind it. So it would be nice if someone could post a working grub2 FreeBSD entry to boot from usb.
 
@wblock:
I think (and I am just speculating here) the key to your post is the type of iso being used: bootonly.iso as opposed to a regular kernel / iso. Again speculation, the bootonly is somehow different than the "regular" iso
 
Beeblebrox said:
@wblock:
I think (and I am just speculating here) the key to your post is the type of iso being used: bootonly.iso as opposed to a regular kernel / iso. Again speculation, the bootonly is somehow different than the "regular" iso

A bootonly ISO boots the same as a "disc1" ISO, it just doesn't have all the install distributions on it. Many of the systems I use don't have even 512M of RAM, so there's not enough to store a 653M disc1 image. bootonly.iso is only 47M.

Just tested, and a full disc1 install CD also boots fine, provided the target system has enough RAM to hold it with some left over to run.
 
install FreeBSD ISO from grub via USB

To install FreeBSD from grub or grub2, add the following to grub.cfg:
Code:
###  BEGIN of grub.cfg ###
# Boot automatically after 30 secs.
set timeout=30

# By default, boot the first entry.
set default=0

menuentry "1 FreeBSD 8.2 i386 boot only" {
 	set isofile=/FreeBSD-8.2-RELEASE-i386-bootonly.iso
	loopback loop $isofile
	kfreebsd (loop)/boot/kernel/kernel iso-scan/filename=$isofile noeject noprompt splash --
	kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}

menuentry "2 FreeBSD 8.2 amd64 boot only" {
 	set isofile=/FreeBSD-8.2-RELEASE-amd64-bootonly.iso
	loopback loop $isofile
	kfreebsd (loop)/boot/kernel/kernel boot=casper iso-scan/filename=$isofile noeject noprompt splash --
	kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}
###  END of grub.cfg ###
 
I wonder if it's possible to put FreeBSD into a separate partition on the USB stick, install the FreeBSD bootloader on that partition, then use chainloader +1 option in /etc/grub.d/40_custom before running update-grub, all right on the USB stick. The USB stick would have to be rather big but maybe it will work?

Thanks.
 
jola said:
To install FreeBSD from grub or grub2, add the following to grub.cfg:
Code:
###  BEGIN of grub.cfg ###
# Boot automatically after 30 secs.
set timeout=30

# By default, boot the first entry.
set default=0

menuentry "1 FreeBSD 8.2 i386 boot only" {
 	set isofile=/FreeBSD-8.2-RELEASE-i386-bootonly.iso
	loopback loop $isofile
	kfreebsd (loop)/boot/kernel/kernel iso-scan/filename=$isofile noeject noprompt splash --
	kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}
###  END of grub.cfg ###

It looks like you've copy/pasted the required Ubuntu parameters. Have you tested? Does this work? Obviously "boot=casper" and "iso-scan/filename" have no meaning as BSD kernel arguments. Actually, I think "noeject", "noprompt", and "splash" are also meaningless for FreeBSD. You should be able to leave off everything after "kernel". Also, this won't work on Grub, only Grub2... Grub has a different format and doesn't support loopback.

There seems to be a lot of confusion in this thread about what Grub2 is doing. It's not magic. It's not creating a device that either Linux or FreeBSD kernels can see. It can't. It is opening the iso file you provide it and allowing grub2 (and only grub2) to access files inside of it. The only purpose of loopback on grub2 is to allow one to extract the kernel and init image (initrd or freebsd_module). After that, it is entirely up to the booted kernel and init scripts to find the ISO if necessary and continue booting. Once the kernel has taken over, the loopback "device" created by grub vanishes. It doesn't matter if you're booting Linux, FreeBSD, or Windows, the ISO you're booting is not able to see anything grub did and needs to support this method of booting.

For many small ISOs (TinyCore Linux, and I suspect the FreeBSD netinstaller), everything of value exists in the Kernel and Init image. For bigger live CDs, such as Ubuntu, the Init scripts need to support this method of booting. The way it works on Ubuntu is the init script (casper on Ubuntu... they like naming things goofy) recognizes the iso-scan/filename parameter. If that parameter is non-empty, casper mounts every partition on the system one after another until it finds the ISO. Then it mounts the ISO as a loopback device and continues as if that loopback device were the CD-ROM.

Only if FreeBSDs init scripts included the ability to parse a kernel parameter such as Ubuntu's poorly named "iso-scan/filename" could we boot a full image. But it sounds like the bootonly.iso works, so there you go...
 
All the excitement aside, jola's proposed solution does not work. Tried and Tired, so did not respond.

The main problem with iso boots (and grub does a great job of it) is the mount root stage of the process. So you can get the loop working, you can get kernel and init to boot, but it hits its head against a wall at the mount root from stage.

Each group of distro (debian/rhl/etc) has different mount root options and this info is not easily found on the intertubes. xBSD releases are no exception, mainly for the reason that they do not use grub as the main bootloader.

Another, but related problem, is that you may manage to boot from the iso but not manage to install it on your drive. The error in this case is usually a message that the filesystem or some package did not like the setup. These errors are really a result of incorrect mount options for root in the grub.cfg line.

RESULT: How do you mount root from loopback as posted in #1 post:
Boot process moves along fine until it gets to mounting root (/). Here it drops to the mountroot>
Any result which claims success without being able to fully install the iso is null and void. For clues, I have studied mfsbsd's boot options without result as how-to's are not for the iso but for the un-compressed format.
 
You need to use the Boot Only FreeBSD ISO

Beeblebrox said:
The main problem with iso boots (and grub does a great job of it) is the mount root stage of the process. So you can get the loop working, you can get kernel and init to boot, but it hits its head against a wall at the mount root from stage.

Please see my explanation. The FreeBSD CDs do not recognize the iso-scan/filename kernel parameter (as a FreeBSD n00b, I don't even know if FreeBSD accepts kernel parameters in that syntax). However, after posting my explanation, I did try Jola's method using the modifications I proposed (because FreeBSD is not Ubuntu).

If your CD is failing to mount root, then you are not using the Boot Only CD. The Boot Only CD does not contain any packages on the CD-Rom itself; everything is in the mfsroot.gz, which gets extracted into ram.

The proper configuration, which I am using without problems, is:

Code:
menuentry "FreeBSD 8.2 i386 boot only" {
  set isofile=/boot/isos/FreeBSD-8.2-RELEASE-i386-bootonly.iso
  loopback loop $isofile
  kfreebsd (loop)/boot/kernel/kernel
  kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}

menuentry "FreeBSD 8.2 amd64 boot only" {
  set isofile=/boot/isos/FreeBSD-8.2-RELEASE-amd64-bootonly.iso
  loopback loop $isofile
  kfreebsd (loop)/boot/kernel/kernel
  kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
}

Again, you cannot use any install ISO other than boot only, as FreeBSD's mfs_root does not contain init scripts with the ability to find and mount an ISO. I've explained how the process works for Ubuntu (RedHat, etc are the same) and why it doesn't work for the normal FreeBSD CDs (and Damn Small Linux and many other distros) up above. You need to the boot only ISO and you can't give FreeBSD any instructions to mount any part of the ISO as the root partition.

I just completed an i386 install of FreeBSD using this method. It works, but only as described.
 
The funny thing is, I have booted ISO files off USB for the likes of DSL and Pentoo before. Unfortunately I lost my notes when moving, so no help on that issue fromme at the moment. Whether the booted ISO is able to do an install or correctly run the installation script/program is another issue and the reason why I started the thread (but your comment on the problem are certainly welcome).
Re the same problem for FreeBSD, I do think it is possible to boot the liveCD as ISO, and as you stated, sysinstall will probably have problems (exact similar issue recently with Backtrack-5).
To explain my explanation, what I meant by:
FreeBSD's memory device handling
Is that (as I understand it) FreeBSD needs the extra step of mdconfig to create a loopback thingy (whatever you want to call it at this point is fine by me) wile linux does not seem to need that step.
 
Beeblebrox said:
Is that (as I understand it) FreeBSD needs the extra step of mdconfig to create a loopback thingy (whatever you want to call it at this point is fine by me) wile linux does not seem to need that step.

I'm sure that's true. If you use the bootonly ISO, it doesn't matter, though, because the ISO is never mounted as a loopback device by FreeBSD (or grub, for that matter). "loopback" in grub is more like unzipping a specific file from a tar.gz than actually mounting an ISO as a loopback device, and it disappears as soon as the kernel loads. The 'bootonly' ISO has nothing of value on the ISO filesystem, however, and downloads everything it needs from the internet.

I'm not familiar with Pentoo, but DSL certainly might have added support for Grub2 ISO style booting since I last attempted, either by shoving everything into the init ram image (ala FreeBSD boot only, the 20MB Ubuntu Mini ISOs, etc ) or by making the init scripts on the init ram image support searching and mounting the ISO. I guess this is off topic.

It really doesn't matter at all what method the OS kernel uses to mount ISOs as loopback devices. There's 0 communication between Grub2 and the OS kernel about the loopback "device" that Grub2 creates; that vanishes as soon as the kernel starts executing (whether it's Linux or FreeBSD). All you can do is pass a "kernel parameter" (which on Linux shows up in /proc/cmdline; not sure what FreeBSD does) and needs to be specifically detected by the init scripts.

If you want to boot the FreeBSD 'Disk1', 'DVD1', or 'LiveFS' ISO files, the init scripts on the 'mfsroot.gz' will need to be edited. If you want to boot the 'bootonly' ISO, you already can; I finished an AMD64 install with this method this morning, so now I know install works on both architectures in this way.

Have you had issues with the 'bootonly' ISO image? Or do you really need one of the other ISOs for some reason?
 
[Solved] boot FreeBSD iso from grub2 USB stick

I understand this was marked solved but I hope you guys get this, you started me in the right direction, I am interested in BSD, currently I am Linux Debian. I wanted to check out the Debian BSD distro but it wouldnt install from a USB DVD Rom. I tried all of the Debian solutions with USB's etc and failed then I searched for booting from grub info as that was also one of the debian solutions more or less. I ran across your posts and it gave me sone information I was lacking. I modified your examples a little and came up with a working solution.
Code:
menuentry "Debian BSD 1" {
	echo "Loading ..."
	set isofile=(hd0,7)/debian-6.0.3-kfreebsd-amd64-CD-1.iso
	loopback loop $isofile 
	set root=(loop)
	kfreebsd (loop)/boot/kernel/kfreebsd.gz
	kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
	set kFreeBSD.vfs.root.mountfrom=ufs:/dev/md0
}
In the last examples the one thing I noticed was that the /boot reference had no "machine style reference" to anchor the process, this is really all I changed was adding the reference to loop for the paths and loop was based on a hard machine reference that is universal to the OS continuum. This allowed the installation to happen. As seen I put the ISO in a root directory of a hard drive (ext4 fs by the way) and loaded it from there with the grub hard drive reference.

Hope one of you finds this!

And thanks for the needed direction.

--jerry
 
@jk*:
I must say good job! I'll have to try it myself as well. The
Code:
mountfrom=ufs:/dev/md0
was exactly what I had in mind as a concept but could not describe. No need to fret about whether it was seen, the discussion was on-going (look at the posted dates)
 
Hi and thanks happy you found it, The
Code:
mountfrom=ufs:/dev/md0
actually came from the grub.cfg on the dvd, I took info from you guys and what was in there and added the two together, along with the machine reference to anchor the filesystem.

--jerry
 
Back
Top