Jump to content











Photo
- - - - -

How to install GRUB2 on USB drive from within Windows


  • Please log in to reply
8 replies to this topic

#1 somanystars

somanystars
  • Members
  • 8 posts

Posted 26 January 2010 - 05:56 PM

Hi All. I've spent a lot of time trying to do subj.
To be more clear. I have an iso image which uses GRUB2 (specifically, grub-1.97.1) as boot loader. (Some beautiful menus etc.) My task is to create bootable USB drive which after booting will behave exactly as the original CD would, by booting from iso image or by just copying image's contents to the USB disk.
The problem is that I cannot find a way to install GRUB2 (or GRUB2-based grub4dos, not legacy grub) into USB stick.
Though grubinst has option --grub2, it requires g2ldr which isn't included in grub4dos bundly (and I really don't understand why).
After hours of surfing I found some strange iso images like grub2-2009-01-13.iso.bz2 and copied g2ldr from them. But after booting from USB disk, theres is an outout:

[codebox]Welcome to GRUB!
error: the symbol 'grub_machine_fini' not found
Entering rescue mode
[/codebox]

And no beautiful menus etc.
Please help as I have no ideas by now...

#2 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 26 January 2010 - 07:07 PM

Please help as I have no ideas by now...


Workaround:
Install grub4dos and chainload grub2, see how the answers that are completely UNLIKE useful in this thread:
http://www.boot-land...showtopic=10242

may help you.

Unlike the problem in the given thread, grub2 can normally be chainloaded by grub4dos:
http://www.boot-land...?...c=9882&st=6

Make sure to get a latish version, this one being recommended:
stable:
http://nufans.net/gr...-2009-10-16.zip
experimental:
http://nufans.net/gr...-2010-01-08.zip

:lol:

Wonko

#3 ireneuszp

ireneuszp

    Frequent Member

  • Advanced user
  • 191 posts
  •  
    Poland

Posted 26 January 2010 - 07:20 PM

experimental version of grub4dos is also here:
http://grub4dos-chen...-2010-01-23.zip

grub2 is here
http://cz.archive.ub...buntu5_i386.deb

or here from debian
http://ftp.debian.or...l/main/g/grub2/

use 7-Zip File Manager
and unpack from grub-rescue-pc_*.* file grub-rescue-cdrom.iso
and test it

g2hdr.bin
g2ldr.mbr
is here
http://ftp.de.debian....1-18-3_all.deb

#4 somanystars

somanystars
  • Members
  • 8 posts

Posted 28 January 2010 - 09:30 AM

Thank you both very much for your extensive replies! I have succeeded chainloading boot loader from iso image using grub4dos (grub1-based) by using the following grub4dos commands:

map (hd0,0)/myimage.iso (0xff) || map --mem (hd0,0)/myimage.iso (0xff)
map --hook
root (0xff)
chainloader (0xff)
map (0xff) (hd0)

And I get grub2 from iso and all the beautiful menus etc. When I go to grub2 command line I can see 4 disk devices using ls command:

(hd0) (hd1) (hd127) (fd0)

And ls / gives me a file list of the files inside myimage.iso, and so ls (hd127)/ does. It means grub 2 sees my virtual CD (though I did expect virtual CD to be (hd0) due to map (0xff) (hd0)).

OK, then I select some item from my beautiful menu to start, and Linuex starts loading. But loading fails because Linux cannot find image.squashfs file (which is really presents inside iso). Specifically the messages are:

[codebox]Determining looptype… !!Invalid loop location: /image.squashfs !!Please export LOOP with a valid location, or reboot and pass proper loop=… !!kernel command line [/codebox] As I can see in the earlies messages, Linux doesn't see my virtual CD, because it found /dev/sda1, /dev/sda2 (which seems to be 2 partitions of my HDD), /dev/sr0 (seems to be real DVD drive) and /dev/sdb1 (seems to be USB flash stick which I'm trying to boot from). OK, I read manual and edited grub.cfg inside iso image to direct grub2 to make virtual drive from iso image, too, using the following loopback command: insmod fat insmod iso9660 loopback loop (hd0,0)/rescue.iso linux /boot/rescue root=/dev/ram0 init=/linuxrc looptype=squashfs loop=/image.squashfs cdroot initrd=rescue.igz noapic kav_lang=${kav_lang} quiet initrd /boot/rescue.igz But the loopback command fails with message: error: no such partition

