[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Installing grub on an HD image
From: |
Eduardo Ochs |
Subject: |
Installing grub on an HD image |
Date: |
Thu, 27 Sep 2007 13:25:57 -0300 |
Hi list,
Maybe I'm missing something basic, but how do I install grub
(preferably grub2) on an HD image that will later be used as an hd0 on
a Flash IDE adapter?
Here's what I'm trying to do (the real script is at
<http://angg.twu.net/e/plurall.e.html#loop-fdisk-mke2fs>):
--snip--snip--
# Create a zeroed HD image with 20MB
rm -v /tmp/test.img
dd if=/dev/zero of=/tmp/test.img bs=1M count=20
# Create two primary partitions: 1st=4M, 2nd=16MB
sudo fdisk -C 20 -H 64 -S 32 /tmp/test.img
n
p
1
4
n
p
2
20
u
p
w
# Some notes about how to get the offsets for "losetup -o",
# and the sizes of the partitions for mke2fs...
# (find-sh "echo -e 'u\\np\\nq' | sudo fdisk /tmp/test.img")
# 64 heads, 32 sectors/track, 0 cylinders, total 0 sectors
# Units = sectors of 1 * 512 = 512 bytes
# Device Boot Start End Blocks Id System
# /tmp/test.img1 32 8191 4080 83 Linux
# /tmp/test.img2 8192 40959 16384 83 Linux
# Sizes, in 512-byte blocks:
# (list "/tmp/test.img1" (+ -32 8191 1) (* 4080 2))
# (list "/tmp/test.img2" (+ -8192 40959 1) (* 16384 2))
# Associate the full image to a loop device
# (grub-setup may need this)
sudo losetup -f | tee /tmp/test.dev0
sudo losetup $(cat /tmp/test.dev0) /tmp/test.img
# Associate the first partition to a loop device,
# clear it, make an ext2 filesystem there, mount it.
sudo losetup -f | tee /tmp/test.dev1
sudo losetup -o $[512*32] $(cat /tmp/test.dev1) /tmp/test.img
sudo dd if=/dev/zero of=$(cat /tmp/test.dev1) bs=1024 count=4080
sudo mke2fs -b 1024 -v $(cat /tmp/test.dev1) 4080
mkdir /tmp/dev1
sudo mount -o loop $(cat /tmp/test.dev1) /tmp/dev1
# Associate the second partition to a loop device,
# clear it, make an ext2 filesystem there, mount it.
sudo losetup -f | tee /tmp/test.dev2
sudo losetup -o $[512*8192] $(cat /tmp/test.dev2) /tmp/test.img
sudo dd if=/dev/zero of=$(cat /tmp/test.dev2) bs=1024 count=16384
sudo mke2fs -b 1024 -v $(cat /tmp/test.dev2) 16384
mkdir /tmp/dev2
sudo mount -o loop $(cat /tmp/test.dev2) /tmp/dev2
df
# Now copy the grub files to /tmp/dev1/boot/grub/
# and install grub on MBR of the HD image.
# (Omitted - my attempts to install grub on the image have failed!...)
# Umount, release loop devices
sudo umount /tmp/dev1
sudo umount /tmp/dev2
sudo losetup -d $(cat /tmp/test.dev2) 2>&1 > /dev/null
sudo losetup -d $(cat /tmp/test.dev1) 2>&1 > /dev/null
sudo losetup -d $(cat /tmp/test.dev0) 2>&1 > /dev/null
--snip--snip--
By the way, after installing grub on the image the next steps are:
* try to boot from that HD image with qemu,
* make sure that grub recognizes the two partitions,
* extract a linux kernel and an initrd from a certain liveCD
(http://www.devil-linux.org/) and put them in the first partition,
* enlarge the HD size to 256MB,
* copy the CD image to the second partition (so that it cease to be
ext2 and will become a compressed iso)
* change the /linuxrc onthe initrd to make it start an interactive
shell,
* use that shell to mount (manually) the CD image from /dev/hda2
instead of from a CD device, and then try to run pivotroot into it
to run the liveCD,
* change the CD detection functions in the /linuxrc script to make
them handle a boot parameter like "cddevice=/dev/hda2".
If this works well then we will be able to run small liveCD images
(Devil Linux is ~ 200MB) on scrap machines that have no CD drive and
no HD, just by putting a 256MB flash IDE adapter on them...
Cheers,
Eduardo Ochs
address@hidden
http://angg.twu.net/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Installing grub on an HD image,
Eduardo Ochs <=