OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 7:59 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 5:29 am 
Offline

Joined: Mon Dec 19, 2016 5:15 am
Posts: 9
Hey everyone!

This might be a stupid question, but: Every source of documentation for ext2 that I've found has specified that the ext2 superblock is always at offset 1024 (or 0x400, or LBA 2 with 512 byte sectors), though when I create a qemu image and create an empty ext2 file system on it the superblock is located at offset 2560 (or 0xA00, or LBA 5). fsck still correctly identifies the file system, so it's obvious that I'm misunderstanding something here.

Here is my process for creating the ext2 volume:

Code:
# qemu-img create -f raw harddrive.img 512M
# kpartx -a harddrive.img
# mkfs.ext2 /dev/mapper/loop0p1
Discarding device blocks: done                           
Creating filesystem with 524284 1k blocks and 131072 inodes
Filesystem UUID: 73f5f38b-d312-4af2-afda-ac34f356a6da
Superblock backups stored on blocks:
   8193, 24577, 40961, 57345, 73729, 204801, 221185, 401409

Allocating group tables: done                           
Writing inode tables: done                           
Writing superblocks and filesystem accounting information: done


Any help on this would be greatly appreciated!


Top
 Profile  
 
 Post subject: Re: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 5:44 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
The super block is always located at offset 1024 from the start of the partition (not the start of the disk).


Top
 Profile  
 
 Post subject: Re: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 5:50 am 
Offline

Joined: Mon Dec 19, 2016 5:15 am
Posts: 9
Ah, I figured it'd have something to do with partitions. Is there any other reliable way to find the superblock (since I guess it won't always be at offset 2560 then)?


Top
 Profile  
 
 Post subject: Re: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 5:55 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
You read the partition table (located at a fixed point) to determine where each partition starts. Then you can read the block at offset 1024 from the start of each partition to determine whether they contain an ext2 filesystem.


Top
 Profile  
 
 Post subject: Re: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 6:16 am 
Offline
Member
Member

Joined: Sun Feb 01, 2009 6:11 am
Posts: 1070
Location: Germany
HackerCow wrote:
Here is my process for creating the ext2 volume:

Code:
# qemu-img create -f raw harddrive.img 512M
# kpartx -a harddrive.img
# mkfs.ext2 /dev/mapper/loop0p1
Discarding device blocks: done                           
[...]

I don't believe you. When run on a completely empty disk image (as created by qemu-img create), kpartx won't create a /dev/mapper/loop0p1, because there are no partitions on the image yet.

_________________
Developer of tyndur - community OS of Lowlevel (German)


Top
 Profile  
 
 Post subject: Re: ext2 superblock offset
PostPosted: Mon Dec 19, 2016 11:34 am 
Offline
Member
Member
User avatar

Joined: Sat Mar 31, 2012 3:07 am
Posts: 4594
Location: Chichester, UK
I'm guessing that the OP has forgotten to mention the partition creation step. But the numbers given are correct for the first (or only) partition on a hard disk of that size.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 216 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group