rbsfou
01-14-2008, 10:27 AM
I've managed to squeeze the last few Kb from my 4GB CF card (and i've got an 8GB CF card on order to see whether this trick will work with that).
To start with my "Lifedrive" showed up as 3815.5mb in Card Info, but after applying this hack i get 3830.3mb. Ok, not a great deal of difference, but at least i've managed to get more than the bog standard.
It's all about the entry for Partition number 3 in the (raw) MBR, you just need to change this to fill up the card (and keep everything else the same!).
However, it's the "keeping everything else the same" bit that's tricky (OSX fdisk wipes entries with unknown partition types, linux fdisk throws a wobbly if your partitions don't fit the geometry of the disk - stupid, i don't care if my partition starts when a new cylinder does!, etc...).
So here's how i did it. Please note that you will need to know your card's raw device id (Linux users look in dmesg, Mac users can use Disk Utility.app).
As usual there is NO WARRANTY for this working on your particular setup. I can only say it worked for me. My method will erase your Lifedrive partition - it may be possible to do this without erasing, but i did not try this.
1. Back up your card's MBR (and KEEP A COPY SOMEWHERE!)
dd if=/dev/rdisk1 of=table.sct bs=512 count=1
cp table.sct orginal.sct
2. Now use a partition utility to extend partition 3 to the end of the card (here's a sample session with the OSX fdisk program):
pteranodon:~/LifeDrive/custom-rom rbsfou$ fdisk /dev/rdisk1
Disk: /dev/rdisk1 geometry: 995/128/63 [8027712 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: 06 0 1 1 - 16 80 15 [ 63 - 134016] DOS > 32MB
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 0B 22 29 29 - 991 94 29 [ 179263 - 7818112] Win95 FAT-32
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
And now we want to extend partition 3:
pteranodon:~/LD-Part-Tables rbsfou$ fdisk -e /dev/rdisk1
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> edit 3
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
3: 0B 22 29 29 - 991 94 29 [ 179263 - 7818112] Win95 FAT-32
Partition id ('0' to disable) [0 - FF]: [B] (? for help)
Do you wish to edit in CHS mode? [n] n
Partition offset [0 - 8027712]: [179263]
Partition size [1 - 7848449]: [7848449]
fdisk: 1> w
Writing MBR at offset 0.
fdisk: 1> exit
In this particular case, OSX fdisk assumed (correctly) that we want the partition to end on the last sector of the disk.
3. The CF card will now NOT BOOT in the LD in it's current state (at least with OSX fdisk, as entry 2 has been erased by re-writing the MBR), so we want to merge the values for partition 3 from this new MBR into the old one.
So to start with, we take a copy of this new MBR:
dd if=/dev/rdisk1 of=new.sct bs=512 count=1
4. Now what we need to do is get a decent HEX editor (i used 0xED.app), and make sure it is in "Overwrite" not "Insert" mode (it needs to stay at 512 bytes and end in 0x55AA).
5. Open both new.sct, and table.sct in the hex editor. Now copy the 16 bytes starting from offset 478 decimal / 0x1DE hex (this is the partition table entry for partition 3) from new.sct into table.sct (the exact means of doing this will of course vary depending on the hex editor you are using).
FYI The standard one looks like this:
00281D0B0BCF5DF13FBC0200804B7700
6. Now save table.sct (this is the original MBR with these 16 bytes changed), and write it back to the CF card:
sudo dd if=table.sct of=if=/dev/rdisk1 bs=512 count=1
7. Now pop the card back in your LD, boot, and re-format with Card Info. You should have more space in your Lifedrive now :D
The 3rd Partition
You might have noticed that you cannot mount /dev/disk1s3 or /dev/sdc3 (whatever!) directly on a machine. This is because the FAT32 filesystem does NOT start at sector 179263 (as indicated in the MBR), rather it is 63 bytes beyond that, at sector 179326.
I can only conclude that this is something to do with Drive Mode, whereby the first (0th) sector is a "pseudo-MBR" containing one FAT32 partition (which is somehow faked by the USB mass-storage code in Drive Mode.prc), and the first 62 sectors of the partition are left blank as is the convention (probably something archaic to do with cylinder boundaries; tho at least on a PC it leaves room for GRUB :) ).
I sucessfully changed Partition 3 to start at 179326, and it mounted straight away on my mac. YMMV. This means (in theory) you could edit the start to be here (keeping the end as it is), then use some kind of FAT32 filesystem and partition resizer util to non-destructively make the filesystem fit the physical disk. But you would then need to set the start back to sector 179263 (for the benefit of the palm os) before you copied the parition entry into the MBR (Step 3 onwards).
I have NOT done this as my LD isn't "Production" yet with data i want to preserve (as i'm still fiddling with it!).
Also if anyone knows what these 16-bytes mean and how to fiddle with them, then they could probably bypass much of this process.
I'd be interested to know if anyone else makes this work; as i said i'll be getting an 8gb card soon, so i'll post my results to this thread.
UPDATE : Initial tests with drive mode are successful, and a "secure erase" kept the partition table the same with Card Info still reporting 3830.3mib. Secure Erase did hang however when it was near completion.
To start with my "Lifedrive" showed up as 3815.5mb in Card Info, but after applying this hack i get 3830.3mb. Ok, not a great deal of difference, but at least i've managed to get more than the bog standard.
It's all about the entry for Partition number 3 in the (raw) MBR, you just need to change this to fill up the card (and keep everything else the same!).
However, it's the "keeping everything else the same" bit that's tricky (OSX fdisk wipes entries with unknown partition types, linux fdisk throws a wobbly if your partitions don't fit the geometry of the disk - stupid, i don't care if my partition starts when a new cylinder does!, etc...).
So here's how i did it. Please note that you will need to know your card's raw device id (Linux users look in dmesg, Mac users can use Disk Utility.app).
As usual there is NO WARRANTY for this working on your particular setup. I can only say it worked for me. My method will erase your Lifedrive partition - it may be possible to do this without erasing, but i did not try this.
1. Back up your card's MBR (and KEEP A COPY SOMEWHERE!)
dd if=/dev/rdisk1 of=table.sct bs=512 count=1
cp table.sct orginal.sct
2. Now use a partition utility to extend partition 3 to the end of the card (here's a sample session with the OSX fdisk program):
pteranodon:~/LifeDrive/custom-rom rbsfou$ fdisk /dev/rdisk1
Disk: /dev/rdisk1 geometry: 995/128/63 [8027712 sectors]
Signature: 0xAA55
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
1: 06 0 1 1 - 16 80 15 [ 63 - 134016] DOS > 32MB
2: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
3: 0B 22 29 29 - 991 94 29 [ 179263 - 7818112] Win95 FAT-32
4: 00 0 0 0 - 0 0 0 [ 0 - 0] unused
And now we want to extend partition 3:
pteranodon:~/LD-Part-Tables rbsfou$ fdisk -e /dev/rdisk1
fdisk: could not open MBR file /usr/standalone/i386/boot0: No such file or directory
Enter 'help' for information
fdisk: 1> edit 3
Starting Ending
#: id cyl hd sec - cyl hd sec [ start - size]
------------------------------------------------------------------------
3: 0B 22 29 29 - 991 94 29 [ 179263 - 7818112] Win95 FAT-32
Partition id ('0' to disable) [0 - FF]: [B] (? for help)
Do you wish to edit in CHS mode? [n] n
Partition offset [0 - 8027712]: [179263]
Partition size [1 - 7848449]: [7848449]
fdisk: 1> w
Writing MBR at offset 0.
fdisk: 1> exit
In this particular case, OSX fdisk assumed (correctly) that we want the partition to end on the last sector of the disk.
3. The CF card will now NOT BOOT in the LD in it's current state (at least with OSX fdisk, as entry 2 has been erased by re-writing the MBR), so we want to merge the values for partition 3 from this new MBR into the old one.
So to start with, we take a copy of this new MBR:
dd if=/dev/rdisk1 of=new.sct bs=512 count=1
4. Now what we need to do is get a decent HEX editor (i used 0xED.app), and make sure it is in "Overwrite" not "Insert" mode (it needs to stay at 512 bytes and end in 0x55AA).
5. Open both new.sct, and table.sct in the hex editor. Now copy the 16 bytes starting from offset 478 decimal / 0x1DE hex (this is the partition table entry for partition 3) from new.sct into table.sct (the exact means of doing this will of course vary depending on the hex editor you are using).
FYI The standard one looks like this:
00281D0B0BCF5DF13FBC0200804B7700
6. Now save table.sct (this is the original MBR with these 16 bytes changed), and write it back to the CF card:
sudo dd if=table.sct of=if=/dev/rdisk1 bs=512 count=1
7. Now pop the card back in your LD, boot, and re-format with Card Info. You should have more space in your Lifedrive now :D
The 3rd Partition
You might have noticed that you cannot mount /dev/disk1s3 or /dev/sdc3 (whatever!) directly on a machine. This is because the FAT32 filesystem does NOT start at sector 179263 (as indicated in the MBR), rather it is 63 bytes beyond that, at sector 179326.
I can only conclude that this is something to do with Drive Mode, whereby the first (0th) sector is a "pseudo-MBR" containing one FAT32 partition (which is somehow faked by the USB mass-storage code in Drive Mode.prc), and the first 62 sectors of the partition are left blank as is the convention (probably something archaic to do with cylinder boundaries; tho at least on a PC it leaves room for GRUB :) ).
I sucessfully changed Partition 3 to start at 179326, and it mounted straight away on my mac. YMMV. This means (in theory) you could edit the start to be here (keeping the end as it is), then use some kind of FAT32 filesystem and partition resizer util to non-destructively make the filesystem fit the physical disk. But you would then need to set the start back to sector 179263 (for the benefit of the palm os) before you copied the parition entry into the MBR (Step 3 onwards).
I have NOT done this as my LD isn't "Production" yet with data i want to preserve (as i'm still fiddling with it!).
Also if anyone knows what these 16-bytes mean and how to fiddle with them, then they could probably bypass much of this process.
I'd be interested to know if anyone else makes this work; as i said i'll be getting an 8gb card soon, so i'll post my results to this thread.
UPDATE : Initial tests with drive mode are successful, and a "secure erase" kept the partition table the same with Card Info still reporting 3830.3mib. Secure Erase did hang however when it was near completion.