The purpose of the article is to explain how to automate the fdisking of a hard drive by primarily using Sfdisk and the Perl Expect module. Why would you want to do this? Well, it can be one way of many ways to solve the problem where you need to have your bootable files for Linux before the 1024th cylinder. There are other ways to solve the boot problem, but we will stick to the cylinder method for this article. It also can be used to automatically partition new hard drives.
Sfdisk is a tool that allows you to change the partitioning of your hard disks through scripts. It also lets you get information about your hard drives. Although it is a pretty cool program, it does have limitations. It works and it has most of the necessary powers of fdisk, but not all of it.
Disk Druid is a program used by RedHat to initialize hard drives (change their geometry) before you install Linux to the hard drive.
Perl is a very very cool programming language. The "Expect" perl module is a module in perl which adds a relatively user-friendly way of making a script which automates commands. In other words, when you execute an Expect script, it types commands to the computer as though you were typing them -- like a macro but more advanced and usable for any console based program. Perl is just so cool to use with everything.
There are two other modules you have to install with the Expect perl module.
IO-Stty-.02.tar.gz
IO-Tty-0.02.tar.gz
To get the geometry of your hard drive,
/sbin/sfdisk -g /dev/hddHere is how to get the size (in bytes) of the total space of your hard drive,
/sbin/sfdisk -s /dev/hddHere is how to change the id of a partition 5 on your first hard drive to the Linux partition,
sfdisk --change-id /dev/hdd 5 83
Start, Size, ID, Bootable
Start = cylinder to start at (first available cylinder if left blank), Size = number of cylinders (all if left blank), ID = type of partition (Linux, Swap, MSDOS, or other), and Bootable = if this partition is bootable. There are other options, but we won't get into them in this article.
To make it so you have 1 partition of 136 cylinders, a second partition with 254 cylinders of the SWAP ID (82), and a third Linux partition bootable that grabs the rest of the space (ID = 83), make a file list this,
1,136 101,254,82 201,,83,*
and then issue this command to take this configuration and execute it on your slave hard drive on your secondary controller
/sbin/sfdisk /dev/hdd << Test.dataand then issue this command to see what you did
/sbin/sfdisk /dev/hdd
Again, it is highly recommended you read the manpage to figure out how to format this data file. Any fields you leave blank have default values described above.
Basically, with the Expect module, you can automate certain takes, which can be used later for a more sophisticated program - hint, hint of what is to come.
Save the script to "Dufus_Move.pl" and issue the command
chmod 755 Dufus_Move.pland then to do it on your slave hard drive on your secondary controller,
./Dufus_Move.pl d
Anyways, that script maximizes the number of cylinders.
Save the script to "Change_Cylinders.pl" and issue the command
chmod 755 Change_Cylinders.pland then to do it on your slave hard drive on your secondary controller,
./Change_Cylinders.pl d