LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
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.

Notices


Reply
  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
(fd0)
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

CDIMAGE=./bootcd.img
ISOIMAGE=./bootcd.iso
SIZE=8
LOOPD=/dev/loop1
RELEASE=`uname -r`
BOOTFSTYPE=ext3

##
## 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
done

##
## 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/.
done
for file in /boot/vmlinuz-$RELEASE /boot/initrd-$RELEASE.img ;do
cp $file $TEMPMOUNT/boot/.
done

##
## 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
prompt
title Linux ($RELEASE)
kernel /boot/vmlinuz-$RELEASE
initrd /boot/initrd-$RELEASE.img
__GRUB_CONF

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

##
## Remove the temporary mount points and loopback associations.
##

umount $TEMPMOUNT
rmdir $TEMPMOUNT
/sbin/losetup -d $LOOPD

##
## END
##
 
Old 12-26-2003, 08:15 AM   #2
aus9
LQ Guru
 
Registered: Oct 2003
Distribution: Fedora 25 Gnome (Wayland)
Posts: 5,132

Rep: Reputation: Disabled
Owen

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

In your system.map 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
http://www.trekweb.com/~jasonb/artic...loopback.shtml
http://www.linux.org/docs/ldp/howto/...S-3.html#ss3.7
 
Old 12-26-2003, 09:06 AM   #3
whansard
Senior Member
 
Registered: Dec 2002
Location: Mosquitoville
Distribution: RH 6.2, Gen2, Knoppix,arch, bodhi, studio, suse, mint
Posts: 3,185

Rep: Reputation: 52
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?
 
  


Reply


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


All times are GMT -5. The time now is 09:29 AM.

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