I tried insmod ntfs (because my HDD is NTFS-formatted) and after that I tried (hd0,1) ... (hd0,5) and (hd1,0) ... (hd1,5), but result was the same. I tried running 'partition' command but it said unknown filesystem (fs) or something like that.

So now in case of trying to boot from iso directly I'm stuck with problem: why grub2 doesn't see partitions of my HDD and USB stick (which is FAT32 formatted).


Now, if try to go another way and install grub2 on the USB disk itself, I can't understand how to install g2hdr.bin and g2ldr.mbr to USB disk's MBR. As far as I understand grubinst utility which latest version available to me is of January 2008 contains grub(1,2) boot sectors inside it and uses these old ones. So the second questing is: How can I direct grubinst or another utility to use external g2hdr.bin/g2ldr.mbr and install the to USB disk's MBR?..

Will be thankful for any ideas and comments...

#5 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 28 January 2010 - 10:11 AM

You seem like "obsessed" by mapping or re-mapping things.

You don't need to.

In grub4dos don't re-map anything (KISS approach :lol:):
title grub2

find --set-root /boot/grub/core.img
(make sure that grub2 core.img is in /boot/grub/ - remember that on CDFS grub4dos is CaSe SeNsItiVe - use Command line to make tests)

And post what happens.

Once we solve the loading of grub2, one way or the other, there will be still the problems about "converting" your grub.cfg entries "from CD" "to USB HD like device".

About installing grub2, have you actually tried what's in the grub2 package pointed to?

Package: grubutil-win32
Version: 1.1-18-3
Architecture: all
Maintainer: Robert Millan <rmh@aybabtu.com>
Installed-Size: 52
Section: devel
Priority: extra
Description: GRUB win32 boot images
This package provides GRUB boot record images that can be used by the
native bootloaders of various win32 platforms in order to load a full
instance of GNU GRUB.
.
It is used by the win32-loader package to provide suitable GRUB images for
loading Debian-Installer on win32.

http://packages.debi.../grubutil-win32
and follow the "chain of thought" of the good debian guys?
http://packages.debi...ds=win32-loader
(i.e. fake a debian install on the stick, and you should have grub2 installed allright)

you may want to try some other tools (but CANNOT say if they would work):
http://www.boot-land...?showtopic=7328
http://www.boot-land...?showtopic=8986

Wonko

#6 somanystars

somanystars
  • Members
  • 8 posts

Posted 05 February 2010 - 04:28 PM

Thank you Wonko the Sane! I don't know whether it's black magic around grub2 or something else, but I could not ever find core.img anywhere ;) But finally, I found a solution with grub4dos chainloading patched iso image.
Thanks to all very much!

#7 Wonko the Sane

Wonko the Sane

    The Finder

  • Advanced user
  • 16066 posts
  • Location:The Outside of the Asylum (gate is closed)
  •  
    Italy

Posted 05 February 2010 - 04:36 PM

Thank you Wonko the Sane!


You are welcome ;), BUT ;)

But finally, I found a solution with grub4dos chainloading patched iso image.


... which you are carefully avoiding to describe and detail....;).

I mean, what do you think that would be more useful to another guy having a similar problem (please choose one):
  • a thread where a number of possibilities are given and the OP reports success with one of them (without saying WHICH one :P )
    or
  • a thread where a number of possibilities are given and the OP reports success with one of them (describing in detail WHICH one worked for him :cheers: )

:P

Wonko

#8 breaker

breaker

    Frequent Member

  • Advanced user
  • 114 posts
  •  
    United States

Posted 07 March 2010 - 07:25 PM

@somanystars It would have helped to know exactly what iso you were trying to boot. I am surprised your iso uses grub2 to boot, usually that is not the case. Depending on what the iso is, it can be very easy to boot it on a usb flash drive. Unetbootin is a Windows program you can use to boot almost any Linux distro, if that's what it is. It extracts the iso then boots it with syslinux. IF it is a Linux distro, depending on the distro another option is to burn a Linux Distro that has the grub-pc package installed (Like Linux Mint 8 or Ubuntu Karmic Koala), then from within the command line of the CD, simply install grub2 to the mbr and a /boot directory of the flash drive, copy the entire iso over to the drive, then make a simple grub.cfg (menu for grub2) that has the commands to boot the iso directly.

