Jump to content

Archived

This topic is now archived and is closed to further replies.

nemesys

HOWTO: Boot Grub4Dos and Grub2 from one usb; Grub2 backgrounds and example config files.

Recommended Posts

This is a non-distro specific instruction on how to load Grub2 from Grub4Dos and to add background images into Grub2. Also including my example grub.cfg and menu.lst files including many unique distros which we haven't had much guidance on booting with grub2.

If you would like some very good information on more than is my scope at the moment please find the links at the bottom of this post.

UPDATES:

Great!

1) Grub2 is able to load Grub4Dos grldr without a patch!

If using the files from the grub4dos zip which include grub.exe

menuentry "Grub4Dos" {

linux16 /boot/grub/grub.exe

}

If you compiled from source and don't have grub.exe or simply prefer to use memdisk,

all that needs to be done is to use memdisk from syslinux as the kernel like this;

menuentry "Grub4Dos" {

linux16 /boot/grub/memdisk

initrd16 /boot/grub/grldr

}

I got memdisk from /usr/lib/syslinux and placed it in my usb's /boot/grub/ directory.

This works great. So now we can even load Grub4Dos from Grub2!

I started this to be able to boot all of what I wanted from grub2, yet I also liked Ultimate Boot CD, though did not want to edit the many menu files to convert them to grub2, that are installed with it. Even though the latest beta UBCD iso supports the loop boot in grub2 I wanted to have a system I could modify such as updating the virus databases and many different tools available in UBCD. This was the outcome of scouring many docs about installing and discussions about the limitations I was dealing with.

So I present the caveats

As a note this was all done on an 8GB flash drive using Slackware Linux.

**CAVEATS**

1) Do not install grub4dos to the first partition on the device, only to the mbr. I actually did this by mistake and was not able to get grub2 to boot from my usb until I reformatted the partition with a new dos partition table. I would constantly get an "unknown filesystem type" and be dropped in to the grub2 rescue-shell which is very limited.

2) Do not install grub2 onto the actual partition of the device or the mbr. It's unnecessary and actually will cause problems.

3) Adding the Grub2 font console coloring in grub.cfg seems to intercept loading the background image.

There is probably a way around this though I just haven't had the time though you are more than welcome to find a way and I would be happy to know the answer.

Installation:

