Reply to this topic
 How to install GRUB2 on USB drive from within Windows
post Jan 26 2010, 05:56 PM
Post #1
somanystars
  
Group: Members

  Joined: 26-January 10
Posts: 8
Thank(s): 0


Russia


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:

CODE
Welcome to GRUB!
error: the symbol 'grub_machine_fini' not found
Entering rescue mode


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


+Quote Post
post Jan 26 2010, 07:07 PM
Post #2
Wonko the Sane
Gold Member   *****
Group: Advanced user

  Joined: 8-January 10 From: The Outside of the Asylum

Posts: 2,277
Thank(s): 252


Italy


QUOTE (somanystars @ Jan 26 2010, 06:56 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.net/forums/index.php?showtopic=10242

may help you.

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

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

cheers.gif

Wonko


--------------------
+Quote Post
post Jan 26 2010, 07:20 PM
Post #3
ireneuszp
Frequent Member   ***
Group: Advanced user

  Joined: 29-September 06
Posts: 155
Thank(s): 42


Poland


experimental version of grub4dos is also here:
http://grub4dos-chenall.googlecode.com/fil...-2010-01-23.zip

grub2 is here
http://cz.archive.ubuntu.com/ubuntu/pool/u...buntu5_i386.deb

or here from debian
http://ftp.debian.org/pool/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.org/debian/pool/main/....1-18-3_all.deb


--------------------
+Quote Post
post Jan 28 2010, 09:30 AM
Post #4
somanystars
  
Group: Members

  Joined: 26-January 10
Posts: 8
Thank(s): 0


Russia


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:

CODE
Determining looptype…
!!Invalid loop location: /image.squashfs
!!Please export LOOP with a valid location, or reboot and pass proper loop=…
!!kernel command line


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...
+Quote Post
post Jan 28 2010, 10:11 AM
Post #5
Wonko the Sane
Gold Member   *****
Group: Advanced user

  Joined: 8-January 10 From: The Outside of the Asylum

Posts: 2,277
Thank(s): 252


Italy


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

You don't need to.

In grub4dos don't re-map anything (KISS approach wink.gif):
CODE
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?
QUOTE
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.debian.org/lenny/grubutil-win32
and follow the "chain of thought" of the good debian guys?
http://packages.debian.org/search?keywords=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.net/forums/index.php?showtopic=7328
http://www.boot-land.net/forums/index.php?showtopic=8986

Wonko


--------------------
+Quote Post
post Feb 5 2010, 04:28 PM
Post #6
somanystars
  
Group: Members

  Joined: 26-January 10
Posts: 8
Thank(s): 0


Russia


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 sad.gif But finally, I found a solution with grub4dos chainloading patched iso image.
Thanks to all very much!
+Quote Post
post Feb 5 2010, 04:36 PM
Post #7
Wonko the Sane
Gold Member   *****
Group: Advanced user

  Joined: 8-January 10 From: The Outside of the Asylum

Posts: 2,277
Thank(s): 252


Italy


QUOTE (somanystars @ Feb 5 2010, 05:28 PM) *
Thank you Wonko the Sane!


You are welcome smile.gif, BUT happy22.gif
QUOTE (somanystars @ Feb 5 2010, 05:28 PM) *
But finally, I found a solution with grub4dos chainloading patched iso image.


... which you are carefully avoiding to describe and detail....sad.gif.

I mean, what do you think that would be more useful to another guy having a similar problem (please choose one):
  1. a thread where a number of possibilities are given and the OP reports success with one of them (without saying WHICH one ranting2.gif )
    or
  2. 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 cool.gif )


cheers.gif

Wonko


--------------------
+Quote Post
post Mar 7 2010, 07:25 PM
Post #8
breaker
Member   **
Group: Members

  Joined: 19-February 10
Posts: 38
Thank(s): 6


United States


@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
+Quote Post
post Mar 20 2010, 06:01 PM
Post #9
somanystars
  
Group: Members

  Joined: 26-January 10
Posts: 8
Thank(s): 0


Russia


Hi everybody! I'm sorry for not instant replying, but it's better late then never, isn't it? smile.gif
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:

CODE
map (hd0,0)/my/myusb.iso (0xff) || map --mem (hd0,0)/my/myusb.iso (0xff)
map --hook
chainloader (0xff)


then grub2 starts, then Gentoo kernel starts and finds my.iso and mounts it and the things are going almost fine smile.gif

My Gentoo init script (part that I changed):
CODE
if [ "${CDROOT}" = '1' ]
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}" != '' ]
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'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}" = '' ]
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 '.'
let COUNTER=${COUNTER}+1
done

sleep 1
echo -e "${NORMAL}"
bootstrapCD
fi

if [ "${REAL_ROOT}" = '' ]
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 'Could not find CD to boot, something else needed!'
CDROOT=0
fi
fi

# Determine root device
good_msg 'Determining root device...'
while true
do
while [ "${got_good_root}" != '1' ]
do
case "${REAL_ROOT}" in
LABEL\=*|UUID\=*)

ROOT_DEV=""
retval=1

if [ "${retval}" -ne '0' ]; then
ROOT_DEV=`findfs "${REAL_ROOT}" 2>/dev/null`
retval=$?
fi

if [ "$retval" -ne '0' ]; then
ROOT_DEV=`busybox findfs "${REAL_ROOT}" 2>/dev/null`
retval=$?
fi

if [ "${retval}" -ne '0' ]; then
ROOT_DEV=`blkid -t "${REAL_ROOT}" | cut -d ":" -f 1 2>/dev/null`
retval=$?
fi

if [ "${retval}" -eq '0' ] && [ -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}" = '' ]
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}" != '' ]
then
REAL_ROOTFLAGS="loop -t iso9660"
mount -o ro,${REAL_ROOTFLAGS} ${REAL_ROOT} ${NEW_ROOT}/mnt/cdrom
if [ "$?" = '0' ]
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}" = '1' -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}" = '/dev/nfs' ]; then
findnfsmount
else
# mount ro so fsck doesn't barf later
if [ "${REAL_ROOTFLAGS}" = '' ]; 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 [ "$?" = '0' ]
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=''
fi
else
bad_msg "Could not mount specified ROOT, try again"
got_good_root=0
REAL_ROOT=''
fi
fi
done
# End determine root device


+Quote Post

Reply to this topic
5 User(s) are reading this topic ()



Collapse

  Topic Replies Topic Starter Views Last Action
No new Topic has attachmentsInstall Windows 7/Vista From USB Drive
Very simple
71 Nuno Brito 35,954 1st September 2010 - 02:34 PM
Last post by: ps2_hacker
No New Posts driverpacks.net and winbuilder?
Can driverpacks.net additions be used with livexp?
4 bradgillap 157 1st September 2010 - 04:50 AM
Last post by: bradgillap
No New Posts Windows Server 2008 R2 Server - The perfect workstation OS
0 Michael Pietroforte 97 31st August 2010 - 08:19 PM
Last post by: Michael Pietroforte
No New Posts Grub2 Manual
7 Icecube 289 31st August 2010 - 05:00 PM
Last post by: Wonko the Sane
No New Posts HOW TO Integrate Fedora 13 Into a Sardu + G4D Multiboot USB
HOW TO
4 fms 237 29th August 2010 - 03:51 PM
Last post by: Wonko the Sane