YMMV, but I feel these methods are easier than using grub4dos _IF_ this is a Linux Live CD iso.

SO, exactly which iso did you boot?

Thanks,

breaker

#9 somanystars

somanystars
  • Members
  • 8 posts

Posted 20 March 2010 - 06:01 PM

Hi everybody! I'm sorry for not instant replying, but it's better late then never, isn't it? <_<
Unfortunately I can't name the iso I work with because it's not publicly available by now.
Below are some details about my solution, which looks rathe strange but working (though grub4dos is not always can start itself and this is going to be my next topic here).
The iso is Gentoo-based. As I said, I was able to chainload it using grub4dos' map command, but there is an inconvenience because you must have the iso file defragmented or you have to wait for a rather long time while map --mem is loading it into RAM.
But this is not worst. After iso image bootstrapped, grub2 loads it's menus etc., user makes a selection and Gentoo kernel starts loading, iso mapping is no longer works and loading script fails. It means all efforts spent to chainload large iso file are almost useless.
So I decided to solve this into 2 steps:
1) split original iso into 2 files. The first one contains only grub2 and Gentoo kernel files, and the second one is the original iso file with all applications and data (and grub2 and Gentoo too). Let's say their names are myusb.iso and my.iso.
2) change Gentoo's loading scripts so that it mounts original iso (if it finds myiso.iso) and points REAL_ROOT starting script variable to it. I ended up with an init script that you can find at the and of this topic.

When such prepared USB stick boots, first MBR code finds grldr of grub4dos, then grub4does performs:

