Data Partition
From Entuura
For OpenWRT on Alix, we like the fact that the install image is one little squashfs, and that it does not care about the actual size of the CF card where it lives. We'd like to have a data partition live out at the END of the CF card, so that the OS image can be reapplied and will "re-find" the data partition.
Here are some notes on how to do this.
root@Entuura-Leeds:/proc# cat partitions major minor #blocks name 3 0 990864 hda 3 1 4504 hda1 3 2 49360 hda2 31 0 49344 mtdblock0 31 1 39552 mtdblock1 7 0 754416 loop0
This lets us easily see if the data partition exists yet, and also gives us the number of blocks of the CF card. This is a 1 gig card, so these blocks must be 1024 bytes.
dmesg says:
hda: 1981728 sectors (1014 MB) w/1KiB Cache, CHS=1966/16/63
Sectors are 512 bytes, and sure enough, 1981728 (number of sectors reported by fdisk) is double 990864 (number of blocks reported by /proc/partition).
fdisk says this:
root@Entuura-Leeds:/proc# fdisk -l -u /dev/hda Disk /dev/hda: 1014 MB, 1014644736 bytes 16 heads, 63 sectors/track, 1966 cylinders, total 1981728 sectors Units = sectors of 1 * 512 = 512 bytes Disk identifier: 0x00000000
Device Boot Start End Blocks Id System /dev/hda1 * 63 9071 4504+ 83 Linux /dev/hda2 9135 107855 49360+ 83 Linux
So, it all comes together. The length of hda2 is 107855 - 9135 = 98720 sectors. Divided by two, that's 49360 blocks, like like /proc/partitions says.
Finally, we need a way to figure out the highest sector number that fdisk will take. That comes from doing it all backwards. /proc/partition says that hda has 990864 blocks. Multiply it by two and you get 1981728. Sectors are zero-based, so subtract one. The higest sector number is 1981727, just like fdisk thinks:
root@Entuura-Leeds:/sys/module/block2mtd/parameters# fdisk -u /dev/hda Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 First sector (9072-1981727, default 9072):
Yay, so putting it all together we:
- get length of hda from /proc/partitions
- multiply by 2, minus 1 to get the end sector
- choose an appropriate buffer after hda2 for start sector
- put all of it into fdisk (but actually, you can just let fdisk calculate the end sector itself if you want)
Here's what goes into the UCI-managed fstab:
fstab.@mount[0]=mount fstab.@mount[0].fstype=ext3 fstab.@mount[0].options=rw,sync fstab.@mount[0].enabled=1 fstab.@mount[0].device=/dev/hda3 fstab.@mount[0].target=/data/fixed
The code that does this stuff is in init.d/et-startup.
