How-to-Make-a-Computer-Operating-System icon indicating copy to clipboard operation
How-to-Make-a-Computer-Operating-System copied to clipboard

Explain losetup offset in diskimage.sh

Open akkartik opened this issue 11 years ago • 9 comments

Is it to make room for the grub MBR?

akkartik avatar Nov 30 '13 18:11 akkartik

No it's not, it's the offset of the first partition: https://github.com/SamyPesse/How-to-Make-a-Computer-Operating-System/blob/master/Chapter-3/README.md#create-a-disk-image-for-our-kernel-and-grub

SamyPesse avatar Dec 01 '13 16:12 SamyPesse

Thanks. But I'm still confused: why isn't the offset 0? Why do we have to use the computation in your link?

I also am trying to go over the computation at your link. Locally, the output of fdisk -l -u c.img:

Disk sdk/c.img: 2 MB, 2097152 bytes
1 heads, 5 sectors/track, 819 cylinders, total 4096 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9cbdff7d

    Device Boot      Start         End      Blocks   Id  System
sdk/c.img1   *           1           4           2   83  Linux

On the VM:

You must set cylinders.
You can do this from the extra functions menu.

Disk c.img: 0 MB, 0 bytes
1 heads, 5 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x9cbdff7d

Device Boot      Start         End      Blocks   Id  System
c.img1   *           1           4           2   83  Linux

I see where these show the size of each sector, but not where the 63 comes from. From http://en.wikipedia.org/wiki/Cylinder-head-sector#Sectors I learn that PCs usually have 63 sectors per track. Is that it?

akkartik avatar Dec 01 '13 19:12 akkartik

Did you change the disk geometry for your c.img1? or do you use the same geometry of c.img?

The offset is not 0 because the partition starts after some boot sectors.

SamyPesse avatar Dec 01 '13 19:12 SamyPesse

I didn't mean to change the geometry, I think I used the same geometry. And oddly enough the one with the 'must set cylinders' message is what shows hello correctly.

akkartik avatar Dec 01 '13 20:12 akkartik

Hum, in vagrant I have:

vagrant@lucid32:/vagrant/sdk$ fdisk -l -u c.img
You must set cylinders.
You can do this from the extra functions menu.

Disk c.img: 0 MB, 0 bytes
16 heads, 63 sectors/track, 0 cylinders, total 0 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xe8c36f7f

Device Boot      Start         End      Blocks   Id  System
c.img1   *          63        4031        1984+  83  Linux

Locally what os are you using? do you have the same thing with vagrant?

SamyPesse avatar Dec 02 '13 16:12 SamyPesse

Host OS: Ubuntu 12.04.1 Vagrant OS: Ubuntu 10.04.4

Hmm, I installed vagrant from apt-get. Is this a problem?

akkartik avatar Dec 02 '13 20:12 akkartik

I have different results in Vagrant from when running on bare metal.

mk270 avatar Dec 04 '13 20:12 mk270

I have got the same message

16 heads, 63 sectors/track, 0 cylinders, total 0 sectors Units = sectors of 1 * 512 = 512 bytes

but why 0 cylinders?

liuluheng avatar Dec 08 '13 14:12 liuluheng

just something from fdisk:

the -u option, should receive the format wanted. The default is set if just "-u" is given. The default is different in different OS or Linux flavors. To avoid it you should use:

/sbin/fdisk -u=cylinder ...

vpereira avatar Feb 08 '15 17:02 vpereira