JohnS
Group: Members
Posts: 23
Joined: Dec. 2004 |
|
Posted: Dec. 31 2004,18:53 |
|
While trying to get pendrive booting to work I learned a lot about changing the geometry on a pendrive. I thought I'd share some of that here.
First off it appears that the geometry on a pendrive is NOT fixed in hardware, I have been able to change the parameters and have it work fine both in DSL and WinXP, the upshot is that if your pendrive doesn't have parameters you like, change them!
The best tool for doing this is sfdisk under DSL. Its MUCH easier to manipulate partitions using sfdisk under DSL than using windows tools, even if you will then be using it under windows. When playing around with the geometry parameters make sure you use the -f (thats the FORCE) option to sfdisk, otherwise it won't change some of the parameters. The reason this works is that there really are no heads or cylinders, its a bunch of bytes, the heads and such are just to keep the disk drivers happy.
Why would you want to change the parameters? When making a bootable partition you want to have 32 sectors per track and 1024 or less cylinders in the boot partition. Some pendrives come with strange parameters and if you change the sectors per track, the number of cylinders might go over 1024. (I know, this happened to me) The solution is to use sfdisk to change all the parameters.
Here is the sequence I would use to generate two partitions, one for booting and the other for storing .dsl files and backups etc.
First look at the current partition table and write down the parameters, if you make a mistake you can put it back the way it was!
sudo su -- you need to do everything as root
sfdisk -l /dev/sda
The -l lists the partition table and tells you the current geometry. NOTE: use /dev/sda NOT sda1. sda referes to the whole drive, sda1 refers to the first partition on that drive, since sfdisk works on the partition table itself, specifying a specific partition will not work.
Write down the number of cylinders, heads and sectors. Multiply all three of these numbers together, this gives you the total number of sectors on the drive, thats important to know when you start changing the parameters, you don't want to wind up telling sfdisk there are more sectors than what is actually there!!
Now look at the number of sectors per track, if that is NOT 32 you will need to change it to 32. Using 32 calculate the number of cylinders if you use the current number of heads. total_sectors / 32 / number_of_heads = no_of_cylinders. You really only need the number to be less than 1024 for the boot partition, which is usually 64 MB or sometimes 128 MB. Since a sector is 512 bytes you can divide the 64million by 512 to get the total number of sectors. Use the above equation to figure out the no of cylinders in your boot partition, if greater than 1024, increase the number of heads. The max number of heads is usually speced as 32 which should work for almost all cases. If you change the number of heads to get the boot partition right make sure you recalculate the total number of cylinders you need for the whole drive. You have to use the same number of heads and sectors for ALL partitions on the drive, the only thing you can vary per partition is the number of cylinders.
Now that you have the number of sectors per track, number of heads and number of cylinders for the whole drive you can set those with sfdisk:
sfdisk -f -Cnumcyl -Hnumheads -Snumsectors /dev/sda
If these numbers are different than the previous parameters it will tell you so, but thats fine, we are chaning them!
At this point it will be asking you for the parameters for the partitions, the first one will be for the boot partition so it gets some special arguments: here is what one might look like: sda1:0 500 6 *
sfdisk prints the sda1: you type in the rest. The 0 means it starts at cylinder 0, the 500 is 500 cylinders long (use whatever you calculated for the boot partition) the 6 is type 6 which is a FAT16 partition and the * means its a bootable partition. If you just hit enter for the next line it makes the rest of the drive as sda2 and makes it a nonbootable linux partition. Just hit enter for sda3 and sda4 and it won't make a partition for them since all the space is used up with sda1 and sda2. Sfdsik asks if you want to write to the disk, type y<enter> and you are done.
At this point reboot dsl so the system sees the new parameters.
You can now format the partitions:
mkdosfs /dev/sda1 mk2fs /dev/sda2
reboot again and you can mount the partitions.
If you are using the install to pendrive command from DSL, don't format or mount the root partition. (sda1)
I hope this helps others get their pendrives properly partitioned.
John S.
|