On Thu, 17 Jun 1999, Tigran Aivazian wrote:
> Can anyone tell me if it is possible to manipulate a disk image with
> multiple partitions? I wanted to make a file that looks like
> "hda: hda1 hda2" for booting Linux (or some other OS) under bochs and I
My recollection from the time I tried bochs was that I created a big block
of zeros to be the drive and partitioned it from (blech) DOS fdisk running
inside bochs, booted from a virtual floppy. The same could be done with
Linux fdisk running inside bochs, or I'm sure you could hack up fdisk to
work on a file as though it were a partition.
Yes. No hacking required, this works already.
For example
% dd if=/dev/zero of=mydisk bs=1024 count=1024
Now we have a 1 MiB disk filled with zeroes.
% /sbin/sfdisk -C 4 -H 16 -S 32 mydisk << EOI
,2,
,,
EOI
Since a file has no geometry, we have to pick one ourselves.
Note that 4*16*32*512 bytes = 1 MiB, so the geometry fits
the size of the disk file.
The sfdisk input asks for a 2-cylinder partition, followed
by a partition that contains the rest. Let us verify this worked.
% /sbin/sfdisk -l -uS mydisk
Units = sectors of 512 bytes, counting from 0
Device Boot Start End #sectors Id System
mydisk1 1 1023 1023 83 Linux
mydisk2 1024 2047 1024 83 Linux
mydisk3 0 - 0 0 Empty
mydisk4 0 - 0 0 Empty
The partitions inside the file can be accessed by appropriately setting
the offset address for your loop device (see man 8 losetup). I'm sure
there's a magic method of calculating the offset but I don't know it
Yes, let us do it. Setup /dev/loop1 on mydisk1 and /dev/loop2 on mydisk2.
% losetup /dev/loop1 mydisk -o 512
% losetup /dev/loop2 mydisk -o 524288
(where the offsets come from 1*512 and 1024*512).
% mke2fs -F /dev/loop1 511
% mke2fs -F /dev/loop2
% mkdir /a1 /a2
% mount /dev/loop1 /a1
% mount /dev/loop2 /a2
(the 511 is 1023/2, the number of blocks of size 1024 in mydisk1;
note that /dev/loop1 extends to the end of mydisk - the loop device
is given a starting offset, but no length).
Now at first sight all seems to work.
Conclusion: Tigran's question `is it possible to manipulate
a disk image with multiple partitions' may be answered
affirmatively for a very weak interpretation of `possible'.
The loop device would require several enhancements before
this type of thing would be really convenient.
(Wish list:
(i) a loop setup ioctl that allows one to give offset and length,
so that one can specify a `window' on a file.
(ii) partitions on a loop device.
Both are trivial to add.)
Andries
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/