[codebox]map (hd0,0)/my/myusb.iso (0xff) || map --mem (hd0,0)/my/myusb.iso (0xff) map --hook chainloader (0xff) [/codebox] then grub2 starts, then Gentoo kernel starts and finds my.iso and mounts it and the things are going almost fine :wodoo: My Gentoo init script (part that I changed): [codebox]if [ "${CDROOT}" = &#39;1&#39; ] then good_msg "Making tmpfs for ${NEW_ROOT}" mount -n -t tmpfs tmpfs "${NEW_ROOT}" for i in dev mnt mnt/cdrom mnt/livecd mnt/key mnt/usb tmp tmp/.initrd mnt/gentoo sys do mkdir -p "${NEW_ROOT}/${i}" chmod 755 "${NEW_ROOT}/${i}" done [ ! -e "${NEW_ROOT}/dev/null" ] && mknod "${NEW_ROOT}"/dev/null c 1 3 [ ! -e "${NEW_ROOT}/dev/console" ] && mknod "${NEW_ROOT}"/dev/console c 5 1 # For SGI LiveCDs ... if [ "${LOOPTYPE}" = "sgimips" ] then [ ! -e "${NEW_ROOT}/dev/sr0" ] && mknod "${NEW_ROOT}/dev/sr0" b 11 0 [ ! -e "${NEW_ROOT}/dev/loop0" ] && mknod "${NEW_ROOT}/dev/loop0" b 7 0 fi # Mount iso image, if any if [ "${DO_slowusb}" ] || [ "${FORCE_slowusb}" ] then sleep 10 fi good_msg "Trying to mount live usb..." # USB Keychain/Storage local USB_DEVICES="/dev/sd*" # IDE devices USB_DEVICES="$USB_DEVICES /dev/hd*" # USB using the USB Block Driver USB_DEVICES="$USB_DEVICES /dev/ubd* /dev/ubd/*" # Prevent error message local OLD_CRYPT_SILENT="$CRYPT_SILENT" CRYPT_SILENT=1 findmediamount "usb" "${SUBDIR}/myliveusb" "USB_ROOT" "${NEW_ROOT}" "${USB_DEVICES}" CRYPT_SILENT="$OLD_CRYPT_SILENT" if [ "${USB_ROOT}" != &#39;&#39; ] then REAL_ROOT="${NEW_ROOT}/mnt/usb/my/my.iso" good_msg "Live usb mounted, real root is ${REAL_ROOT}" fi # Required for splash to work. Not an issue with the initrd as this # device isn&#39;t created there and is not needed. if [ -e /dev/tty1 ] then [ ! -e "${NEW_ROOT}/dev/tty1" ] && mknod "${NEW_ROOT}/dev/tty1" c 4 1 fi if [ "${REAL_ROOT}" != "/dev/nfs" ] && [ "${LOOPTYPE}" != "sgimips" ] then bootstrapCD fi if [ "${REAL_ROOT}" = &#39;&#39; ] then echo -n -e "${WARN}>>${NORMAL}${BOLD} No bootable medium found. Waiting for new devices" COUNTER=0 while [ ${COUNTER} -lt 3 ]; do sleep 3 echo -n &#39;.&#39; let COUNTER=${COUNTER}+1 done sleep 1 echo -e "${NORMAL}" bootstrapCD fi if [ "${REAL_ROOT}" = &#39;&#39; ] then # Undo stuff umount "${NEW_ROOT}/dev" 2>/dev/null umount "${NEW_ROOT}/sys" 2>/dev/null umount /sys 2>/dev/null umount "${NEW_ROOT}" rm -rf "${NEW_ROOT}/*" bad_msg &#39;Could not find CD to boot, something else needed!&#39; CDROOT=0 fifi# Determine root devicegood_msg &#39;Determining root device...&#39;while truedo while [ "${got_good_root}" != &#39;1&#39; ] do case "${REAL_ROOT}" in LABEL\=*|UUID\=*) ROOT_DEV="" retval=1 if [ "${retval}" -ne &#39;0&#39; ]; then ROOT_DEV=&#96;findfs "${REAL_ROOT}" 2>/dev/null&#96; retval=$? fi if [ "$retval" -ne &#39;0&#39; ]; then ROOT_DEV=&#96;busybox findfs "${REAL_ROOT}" 2>/dev/null&#96; retval=$? fi if [ "${retval}" -ne &#39;0&#39; ]; then ROOT_DEV=&#96;blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null&#96; retval=$? fi if [ "${retval}" -eq &#39;0&#39; ] && [ -n "${ROOT_DEV}" ]; then good_msg "Detected real_root=${ROOT_DEV}" REAL_ROOT="${ROOT_DEV}" else whereis "REAL_ROOT" "root block device" got_good_root=0 continue fi ;; esac if [ "${REAL_ROOT}" = &#39;&#39; ] then # No REAL_ROOT determined/specified. Prompt user for root block device. whereis "REAL_ROOT" "root block device" got_good_root=0 # Check for an iso image elif [ "${USB_ROOT}" != &#39;&#39; ] then REAL_ROOTFLAGS="loop -t iso9660" mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}/mnt/cdrom if [ "$?" = &#39;0&#39; ] then got_good_root=1 fi # Check for a block device or /dev/nfs elif [ -b "${REAL_ROOT}" ] || [ "${REAL_ROOT}" = "/dev/nfs" ] then got_good_root=1 else bad_msg "Block device ${REAL_ROOT} is not a valid root device..." REAL_ROOT="" got_good_root=0 fi done if [ "${CDROOT}" = 1 -a "${got_good_root}" = &#39;1&#39; -a "${REAL_ROOT}" != "/dev/nfs" ] then # CD already mounted; no further checks necessary
break
elif [ "${LOOPTYPE}" = "sgimips" ]
then
# sgimips mounts the livecd root partition directly
# there is no isofs filesystem to worry about
break
else
good_msg "Mounting root..."

# Try to mount the device as ${NEW_ROOT}
if [ "${REAL_ROOT}" = &#39;/dev/nfs&#39; ]; then
findnfsmount
else
# mount ro so fsck doesn&#39;t barf later
if [ "${REAL_ROOTFLAGS}" = &#39;&#39; ]; then
mount -o ro ${REAL_ROOT} ${NEW_ROOT}
else
good_msg "Using mount -o ro,${REAL_ROOTFLAGS}"
mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}
fi
fi

# If mount is successful break out of the loop
# else not a good root and start over.
if [ "$?" = &#39;0&#39; ]
then
if [ -d ${NEW_ROOT}/dev -a -x ${NEW_ROOT}/sbin/init ] || [ "${REAL_ROOT}" = "/dev/nfs" ]
then
break
else
bad_msg "The filesystem mounted at ${REAL_ROOT} does not appear to be a valid /, try again"
got_good_root=0
REAL_ROOT=&#39;&#39;
fi
else
bad_msg "Could not mount specified ROOT, try again"
got_good_root=0
REAL_ROOT=&#39;&#39;
fi
fi
done
# End determine root device
[/codebox]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users