We must create the grub2 files we need. Boot into a running system with grub2 or compile it (download the latest 1.9x version from; and install like I did. It installs to /usr/local/.

Next use grub-install to create the grub2 core.img and other files we need on the mounted usb drive using the command below. Using grub-setup is discouraged as grub-install calls it if needed anyway.

grub-install --no-floppy --root-directory=/mnt/usb/ --grub-setup=/bin/true /dev/sdb

NOTE: It is not required (as I once thought) to actually install grub2 to the mbr and then grub4dos over it. I found that by using the command above we can generate all the necessary files including core.img without actually touching the mbr. When /bin/true is specified it will 'do nothing successfully' when executed instead of overwriting the master boot record. Which is good.

After this we have the proper /boot/grub/ on the usb device, next we install grub4dos from Windows or whatever Linux you have grub4dos compiled on. Please make sure you are on the grub4dos machine now and not installing grub2 again. The grub4dos will not overwrite any grub2 files in /boot/grub/, only add new ones. Please change what is needed if you are installing grub4dos from Windows. It's very documented if you don't know as I don't since I only use Linux, except for Windows in a VirtualBox machine. To find out how to boot your usb directly into VirtualBox with a Linux host see the bottom of this post.

Using grub-setup is discouraged as grub-install calls it if needed anyway.

Install grub4dos to mbr;

grub-install --no-floppy --root-directory=/mnt/usb/ /dev/sdb (*replace with the proper directory/device*)

If you get an error about "unable to detect filesystem type" run the above command with --recheck added. This will rescan the hard drives on your computer and generate a new device.map in /boot/grub/

grub-install --recheck --no-floppy --root-directory=/mnt/usb/ /dev/sdb

Okay, Doing great so far.

Next we will need to add our menu.lst and a grldr file into /mnt/usb/boot/grub. I just used the ones from the UBCD /mnt/usb/ubcd/boot/grub/ for the time being. I have an nice light-green on black and vice-verso for highlighting color scheme which you can see in my configs for both grubs that work very well together and look pretty sic.

In UBCD the /boot/grub/menu.lst just leads to another file located within the ubcd directory at the root of the usb drive.

If you like UBCD you can use it's main.lst file that /boot/grub/menu.lst points to.

Once you edit it you will understand. If you choose not to use UBCD then just create a menu.lst in /grub/boot. I have an example attached.

Remember to get a hold of grldr also to place into the grub folder with menu.lst.

If you choose to load your own background in grub2 you would just add the lines into your grub.cfg;

insmod png

background_image=/boot/grub/images/myimage.png

Or if you prefer a jpg

insmod jpg

background_image=/boot/grub/images/myimage.jpg

There are more modules for graphics as well. There is even a play module and a play file load command that will supposedly play a tune. Those are all the details I have about the module right now and I wasn't able to get it to work with an mp3 though a wave file might very well do.

The ability to load modules like this is outstanding and even though the setup of the grub.cfg file looks different and may be tedious to learn at first, It is superior to the old menu.lst setup. If not just for it's much shorter size though also for the bash scripting design and better syntax.

I will lead you to this simple guide about many things to configure in grub2 including the background image and font which is needed first to load a grub2 graphical theme.

http://en.gentoo-wiki.com/wiki/Grub2

Also..

http://wiki.archlinux.org/index.php/GRUB2

If on Ubuntu/Debian the steps are different;

https://wiki.ubuntu.com/Grub2#Theming

This guide is intended to move away from the more well known Ubuntu howtos and give insight into what will work on any Linux distro though there is still some good information in the above link and is why I included it.

Now, even though Grub2 isn't installed on the mbr we can still call the core.img it created in /boot/grub/ along with any modules as well. Which is great because it requires less space and less hidden partition headache.

The Grub4Dos entry to load Grub2 in menu.lst is;

root (hd0,0)

kernel /boot/grub/core.img

or

uuid dev-uuid

kernel /boot/grub/core.img

You can find the uuid of your usb device using /sbin/blkid

Also make sure (hd0,0) actually corresponds to your disk and partition and remember that it's +1 now on the partition part in grub2 where as grub4dos still uses 0.

I actually just removed the root line totally so that only the kernel line was visible and it boots fine.

The grub2 menu will load and the command line is available with all the neat new modules and tools.

Here is my example menu.lst (actually UBCD's main.lst that menu.lst points to); Are you confused yet? You won't be.

You can see where I have an entry to load Grub2's core.img at the bottom of the file.

http://www.pastey.net/131454

Also here is my grub.cfg Grub2 uses;

http://www.pastey.net/132210-4aw0

Yes I love BackTrack 4 as much as the next person though I chose to use the recently released 2009 Pentoo distro because it has every thing I use anyway (including metasploit) and it's smaller size was ideal for my goal here (plus I like the E17 wm it includes). If you chose BT4 there are many guides available for this already.

The Slitaz I use is my own customized rescue distro. I built it and removed Parted Magic from my usb because Slitaz has everything I need installed including gparted, and many other rescue tools and the iso only comes to under 35MB. I didn't need the extra programs pmagic includes because they were superfluous. Slitaz is a very easy to customize distro that's perfect for usb and they even include the tools to make updating the entire distro easy.

Others you will notice are;

Linux Live Gamer DVD (I have actually removed this one because of it's size. It is nice and does work well if you can fit it.)

Kaspersky Rescue Disk (another invaluable tool located here; http://devbuilds.kaspersky-labs.com/devbuilds/RescueDisk10/)

Linux Mint 8 Live

Slackware Bootdisk + Install Files

Tinycore (It's another cool distro that is easily upgraded, boots into ram, and it's only 10 meg with a full Xvesa graphical environment!)

VirtualBox USB Testing on Linux Host

This has been made into a separate topic and can be found here;

http://hak5.org/forums/index.php?showtopic=15664

If you find a real error in any of the above information, please let me know.

Other very !great sites with information:

http://grub.enbug.org/CommandList |

http://www.dedoimedo.com/computers/grub-2.html

http://multidistro.com |

http://multidistro.com/wiki/wiki.html |

http://grub.enbug.org/FranklinPiat/grub.cfg.manpage |

Share this post


Link to post
Share on other sites

For those wondering about Konboot I seemed to have overlooked it when editing my grub.cfg though have added it back in with the commands below.

I got memdisk from /usr/lib/syslinux and placed it in my usb's /boot/grub/ directory.

#Konboot

menuentry "Konboot" {

linux16 /boot/grub/memdisk

initrd16 /boot/img/FD0-konboot-v1.1-2in1.img

}

Have a look at this site; Boot PC from Floppy Image w/ GRUB2 and MEMDISK

As for dban, it is included in UBCD so I am just using that one for now, though I did have Grub2 loading the dban iso using loopback before and it worked flawlessly.

Share this post


Link to post
Share on other sites

This has yet to work for me after multiple tries. I get an error that says, Cannot find GRLDR. I've verified that it is indeed there.

Share this post


Link to post
Share on other sites
This has yet to work for me after multiple tries. I get an error that says, Cannot find GRLDR. I've verified that it is indeed there.

I recall running into this problem once before and to solve it I placed grldr in the root of my usb drive.

I have since formatted and removed it though and it is now located at /boot/grub/grldr and I have no problem booting grub4dos now with it located there.

Version issue possibly?

Make sure it is lower case as it is on mine just to see if that makes a difference.

Also have a look to see if there is a newer version of grub4dos available than you are using.

Good luck and let me know.

Share this post


Link to post
Share on other sites
I recall running into this problem once before and to solve it I placed grldr in the root of my usb drive.

I have since formatted and removed it though and it is now located at /boot/grub/grldr and I have no problem booting grub4dos now with it located there.

Version issue possibly?

Make sure it is lower case as it is on mine just to see if that makes a difference.

Also have a look to see if there is a newer version of grub4dos available than you are using.

Good luck and let me know.

I redid it using WinGrub GUI (a program that installs Grub4dos) and it placed the grldr in the root. So far so good. When I reboot I get the following errors when trying to boot to the USB:

Try (hd0,0): FAT32: disk error
Error

Any ideas?

Share this post


Link to post
Share on other sites
I redid it using WinGrub GUI (a program that installs Grub4dos) and it placed the grldr in the root. So far so good. When I reboot I get the following errors when trying to boot to the USB:

Try (hd0,0): FAT32: disk error
Error

Any ideas?

I've seen that one before as well. I suggest a clean partition table written with Linux with fdisk and to use mkdosfs to create a fat32 LBA partition on the drive. Then don't allow your WinGrub to format it if you still chose to use Windows. I would really suggest just using Linux to install the grub4dos also. You can grab the latest version and it's easy to compile/install even in a live distro and your package manager may even have it in the repo. I actually use two computers; grub4dos installed on one computer and grub2 on another.

There is no indication as to what version WinGrub is using though the grldr location would give me an indication that it's older because with the latest I have no problem booting grldr from /boot/grub.

As for the error it seems like a new clean partition table is in order without being able to troubleshoot more myself, that is my best advice.

Remember not to install Grub2 to the MBR; only grub4dos. Many repeat tries and fails can cause the partition table to become borked. Rewriting the partition table is different than simply formatting. One way to create it is with fdisk, fdisk /dev/sdb (or whatever your usb is) then use the o option to create the partition table. Next select n to create a new partition and then the t option to change the partition system id to c which is FAT 32(LBA). Use the a command in fdisk to give the partition the boot-able flag Lastly write it out with the w command. Finally use mkdosfs -L <label> -F 32 /dev/sdb to create the fat 32 file system. You should be good to go then and able to follow the steps I laid out above. I found it much easier to use Linux than supposedly "easy to use" windows programs to do the entire process as those usually end up just causing problems either from variant versions or doing more than what you want them to.

Share this post


Link to post
Share on other sites

This is so wrong:

menuentry "Grub4Dos" {
linux16 /boot/grub/memdisk
initrd16 /grldr
}

MEMDISK is supposed to load floppy images, hard disk images or ISO images, not bootsectors.

The right way to load Grub4Dos from grub2 is to use the kernel version of Grub4dos (grub.exe):

menuentry "Grub4Dos" {
linux16 /boot/grub/grub.exe
}

Note: grub.exe doesn't need to be in the root because whole grub4dos is loaded in memory already and doesn't need to read the rest of grldr of the disk.

You can even pass arguments to this Grub4Dos variant.

Boot Grub4Dos and load (hd0,0)/boot/grub/grub4dos.lst as config file:

menuentry "Boot Grub4Dos and load (hd0,0)/boot/grub/grub4dos.lst as config file" {
linux16 /boot/grub/grub.exe --config-file=(hd0,0)/boot/grub/grub4dos.lst
}

Or directly boot a floppy image from Grub4dos when booted from grub2:

menuentry "Boot Grub4Dos and boot floppy image" {
linux16 /boot/grub/grub.exe --config-file="map (rd)+1 (fd0); map --hook; chainloader (fd0)+1; rootnoverify (fd0)"
initrd16 /boot/grub/floppy.img
}

See for more info in the REAME_GRUB4DOS.txt file

Share this post


Link to post
Share on other sites

Thanks for the extra info. Since I compiled from source I did not have these extra files available in the zip.

I'll update my post to show both options though both methods will work and the boogie man _won't_ get you if you use memdisk.

MEMDISK is used to boot an img which is exactly what grldr.

GRLDR is an IMG.

GRLDR is _not_ a boot sector which are actual block spaces at the beginning of a physical drive.

This is so wrong:

menuentry "Grub4Dos" {
linux16 /boot/grub/memdisk
initrd16 /grldr
}

MEMDISK is supposed to load floppy images, hard disk images or ISO images, not bootsectors.

The right way to load Grub4Dos from grub2 is to use the kernel version of Grub4dos (grub.exe):

menuentry "Grub4Dos" {
linux16 /boot/grub/grub.exe
}

Note: grub.exe doesn't need to be in the root because whole grub4dos is loaded in memory already and doesn't need to read the rest of grldr of the disk.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...