Share your knowledge at the LQ Wiki.
Go Back > Forums > Linux Forums > Linux - Software
User Name
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.


  Search this Thread
Old 12-19-2003, 07:21 PM   #1
Owen LaGarde
LQ Newbie
Registered: Dec 2003
Distribution: RH
Posts: 6

Rep: Reputation: 0
Question How to grub install to a partition on an image file via a loopback

I'm looking for a way to make a bootable *file* image with grub. With the image file created, losetup'd to /dev/loop1, a filesystem laid down, and the /boot tree populated, I start the grub shell and use the [unoccupied!!] /dev/fd0 as the temporary device. Here's what happens:

grub> device (fd0) /dev/loop1
grub> root (fd0)
Filesystem type is ext2fs, using whole disk
grub> find /boot/grub/stage1
grub> setup (fd0)
Checking if "/boot/grub/stage1" exists... yes
Checking if "/boot/grub/stage2" exists... yes
Checking if "/boot/grub/e2fs_stage1_5" exists... yes
Running "embed /boot/grub/e2fs_stage1_5 (fd0)"... failed (this is not fatal)
Running "embed /boot/grub/e2fs_stage1_5 (fd0)"... failed (this is not fatal)
Running "install /boot/grub/stage1 (fd0) /boot/grub/stage2 p /boot/grub/grub.conf "... failed

Error 24: Attempt to access block outside partition

Running the individual components of the setup are no different, of course. The partition associated with /dev/loop1 is intact and the file tree contents looks good; I can't identify any problems there and all files cmp cleanly with their originals. I've tried this with partitions small enough for a boot floppy, with and without a patched stage2 loader, and with ext2 and msdos filesystems, all with the same results. It appears that the grub shell cannot write to a partition mounted on a loop device.

Here's the context of the problem; this is a shell snippet of what I'd like to do to automate the processes somewhat. Parts of this should be recognizable from the CDRec and BootCD projects:

----- snip here -------- or there ----------- or anywhere ----------------------------
#!/bin/sh -x

RELEASE=`uname -r`

## Set up a target for the CD image in a file. Associate it with
## a mountable loopback device so that it can be mounted as a raw
## device, ie., before a mountable filesystem has been created on
## it. Use a temporary mount of the loopback device to set up the
## file tree (/boot, /boot/grub, minimal /usr and /etc, etc).

TEMPMOUNT=`/bin/mktemp -d XXXXXX`
dd if=/dev/zero of=$CDIMAGE bs=1k count=$(($SIZE * 1024))
/sbin/losetup $LOOPD $CDIMAGE
/sbin/mkfs -t $BOOTFSTYPE $LOOPD || exit 1
mount $LOOPD $TEMPMOUNT || exit 2
mkdir -p $TEMPMOUNT/boot/grub || exit 3
for dir in /usr/bin /usr/sbin /bin /sbin /etc ;do
mkdir -p $TEMPMOUNT$dir

## Copy the current system bootloader stages, kernel, initrd, and
## minimal root filesystem into place.

for file in /boot/grub/*stage* ;do
cp $file $TEMPMOUNT/boot/grub/.
for file in /boot/vmlinuz-$RELEASE /boot/initrd-$RELEASE.img ;do
cp $file $TEMPMOUNT/boot/.

## Use the grub shell to install the loaders in <bootcd>/boot/grub/
## into the boot record of the image. Patch with a customized copy
## of grub.conf placed in the boot image tree.

cat <<__GRUB_CONF >>$TEMPMOUNT/boot/grub/grub.conf
timeout 10
title Linux ($RELEASE)
kernel /boot/vmlinuz-$RELEASE
initrd /boot/initrd-$RELEASE.img

grub <<__GRUB_CMDS
device (fd0) $LOOPD
root (fd0)
install (fd0)/boot/grub/stage1 (fd0) (fd0)/boot/grub/stage2 p (fd0)/boot/grub/grub.conf

## Remove the temporary mount points and loopback associations.

/sbin/losetup -d $LOOPD

## END
Old 12-26-2003, 08:15 AM   #2
LQ 5k Club
Registered: Oct 2003
Location: Western Australia
Distribution: debian IceWM
Posts: 5,764

Rep: Reputation: Disabled

I have no idea what you are doing, so forgive the following suggestions.

In your file under /boot/grub have you defined a (fd0)/dev/loop1 or don't you think you need to. Me thinks that may be an issue?

2) Its hard to read syntax when we can not be sure if its a typo or culler of space, but are you happy with this concept?
There should be no gap in using an absolute pathway, so its (fd0)/ not (fd0)(space) /

3) google gave me this for starters
Old 12-26-2003, 09:06 AM   #3
Senior Member
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,301

Rep: Reputation: 65
why does it have to be grub?

have you compared your scripts to what the mandrake loopback install
does, or other loopback installs?

are you trying to make your own grub booted loopback installation, or
something for a cd?

you've probably looked at the knoppix block compressed loopback
filesystem setup too, right?


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
How add a loopback DVD iso image to fstab?? carl0ski Linux - General 3 09-02-2011 02:55 PM
Resizing a loopback image Jehuty Linux - Hardware 5 08-29-2005 10:52 AM
Can i install an OS off a cd image on my windows (xp) partition? venom_zx Slackware 8 03-10-2004 02:11 PM
grub stage 2 file on logical partition? Samsara Linux - Newbie 2 02-12-2004 03:47 PM
Mount Loopback filesystem on an entire HD image? wartstew Linux - General 0 01-24-2003 07:46 PM > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 07:43 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration