> What you are doing is something that I messed with at while back.  I found that
> to format partitions inside of a file, you must do the formatting
> _inside_of_plex86_ and not on the host machine.  You can use the host machine
> to partition the file, but you cannot format the partitions inside of the file
> using the host.  This is as good as the answer gets.

Why can't you do it on the host? This is what I've done:

1) Create the disk image

   Size  Cyl  Heads Sectors/Track Sectors
   --------------------------------------
   10MB  306  4     17            20808
   20MB  615  4     17            41820
   30MB  615  6     17            62730
   46MB  940  6     17            95880
   62MB  940  8     17            127840
   112MB 900  15    17            229500
   126MB 256  16    63            258048
   483MB 1024 15    63            967680
   504MB 1024 16    63            1032192


sopwith% dd if=/dev/zero of=disk.img bs=512  count=1032192
1032192+0 records in
1032192+0 records out

2) Setup partitions using fdisk
sopwith% sudo losetup /dev/loop0 disk.img
sopwith% sudo fdisk /dev/loop0
 
  a) Tell fdisk to use my CHS settings, 1024,16,63
  b) Create 2 partions, one for Hurd, one for Swap
  c) Examine values from advanced mode:

        Command (m for help): x
 
        Expert command (m for help): p
 
        Disk /dev/loop0: 16 heads, 63 sectors, 1024 cylinders
 
        Nr AF  Hd Sec  Cyl  Hd Sec  Cyl    Start     Size ID
         1 00   1   1    0  15  63  812       63   819441 83
         2 00   0   1  813  15  63 1023   819504   212688 82
         3 00   0   0    0   0   0    0        0        0 00
         4 00   0   0    0   0   0    0        0        0 00

  d) Write changes and exit.


3) Create two partions and dd them into the image file. I use the
   information I just obtained from fdisk about the partition
   locations and sizes. I examined many scenarios using fdisk, dd,
   and hexdump and verified that the correct thing happens.

   You can't just losetup -o the Hurd partition and mke2fs on it
   since it will create to the end of the disk.img file, overwriting
   the swap parition.

   Does anyone know how to losetup -o a file and not have it map all
   the way to the end of the file?

sopwith% dd if=/dev/zero of=hurd bs=512 count=819441
819441+0 records in
819441+0 records out
sopwith% dd if=/dev/zero of=swap bs=512 count=212688
212688+0 records in
212688+0 records out
sopwith% sudo losetup /dev/loop1 hurd
sopwith% sudo losetup /dev/loop2 swap
sopwith% sudo mke2fs -O sparse_super -o hurd /dev/loop1
sopwith% sudo mkswap /dev/loop2
sopwith% sudo losetup -d /dev/loop1
sopwith% sudo losetup -d /dev/loop2 
sopwith% sudo dd if=hurd of=/dev/loop0 bs=512 seek=63 count=819441
819441+0 records in
819441+0 records out
sopwith% sudo dd if=swap of=/dev/loop0 bs=512 seek=819504 count=212688
212688+0 records in
212688+0 records out


4) The partitions can then be mounted an manipulated normally since our
   ext2 filesystem knows how long it is:
sopwith% sudo losetup -o 32256 /dev/loop1 disk.img
 
 
sopwith% ncftpget
ftp://alpha.gnu.org/pub/gnu/hurd/contrib/marcus/gnu-latest.tar.gz
sopwith% mkdir gnu
sopwith% sudo mount /dev/loop1 gnu
sopwith% ls gnu
lost+found
sopwith% cd gnu
sopwith% sudo tar --same-owner -zxvpf ../gnu-latest.tar.gz
sopwith% cd boot
sopwith% sudo mkdir grub
sopwith% cd grub
sopwith% sudo cp /usr/share/grub/i386-pc/* .
sopwith% sudo vi menu.lst


It seems to have worked just fine. I'm just trying to get the GRUB
stage1/stage2 stuff to work correctly now.


> What this all means in relation to your question about MBR's and boot records,
> etc., is that they are handled the way that they would be otherwise, just
> inside of the guest and not inside of the host.  This problem is a shortcoming
> of the host, and last time I knew it was on the list of TO-DO's for the LINUX
> kernel.  If you have partitioned inside of a file and formatted those
> partitions (inside of Bochs or plex86), then you should, however, be able to
> mount those partitions and use them as if they were physical--you just can't
> format them on the host.

I understand that the virtual machine handles them the same way. My
question is to exactly how they are handled in the first place. I
understand how LILO or GRUB gets run in the MBR. There are 446 bytes of
space available for bootloader code there. My question is where does
LILO or GRUB get put in a normal parition, because mke2fs seems to claim
the whole parition, without leaving any room at the front for boot
loading code.

--Ian




> 
> Ian Duggan wrote:
> 
> > Thanks. When I asked the original question, I really didn't understand
> > how disk geometry and partitions and all worked. I've since dug into
> > lots of information on the subject and am fairly secure in it now. These
> > directions confirm what I'm currently attempting.
> >
> > There is one bit of information that I still haven't squared away in my
> > head. I don't know of a good list to ask on, but perhaps since it is
> > related to this, someone here will know.
> >
> > When the machine first boots, it runs the code in the MBR and uses the
> > parition table there to find the partitions on the machine. If there is
> > an extended partition, it will have another 512 byte boot sector at the
> > beginning with its own partition table. My question is about regular
> > partitions. When I create a file system in an image file (loopback
> > mounted), it seems to use the entire space, including the initial 512
> > bytes. When LILO or some other boot loader is installed into a partition
> > rather than the MBR, where does it put its code and how is it run? I
> > thought there would be an initial 512 bytes in regular partitions that
> > could be used for bootcode, but the filesystem seems to use it... Where
> > does LILO place itself when it is installed in a regular partition?
> >
> > My goal is to get the Hurd booting under plex86. I'll report back any
> > progress I make.
> >
> > --Ian
> >
> > James McMechan wrote:
> > >
> > > Err, I don't think you have a "direct" geometry is the problem.
> > > your Grub is trying to load based on where the data was in partition 3 but
> > > your file does not have
> > > the unused space that partitions 1 and 2 used. Grub is trying to skip over
> > > to get to your kernel.
> > > To fix this you can use a sparse file created something like this
> > >
> > > use fdisk DEVICE2 to get CYCLINDERS/HEADS/SECTORS
> > > and PARTITION3's CYCLINDERSTART, CYCLINDEREND
> > >
> > > and then use dd to copy only the data you need
> > > Master boot record (MBR)
> > > dd if=DEVICE2 of=disk.img bs=512 count=1
> > > and then skipping all the other partitions
> > > dd if=DEVICE2 of=disk.img bs=$(( 512 * HEADS * SECTORS ))
> > > seek=CYCLINDERSTART \
> > > skip=CYCLINDERSTART count=$(( CYCLINDEREND-CYCLINDERSTART ))
> > >
> > > this will produce a spase file ( all unallocated cyclinders will read as
> > > zero and not take up space )
> > > which will have the same geometry as your real hard disk.
> > > This will show up in 'ls -l' as being the same size as your hard disk but
> > > 'df' will only show that sizeof(PARTITION3) is used
> > > |MBR|unallocated space|Boot sector Grub|Hurd
> > >
> > > ----- Original Message -----
> > > From: "Ian Duggan" <[EMAIL PROTECTED]>
> > > To: "plex86" <[EMAIL PROTECTED]>
> > > Sent: Friday, May 04, 2001 12:40 PM
> > > Subject: [plex86] Disk Image Layout
> > >
> > > >
> > > > Hi,
> > > >
> > > > I'm trying to create a bootable disk image for plex86 using another
> > > > partition that I have and am looking for assistance. I keep getting
> > > > drive geometry errors from GRUB, which I'm trying to use as a boot
> > > > loader.
> > > >
> > > > Here was the layout of the original partions
> > > >
> > > > DEVICE1: PARTITION1 (NTFS): Windows2k
> > > > DEVICE2: PARTITION1 (ext2): Linux
> > > > PARTITION2:(ext2): Hurd
> > > > PARTITION3:(swap): Swap (linux and hurd)
> > > >
> > > > I had LILO in the MBR of DEVICE1, which booted Win2k, or took you to the
> > > > boot sectors of D2P1 or D2P2. D2P1 had another LILO for booting various
> > > > Linux kernels in D2P1. D2P2 had GRUB for booting various Hurd/Gnumach
> > > > kernels in D2P2.
> > > >
> > > > So, I created an image of D2P2
> > > >
> > > > dd if=/dev/hdb2 of=disk.img
> > > >
> > > > So, I now have an image of D2P2 with Grub in it's boot sector, and
> > > > Hurd/Gnumach. Something like this:
> > > >
> > > > | Boot Sector Grub | Hurd |
> > > >
> > > > I think I need to create something like this:
> > > >
> > > > | MBR | Boot Sector Grub | Hurd |
> > > >
> > > > To try to boot it using plex86 and not have GRUB get the drive
> > > > geometries confused.
> > > >
> > > > Can someone point me to documentation on how I could lay out a proper
> > > > image file to boot with, or provide instructions on how to go about
> > > > creating it?
> > > >
> > > > --Ian
> > > >
> > > >
> 
> --
> Drew Northup, N1XIM

Reply via email to