• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Boot FreeBSD ISO from Grub2 USB stick

Nukama

Active Member

Thanks: 43
Messages: 129

#26
It seems that the FreeBSD-9.0-RC2-${ARCH}-bootonly.iso isn't built with a boot/mfsroot.gz.

Without this there seems no way to boot FreeBSD-9 with grub2.
 

Beeblebrox

Aspiring Daemon

Thanks: 146
Messages: 985

#28
Bump. Any ideas on this issue?
Care to be more specific? What exactly is the part that's not working? Post #16 solves the issue by adding:
Code:
kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
Use an ISO version that has mfsroot.gz included. You are not limited to the bootonly.iso.
 

frijsdijk

Active Member

Thanks: 17
Messages: 246

#29
This indeed works for FreeBSD 8.x and earlier, however the layout of the 9.0 ISO images has changed significantly - the mentioned mfsroot.gz does not exist anymore.

For earlier editions I was actually using the following config for Grub4dos:

Code:
title FreeBSD 8.3 64-bit
find --set-root /FreeBSD-8.3-RELEASE-amd64-bootonly.iso
map /FreeBSD-8.3-RELEASE-amd64-bootonly.iso (hd32)
map --hook
root (hd32)
chainloader (hd32)
Which works charmfully for basic installations. On our USB sticks we actually have a wide variety of Unix images, which can be booted by either Grub2 or Grub4dos (which in turn is chainloaded from Grub2). In neither Grub2 or Grub4dos I have been successful in booting the FreeBSD 9.0 ISO up to the language selection menu for installations.
 

epopen

Active Member

Thanks: 5
Messages: 112

#30
Beeblebrox said:
Care to be more specific? What exactly is the part that's not working? Post #16 solves the issue by adding:
Code:
kfreebsd_module (loop)/boot/mfsroot.gz type=mfs_root
Use an ISO version that has mfsroot.gz included. You are not limited to the bootonly.iso.
Hi
The mfsroot.gz NOT included in FreeBSD-9.1-RELEASE-amd64-disc1.iso.
So can't boot by the method...:(
 

thermionix

New Member


Messages: 1

#32
Also trying this without success, any tips?

Code:
   kfreebsd (loop)/boot/kernel/kernel -v
   kfreebsd_loadenv (loop)/boot/device.hints
   kfreebsd_module (loop)/data/base.ufs.uzip type=mfs_root
   set kFreeBSD.vfs.root.mountfrom="ufs:/dev/md0"
   set kFreeBSD.xconsole=YES
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#33
How to boot FreeBSD 10.1 ISO from Grub2 USB stick? Anyone help?
Yes you can boot that or any other FreeBSD ISO from a Grub2 USB stick. The way I do it is have 2 partitions of the USB stick. The first one is ~1G large (for the ISO) and the second is for Grub2 boot/grub dir and ISO images that ARE bootable with Grub2 via loopback feature.

Now the 1st partition is used to write a FreeBSD*disc1.iso to it using the dd method. Whenever you need a new ISO you just remove/recreate the partition using gpart commands, then write the needed ISO to it. Yea, because I'm not sure writing with dd over the old one created the same way will work... AFAIK writing image over partition with dd makes the rest of the partition unusable.

