Search Members Help

» Welcome Guest
[ Log In :: Register ]

Mini-ITX Boards Sale, Fanless BareBones Mini-ITX, Bootable 1G DSL USBs, 533MHz Fanless PC <-- SALE $200 each!
Get The Official Damn Small Linux Book. DSL Market , Great VPS hosting provided by Tektonic
Pages: (3) </ [1] 2 3 >/

[ Track this topic :: Email this topic :: Print this topic ]

reply to topic new topic new poll
Topic: Pendrive geometry, Changing geometry parameters on a pendri< Next Oldest | Next Newest >
JohnS Offline





Group: Members
Posts: 23
Joined: Dec. 2004
Posted: Dec. 31 2004,18:53 QUOTE

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.
Back to top
Profile PM 
Z038 Offline





Group: Members
Posts: 16
Joined: Dec. 2004
Posted: Dec. 31 2004,20:02 QUOTE

Ah, very informative post, JohnS.  Thanks.  

I just posted my experiences with sfdisk here but I haven't gotten my USB to boot in the resulting configuration yet.  I believe I'm going to try again as you suggest after I've diddled around a bit more with my current setup.  I see you are changing the partition type, which I didn't do.  

The best thing about having a difficult time installing to and booting from my pen drive, for this Linux newbie anyway, is that I'm learning a lot about Linux and sundry esoteric commands that I wouldn't otherwise learn.
Back to top
Profile PM 
Z038 Offline





Group: Members
Posts: 16
Joined: Dec. 2004
Posted: Jan. 02 2005,05:51 QUOTE

Success!!!  JohnS, your procedure worked perfectly for me!   :)

I'm up and running on my pen drive now.  Thank you.
Back to top
Profile PM 
Z038 Offline





Group: Members
Posts: 16
Joined: Dec. 2004
Posted: Jan. 02 2005,06:23 QUOTE

Oh, I almost forgot to mention, I still had to export MTOOLS_SKIP_CHECK=1 before executing mkdosfs, because it said I had an odd number of sectors.
Back to top
Profile PM 
NorthBear Offline





Group: Members
Posts: 2
Joined: Jan. 2005
Posted: Jan. 05 2005,23:04 QUOTE

I only had luck booting a USB pen drive (Lexar 128MB) after changing the drive's geometry.

I thought the old "less than 1024 cylinders" thing was behind us years
ago. It doesn't seem to be a BIOS issue, is it something to do with
syslinux?

Just curious, why is syslinux used instead of lilo or such? Anyone know?

Thanks...
Back to top
Profile PM 
10 replies since Dec. 31 2004,18:53 < Next Oldest | Next Newest >

[ Track this topic :: Email this topic :: Print this topic ]

Pages: (3) </ [1] 2 3 >/
reply to topic new topic new poll
Quick Reply: Pendrive geometry

Do you wish to enable your signature for this post?
Do you wish to enable emoticons for this post?
Track this topic
View All Emoticons
View iB Code