Hey all!.. I am currently working on the file system and volume architecture of my os. So in order to test my interface, i need to make a hard disk image which is around 100MB or so which i can use with Bochs. I want partitions and a filesystem in this image.
So i used the losetup to create /dev/loop0 and then created a partition table on it using fdisk. But how do i create a filesystem on the partitions? The partitions do not appear as /dev/hdc1 /dev/hdc2 etc as for a normal hard disk. Besides who exactly creates those /dev/hdc1,/dev/hdc2.... from /dev/hdc when linux creates devices...?
I could run a linux image in Bochs and make it operate directly on the hard disk image. But this seems like a problem i feel i should solve.
Mounting a loopback hard disk
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
- karloathian
- Posts: 22
- Joined: Fri Mar 28, 2008 12:09 am
Re: Mounting a loopback hard disk
Using the should sputter out something like this:
You can then run the losetup command but offset to a specific partition of the disk as follows:
I used an offset of 32256 here because the partition started at block 63 and each block is 512 bytes in length. ( 63 * 512 = 32256 ). With that in hand you can now use a mkfs command on that new loopback device.
I hope that was what you were looking for.
Code: Select all
fdisk -ul MyDisk.img
Code: Select all
128 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Device Boot Start End Blocks Id System
MyDisk.img1 * 63 3515903 1757920+ 83 Linux
MyDisk.img2 3515904 4193279 338688 82 Linux swap / Solaris
Code: Select all
losetup -o 32256 /dev/loop1 MyDisk.img
I hope that was what you were looking for.
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Re: Mounting a loopback hard disk
Oh great... I was trying to find that 'offset' kind of thing in mkfs... But never thought of finding it in losetup... Thanx a lot...
- salil_bhagurkar
- Member
- Posts: 261
- Joined: Mon Feb 19, 2007 10:40 am
- Location: India
Re: Mounting a loopback hard disk
And yes.. like I said before, who creates the /dev/hdc1, /dev/hdc2.... from the single /dev/hdc in linux during the boot time?
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
Re: Mounting a loopback hard disk
The kernel does, on Linux/FreeBSD anyway... See Devfs on Wikipedia.salil_bhagurkar wrote:And yes.. like I said before, who creates the /dev/hdc1, /dev/hdc2.... from the single /dev/hdc in linux during the boot time?
On traditional Unix systems, device nodes are created by a shell script... /dev/MAKEDEV.