Only DON'T try to use any *memstick.img for that, it's completely useless! Use normal CD iso.
Then you boot it from Grub2 menu like this (don't need to change that for each new ISO):
Code:
menuentry "FreeBSD *RELEASE" {
set root=(hd0,msods1)
kfreebsd /boot/loader
}
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#34
Now here's the advantage OpenBSD holds here: you just download bsd.rd of the next release, which is a kernel with initramfs and all you need for the (network) installation. You can at all times boot THAT from Grub2 :)

...So you see, the topic of booting FreeBSD off an ISO using the all-winning loopback technology of Grub2 has been subject of my study for quite some time now. But the only working solution I've found is described above: write the iso to a separate partition! Technically that's not a problem at all, since those *disc1.iso CDs are mostly around 1G in size, so you create your 2nd partition on USB stick leaving just enough space for the first one.
And you can always reinstall Grub2 like this:
Code:
#grub-install --boot-directory=$mountpoint_of_your_2nd_usb-partition/boot /dev/daN
This solution is still better than writing a *memstick.img to a whole USB drive, thus leaving the drive unusable for other goals. The 2-partitioned setup allows to always use the 2nd partition for whatever you want.
 
M

Marcelo Politzer Couto

Guest


#35
Just got this working in qemu with the following code:

Code:
   # set iso= ...
   loopback loop=${iso}
   kfreebsd (loop)/boot/kernel/kernel -v
   kfreebsd_module ${iso} type=mfs_root
   set kFreeBSD.vfs.root.mountfrom="cd9660:/dev/md0"
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#36
Just got this working in qemu with the following code:

Code:
   # set iso= ...
   loopback loop=${iso}
   kfreebsd (loop)/boot/kernel/kernel -v
   kfreebsd_module ${iso} type=mfs_root
   set kFreeBSD.vfs.root.mountfrom="cd9660:/dev/md0"
Do you have a bootable FreeBSD ISO on a USB stick? If so can you provide instructions on how to make one?
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#37
Yes you can boot that or any other FreeBSD ISO from a Grub2 USB stick. The way I do it is have 2 partitions of the USB stick. The first one is ~1G large (for the ISO) and the second is for Grub2 boot/grub dir and ISO images that ARE bootable with Grub2 via loopback feature.

Now the 1st partition is used to write a FreeBSD*disc1.iso to it using the dd method. Whenever you need a new ISO you just remove/recreate the partition using gpart commands, then write the needed ISO to it. Yea, because I'm not sure writing with dd over the old one created the same way will work... AFAIK writing image over partition with dd makes the rest of the partition unusable.

Only DON'T try to use any *memstick.img for that, it's completely useless! Use normal CD iso.
Then you boot it from Grub2 menu like this (don't need to change that for each new ISO):
Code:
menuentry "FreeBSD *RELEASE" {
set root=(hd0,msods1)
kfreebsd /boot/loader
}

I'm trying to create a USB stick capable of booting a FreeBSD ISO and thought I'd try following the instructions here but am getting lost...

Assuming I have 16GB USB stick, I need to reserve a 1GB partition for a FreeBSD*disc1.iso. Using gpart add -s 1G da0I need to add a partition type. What should that be? freebsd?

Then I need to dd https://download.freebsd.org/ftp/re...AGES/11.0/FreeBSD-11.0-RELEASE-i386-disc1.iso
to /dev/da0s1

How to create the second partition and install Grub2 on it?
 

aragats

Aspiring Daemon

Thanks: 347
Messages: 871

#38
This solution is still better than writing a *memstick.img to a whole USB drive, thus leaving the drive unusable for other goals. The 2-partitioned setup allows to always use the 2nd partition for whatever you want.
That's not always true: MS Windows recognizes only the 1st partition of a USB flash drive.
Why not using the 2nd partition for an ISO image?
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#39
I'm trying to create a USB stick capable of booting a FreeBSD ISO and thought I'd try following the instructions here but am getting lost...

Assuming I have 16GB USB stick, I need to reserve a 1GB partition for a FreeBSD*disc1.iso. Using gpart add -s 1G da0I need to add a partition type. What should that be? freebsd?

Then I need to dd https://download.freebsd.org/ftp/re...AGES/11.0/FreeBSD-11.0-RELEASE-i386-disc1.iso
to /dev/da0s1

How to create the second partition and install Grub2 on it?
First of all, unless I'm mistaken the partition table on my USB is not GPT but MBR type. Though I dont' remember now.

But I'm actually using this setup to boot every new RELEASE ISO from USB. Just want to emphasize it, it's NOT a USB *img file (that doesn't work!), but CD ISO. Don't think it matters much which partition type it is for it will be overwritten by dd anyway.
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#40
Do you set up the USB drive completely using FreeBSD? How do you install and configure Grub2 on the second partition?
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#41
Do you set up the USB drive completely using FreeBSD? How do you install and configure Grub2 on the second partition?
First of all, I think I did it under Linux (sorry for the disappointment!) Sysresccd using gparted. Create MBR, create vfat partition on your drive. Leave ~1Gb space BEFORE the partition you're creating. Format this one to vfat (in FreeBSD it will be msdosfs). Google for FreeBSD instructions to the same effect...

Then you mount that vfat/msdosfs partition you just created to /$mountpoint and install grub like this:
Code:
#grub-install --boot-directory=/$mountpoint/boot /dev/sda (or whatever your device is called)
Then in your formatted partition there appears /boot folder with grub config files. Grub2 installs to the disk itself (e.g. /dev/sda, /dev/da0 etc) and NOT to any partition (as in /dev/sda2, /dev/da0s1 etc). Then in the free space before the partition you create your other partition up to 1Gb in size etc.

Upon inserting your USB into Windows or other machine it will only mount your msdosfs partition. If you boot from it you'll have grub2 boot menu or prompt. This is the idea.

...Then you can also use this same USB (given it's good size) to boot some ISOs. While the first 1Gb partition will always contain a FreeBSD install CD which you can update as often as you want. I actually even booted Solaris CD this way, so it's pretty safe. Of course, for Solaris CD I played with grub.cfg found on their CD. But for FreeBSD GRUB2 command line is pretty simple...

PS: Tried formatting USB drive with GPT (which would be my preference), but then GRUB2 needs a bios-boot type partition to install the boot images, but in the end it doesn't work. With MBR all works fine.
On the other hand, I haven't tried it with the last GIT version of GRUB2, maybe it works now?
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#42
I'm trying to create the USB stick as you suggest, but only using FreeBSD... USB stick is /dev/da0

Code:
gpart destroy -F da0
gpart create -s mbr da0
gpart add -t freebsd -s 1g da0
gpart add -t fat32 -s 1g da0
newfs_msdos -F32 /dev/da0s2
The second partition is for GRUB. Unfortunately when I try formatting as fat32, I get

newfs_msdos: trim 8 sectors to adjust to a multiple of 63
newfs_msdos: 65502 clusters too few clusters for FAT32, need 65525
I haven't seen any examples showing what should be done to overcome this problem. Any advice would be appreciated.
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#44
After some experimenting, I created a 1GB FAT16 partition, followed by a 1GB FAT32 partition, and that one formatted without the previous error, so I guess I can try installing GRUB on the third partition. Should I install the FreeBSD grub2 pkg?
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#45
After some experimenting, I created a 1GB FAT16 partition, followed by a 1GB FAT32 partition, and that one formatted without the previous error, so I guess I can try installing GRUB on the third partition. Should I install the FreeBSD grub2 pkg?
Well definitely you WON'T be able to install grub from that. Still, I'm not sure which version of GRUB that pkg supplies... I'm using the latest GIT version for my needs.
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#46
I mean, with a recent enough GRUB you will be able to even boot your system, not only your USB. I do that when bootloader troubles happen (due to my constant experimenting, not due to that software's faultiness).
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#47
Well definitely you WON'T be able to install grub from that. Still, I'm not sure which version of GRUB that pkg supplies... I'm using the latest GIT version for my needs.
FreeBSD's pkg GRUB2 works ok, at least it installs, and I've managed to boot my USB stick to a grub prompt, although there is no grub menu, even though I copied your grub.conf from #33 in this thread (which contains a typo BTW). I did enter a few grub commands and managed to get the ISO image to boot, which I'm pleased about, but it would nice to get the menu to come up.
 

balanga

Daemon

Thanks: 69
Messages: 2,074

#49
Yes, I said so above, and very much appreciate your help in getting this working. I even come up with a little script to automate the process of creating a USB stick which will boot FreeBSD (or mfsBSD, or pfsense)....

Code:
gpart destroy -F da0
gpart create -s mbr da0
gpart add -t fat32 -b 7g da0
newfs_msdos -F 32 -c 4 /dev/da0s1
gpart add -t freebsd -s 1g da0
gpart add -t freebsd -s 1g da0
gpart add -t freebsd -s 1g da0
fetch https://download.freebsd.org/ftp/releases/amd64/amd64/ISO-IMAGES/11.0/FreeBSD-11.0-RELEASE-amd64-disc1.iso
fetch http://mfsbsd.vx.sk/files/iso/11/amd64/mfsbsd-mini-11.0-RELEASE-amd64.iso
fetch https://nyifiles.pfsense.org/mirror/downloads/pfSense-CE-2.3.3-RELEASE-amd64.iso.gz
dd if=FreeBSD-11.0-RELEASE-amd64-disc1.iso of=/dev/da0s2 bs=64k
dd if=mfsbsd-mini-11.0-RELEASE-amd64.iso of=/dev/da0s3 bs=64k
gunzip pfSense-CE-2.3.3-RELEASE-amd64.iso.gz
dd if=pfSense-CE-2.3.3-RELEASE-amd64.iso of=/dev/da0s4 bs=64k
pkg install grub2
mkdir /mnt/usb
mount -t msdosfs /dev/da0s1 /mnt/usb
grub-install --boot-directory=/mnt/usb/boot /dev/da0
cat << 'EOF' >> /mnt/usb/boot/grub/grub.cfg
menuentry "FreeBSD 11.0-RELEASE" {
set root=(hd0,msdos2)
kfreebsd /boot/loader
}
menuentry "mfsBSD" {
set root=(hd0,msdos3)
kfreebsd /boot/loader
}
menuentry "pfSense" {
set root=(hd0,msdos4)
kfreebsd /boot/loader
}
EOF
umount /mnt/usb
In my case da0 is an 8GB USB stick so the script may need adjusting. Give it a try and see if it works for you...

I would have tried more ISO's but I guess four partitions are the limit with gpart and mbr. Not sure if gpart can create extended partitions...

I did try using gpt, but found I couldn't dd an ISO to a gpt partition.
 

free-and-bsd

Aspiring Daemon

Thanks: 66
Messages: 633

#50
I did enter a few grub commands and managed to get the ISO image to boot
Yes, I said so above
No, you didn't "get an ISO image to boot" -- you did boot from a partition on your USB stick where you'd written an ISO image using dd. It wasn't an "image" any more, but a partition, and one would expect a partition to boot, you know.

While I was misled ;) by your wording to think that you somehow managed to boot an image the way sought earlier in this thread, using the loopback GRUB command.
 
Top