Friday, September 18, 2009

HowTo: Mount EXT2FS partitions with inode 256 on FreeBSD

Mounting ext2/ext3 slices (or "partitions" in the Linux world) is easy on FreeBSD... if the filesystem was NOT created with inode 256 that is!

If you are one of those unlucky bastards this post presents the required steps on how to patch the FreeBSD 7.2 kernel module that mounts ext2/ext3 filesystems.

First let's begin by installing the sysutils/e2fsprogs application that provides tune2fs which will allow us to confirm that the ext2/ext3 filesystem was in fact created with inode 256. Assuming that the target slice is in the /dev/ad4 disk:
  • % su
  • # cd /usr/ports/sysutils/e2fsprogs
  • # make install clean
  • # rehash
  • # fdisk /dev/ad4
******* Working on device /dev/ad4 *******
parameters extracted from in-core disklabel are:
cylinders=395136 heads=16 sectors/track=63 (1008 blks/cyl)

Figures below won't work with BIOS for partitions not in cyl 1
parameters to be used for BIOS calculations are:
cylinders=395136 heads=16 sectors/track=63 (1008 blks/cyl)

Media sector size is 512
Warning: BIOS sector numbering starts with sector 1
Information from DOS bootblock is:
The data for partition 1 is:
sysid 131 (0x83),(Linux native)
start 63, size 80262 (39 Meg), flag 80 (active)
beg: cyl 0/ head 1/ sector 1;
end: cyl 4/ head 254/ sector 63
The data for partition 2 is:
sysid 130 (0x82),(Linux swap or Solaris x86)
start 80325, size 1012095 (494 Meg), flag 0
beg: cyl 5/ head 0/ sector 1;
end: cyl 67/ head 254/ sector 63
The data for partition 3 is:
sysid 131 (0x83),(Linux native)
start 1092420, size 10008495 (4886 Meg), flag 0
beg: cyl 68/ head 0/ sector 1;
end: cyl 690/ head 254/ sector 63
The data for partition 4 is:
sysid 15 (0x0f),(Extended DOS (LBA))
start 11100915, size 350907795 (171341 Meg), flag 0
beg: cyl 691/ head 0/ sector 1;
end: cyl 1023/ head 254/ sector 63
  • # tune2fs -l /dev/ad4s1 | grep -i 'inode size'
fdisk is used to list the slices that exist on the disk. Sysid 131 means that a ext2/ext3 slice exists and this is target for tune2fs.

Next let's fetch the patch:
  • % wget http://pflog.net/~floyd/ext2fs.diff
In alternative, get the patch from here:
  • % wget http://pastebin.ca/raw/1280738
Now that we have the patch, let's proceed by applying it and build the patched module:
  • # cd /usr/src/sys/gnu/fs
  • # patch < /path/to/patch
  • # cd /usr/src/sys/modules/ext2fs
  • # make depend ; make obj ; make ; make ; make install ; make unload ; make load ; make clean
This way you'll build all dependencies for the module, build the module itself, install it, unload the current loaded module and finally load the new one.

Having the new module loaded you can now successfully mount your ext2/ext3 filesystem:
  • # mount -t ext2fs /dev/ad6s1 /mnt
That's it!

References:
kern/124621: [ext3] [patch] Cannot mount ext2fs partition
man mount
sysutils/e2fsprogs

3 comments:

Shao said...

Thanks a lot for the instructions!

tangram said...

Glad it helped ;)

Take care.

Anonymous said...
This comment has been removed by a blog administrator.