1 #!/usr/bin/perl -w 2 # 3 # Copyright (c) International Business Machines Corp., 2000 4 # 5 # This program is free software; you can redistribute it and/or modify 6 # it under the terms of the GNU General Public License as published by 7 # the Free Software Foundation; either version 2 of the License, or 8 # (at your option) any later version. 9 # 10 # This program is distributed in the hope that it will be useful, 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See 13 # the GNU General Public License for more details. 14 # 15 # You should have received a copy of the GNU General Public License 16 # along with this program; if not, write to the Free Software 17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 18 # 19 20 # 21 # FILE(s) : maimparts 22 # DESCRIPTION : Takes the disk device name (ex: hda) and number of iterations 23 # to run thru and then rips the drive into a defined number of 24 # partitions ($parts). This sets up the device for partbeat 25 # and backbeat which are called after setup occurs. 26 # 27 # WARNING!!! : The device you specify on the command line (hda/sda/etc) will be 28 # blown away...smoking any important data, programs, OS, etc. 29 # Don't specify a device name that you don't want to wipe out. 30 # YOU HAVE BEEN WARNED! 31 # 32 # AUTHOR : Jeff Martin (martinjn (at] us.ibm.com) 33 # HISTORY : 34 # 35 36 # target is device to split into partions 37 $target=$ARGV[0]; 38 $iterations=$ARGV[1]; 39 # part is the number of partitions to split the drive into (max is 4) 40 $parts=3; 41 # fsid is the partition id or type (83 is linux native) 42 $fstype=$ARGV[2]; 43 $fsid=0x83; 44 45 if (!$ARGV[0]) { 46 print "Usage: maimparts [target device ie: hda or sda] [iterations]\n"; 47 exit; 48 } 49 # run sfdisk to display device geometry and rip out info 50 # (specifically cylinders) 51 $Geom = `/sbin/sfdisk -g /dev/$target`; 52 chomp $Geom; 53 ($Junk,$Temp1) = split(/\: /,$Geom,2); 54 ($Cyl,$Heads,$Sec) = split(/\, /,$Temp1,3); 55 ($Cyl,$Junk) = split(/ /,$Cyl,2); 56 ($Heads,$Junk) = split(/ /,$Heads,2); 57 ($Sec,$Junk) = split(/ /,$Sec,2); 58 59 # determine partition size to create (force int so we don't 60 # try to use 1/2 a cylinder!) 61 $psize = int($Cyl/$parts); 62 63 # create a config file in /tmp for sfdisk creation run 64 open(CONFIG,">/tmp/part.cfg") || 65 die "Couldn't create /tmp/part.cfg\n"; 66 for($i=1;$i<=$parts;$i++) { 67 printf(CONFIG ",%d,%x\n",$psize,$fsid); # write the lines in cfg 68 } 69 close(CONFIG); 70 71 # create the partitions! 72 `sfdisk --force /dev/$target < /tmp/part.cfg`; 73 74 #run partbeat on the partitions 75 for ($k=1;$k<=$parts;$k++) { 76 $part[$k] = sprintf("%s%d",$target,$k); 77 $tmp = `./partbeat /dev/$target$k $iterations $fstype`; 78 print $tmp; 79 } 80 $tmp = `./backbeat /dev/$part[1] /dev/$part[2] /dev/$part[3]`; 81 print $tmp; 82