Pendrive geometryForum: USB booting Topic: Pendrive geometry started by: JohnS Posted by JohnS on 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. Posted by Z038 on Dec. 31 2004,20:02
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. Posted by Z038 on Jan. 02 2005,05:51
Success!!! JohnS, your procedure worked perfectly for me! I'm up and running on my pen drive now. Thank you. Posted by Z038 on Jan. 02 2005,06:23
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.
Posted by NorthBear on Jan. 05 2005,23:04
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... Posted by cbagger01 on Jan. 06 2005,04:13
DSL is normally booted up with syslinux or isolinux to allow entry of custom boottime parameters.So having a USB boot system that uses the same tools allows people to boot up via USB device using the same methods that they are already used to with the livecd. Posted by brad on Jan. 07 2005,08:47
hmk, maybe that's the reason I can't get my stick booting..how comes that I get an odd number of sectors when using the formular "total_sectors / 32 / number_of_heads = no_of_cylinders" ? Bytes: 262144000 Total Sectors: 262144000 bytes / 512 = 512000 sectors Cylinders: 512000 sectors / 32 / 9 heads = 1777,77778 Or is there a mistake anywhere? I was following a guid which told me to do a "sfdisk -S 32 /dev/sda" and then setting the partitions. Could that cause any trouble? Your help is greatly appriciated! Below the output of fdisk and sfdisk: sfdisk output ------------- Disk /dev/sda: 1777 cylinders, 9 heads, 32 sectors/track Units = cylinders of 147456 bytes, blocks of 1024 bytes, counting from 0 Device Boot Start End #cyls #blocks Id System /dev/sda1 * 0+ 539 540- 77759+ 6 FAT16 /dev/sda2 540 1776 1237 178128 6 FAT16 /dev/sda3 0 - 0 0 0 Empty /dev/sda4 0 - 0 0 0 Empty fdisk output ------------ Disk /dev/sda: 262 MB, 262144000 bytes 9 heads, 32 sectors/track, 1777 cylinders Units = cylinders of 288 * 512 = 147456 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 540 77759+ 6 FAT16 /dev/sda2 541 1777 178128 6 FAT16 Bytes: 262144000 Total Sectors: 262144000 bytes / 512 = 512000 sectors Cylinders: 512000 sectors / 32 / 9 heads = 1777,77778 Posted by phraque on Jan. 07 2005,12:58
(brad)Also Im getting the message "Total number of sectors not a multiple of sectors per track" which is not correct: 512000 / 32 = 16000 Posted by cbagger01 on Jan. 07 2005,18:35
Try formatting your drive with the Dellll bootable USB key utility program for MSWindows:< http://www.bay-wolf.com/utility/usb_memkey.zip > Then test and make sure that the usb key will boot. If so, then boot into DSL and overwrite the key with the Install to pendrive function. The Dell utility should create a partition with the correct geometry. Then you can use the newly created partition for a bootable linux. Posted by tbaleno on Aug. 27 2005,15:27
My math isn't so good, could someone give me the correct geometry if mine is showing 133674 cylinders, 255 heads, 63 sectors/track? Its a san disk 4GB cruzer mini pendrive but fdisk and others seem to show 1000GB.
Posted by cusco on Aug. 28 2005,14:52
Im having the same problem! instead o a 4GB its a 1GB cruzer mini
how do I change it to 32? I have Disk /dev/sda: 993 cylinders, 32 heads, 63 sectors/track 993*32*63 = 2001888 now when it says
I also don't quite understand: should I do 2001888/32(as if it were 32, the sectors p/ track are 63)/32 ? then its 1954.96875 what am I missig here? please .. thanks in advance [EMAIL=]Tiago@Geada.co.uk[/EMAIL] |