#!/usr/bin/perl #### This perl script is copyrighted by Mark Nielsen, 5-2000. #### This script falls under the GNU License. #### DO NOT RUN THIS SCRIPT. ##### just look at what is it trying to do. #### It is going to be merged with a perl script to make bootable cdroms so that #### you can install a burned image of Linux onto a computer from a cdrom. $Pre_Partitioning = ["Leave Partition 1 or 2 alone", {Item=>"delete",Name=>"Delete 1 and 2"}, {Item=>"leave",Name=>"Leave 1 and 2 alone"}, ]; $Pre_Partition = $Pre_Partitioning->[1]; $Drives = []; $Drives->[0] = "Choose a hard drive to burn."; $Drives->[1] = {Item=>"hda",Valid=>1}; $Drives->[2] = {Item=>"hdb",Valid=>1}; $Drives->[3] = {Item=>"hdc",Valid=>1}; $Drives->[4] = {Item=>"hdd",Valid=>1}; $Drives->[5] = {Item=>"sda",Valid=>0}; $Drives->[6] = {Item=>"sdb",Valid=>1}; $Drives->[7] = {Item=>"sdc",Valid=>1}; $Drives->[8] = {Item=>"sdd",Valid=>1}; $Drive = $Drives->[1]; my $HostName = `hostname`; chomp $HostName; if ($HostName eq "c1.local") {$Drives->[2]->{Valid}=0}; $Part1 = []; $Part1->[0] = "Operating system on Partition 1."; $Part1->[1] = {Item=>"None",Name=>"None",Valid=>1}; $Part1->[2] = {Item=>"Windoze98_3gig.img.gz",Name=>"Win98",Valid=>1}; $Part1->[3] = {Item=>"WindowsNT40.img.gz",Name=>"WinNT40",Valid=>1}; $Part1->[4] = {Item=>"WinNT40Server",Valid=>1}; $Partition1 = $Part1->[1]; $Part2 = []; $Part2->[0] = "Operating system on Partition 2."; $Part2->[1] = {Item=>"None",Name=>"None",Valid=>1}; $Part2->[2] = {Item=>"Cdrom",Name=>"Cdrom",Valid=>1}; $Part2->[3] = {Item=>"Windoze98_3gig.img.gz",Name=>"Win98",Valid=>1}; $Part2->[4] = {Item=>"Extended",Valid=>1}; $Partition2 = $Part2->[2]; $Videos=["Video Card for Xwindows", {Item=>"XF86Config_VGA",Name=>"Regular VGA", Server=>"XF86_VGA16"}, {Name=>"VooDoo 3 2000 16 meg",Item=>"XF86Config_16_VooDooIII_2000",Server=>"XF86_SVGA"}, {Name=>"VooDoo 3 3000 16 meg",Item=>"XF86Config_16_Voodoo3_3000",Server=>"XF86_SVGA"}, {Name=>"Rage IIC 4 meg",Item=>"XF86Config_8_RageIIC",Server=>"XF86_Mach64"}, {Name=>"Rage IIC 8 meg",Item=>"XF86Config_8_RageIIC",Server=>"XF86_Mach64"}, {Name=>"Trident 4 meg",Item=>"XF86Config_4_Trident",Server=>"XF86_SVGA"}, {Name=>"S3 Virge 4 meg",Item=>"XF86Config_4_S3V",Server=>"XF86_SVGA"}, {Name=>"Sis 8 meg",Item=>"XF86Config_8meg_SIS",Server=>"XF86_SVGA"}, {Name=>"Viper 700 16 meg",Item=>"",Server=>""}, ]; $Video = $Videos->[2]; $Ethernets = ["First Ethernet Card", {Item=>"None"}, {Name=>"3COM 3c59x",Item=>"3c59x"}, {Name=>"Intel 10/100",Item=>"eepro100"}, {Name=>"Realtek",Item=>"rtl8139"}, {Name=>"tulip",Item=>"tulip"} ]; $Ethernet = $Ethernets->[1]; $Modems =["Modem port", {Item=>"None"}, {Name=>"com1 or serial1 or ttyS0",Item=>"ttyS0"}, {Name=>"com2 or serial2 or ttyS1",Item=>"ttyS1"}, ]; $Modem = $Modems->[2]; $Checks =["Check for bad sectors?", {Name=>"Check for bad sectors",Item=>"\-c"}, {Name=>"DO NOT check for bad sectors",Item=>""}, ]; $Check = $Checks->[1]; $Swaps = ["Size of swap partition.", {Name=>"128 megs",Item=>"128"}, {Name=>"200 megs",Item=>"200"}, {Name=>"300 megs",Item=>"300"}, ]; $Swap = $Swaps->[1]; $Linuxs = ["Size of the Linux partition", {Item=>"Rest",Name=>"The rest of the diskspace."}, {Name=>"500 gigbytes",Item=>"500"}, {Name=>"1 gigbytes",Item=>"2000"}, {Name=>"2 gigbytes",Item=>"2000"}, {Name=>"4 gigbytes",Item=>"4000"}, {Name=>"6 gigbytes",Item=>"6000"}, {Name=>"6 gigbytes",Item=>"8000"} ]; $Linux = $Linuxs->[1]; $Mouses =["Mouse port", {Item=>"None"}, {Name=>"com1 or serial1 or ttyS0",Item=>"ttyS0"}, {Name=>"com2 or serial2 or ttyS1",Item=>"ttyS1"}, ]; $Mouse = $Mouses->[3]; $Lilos = ["Choose the configuration of Lilo.", {Item=>"lilo.conf",Name=>"Regular"}, {Item=>"lilo.conf_smp",Name=>"Regular Dual cpu"}, {Item=>"lilo.conf_dual",Name=>"Single cpu, Dual boot"}, {Item=>"lilo.conf_dual_smp",Name=>"Dual cpu, Dual boot"} ]; $Lilo = $Lilos->[1]; $Part1_Size = []; $Part1_Size->[0] = "Size of partition 1."; $Part1_Size->[1] = {Item=>"0",Valid=>1}; $Part1_Size->[2] = {Item=>"1000",Valid=>1,Name=>"1 gig"}; $Part1_Size->[3] = {Item=>"2000",Valid=>1,Name=>"2 gig"}; $Part1_Size->[4] = {Item=>"3200",Valid=>1,Name=>"3.2 gig"}; $Part1_Size->[5] = {Item=>"4000",Valid=>1,Name=>"4 gig"}; $Partition1_Size = $Part1_Size->[1]; $Part2_Size = []; $Part2_Size->[0] = "Size of partition 2."; $Part2_Size->[1] = {Item=>"None",Valid=>1,Name=>"0 gig"}; $Part2_Size->[2] = {Item=>"1000",Valid=>1,Name=>"1 gig"}; $Part2_Size->[4] = {Item=>"3200",Valid=>1,Name=>"3.2 gig"}; $Part2_Size->[3] = {Item=>"2000",Valid=>1,Name=>"2 gig"}; $Part2_Size->[5] = {Item=>"4000",Valid=>1,Name=>"4 gig"}; $Partition2_Size = $Part2_Size->[2]; 1; #!/usr/bin/perl open(LogFile,">/tmp/Log_Install"); my $Date = `date`; print LogFile "$Date\n"; close LogFile; my $Commands = (); $Home = "/INSTALL/Install"; $Configs = "$Home/Configuration_Files"; $Mounts = "$Home/Mounts"; $Base = "$Home/Base_Install"; $Images = "$Home/IMAGES"; #$Lib = "$Home/Lib"; #$Data = "$Home/Lib/Data.txt"; $Temp_Dir = "$Home/Temp"; #------------------------- use Expect; #-------------------------- #require "$Data"; #my @Temp = <$Lib/*.pl>; #foreach my $Temp (@Temp) {require $Temp} #------------------------------ #foreach $Temp (keys %$Drive) # {print "$Temp $Drive->{$Temp}\n";} my @Commands = ( [], ["Hard Drive",\$Drive,\$Drives], ["Video card",\$Video,\$Videos], ["Ethernet card",\$Ethernet,\$Ethernets], ["Modem",\$Modem,\$Modems,], ["Check bad sectors",\$Check,\$Checks], ["Size of Swap",\$Swap,\$Swaps], ["Size of Linux",\$Linux,\$Linuxs], ["Pre Partitioning",\$Pre_Partition,\$Pre_Partitioning], ["OS on $Drive->{Name} part 1",\$Partition1,\$Part1], ["OS on $Drive->{Name} part 2",\$Partition2,\$Part2], ["Size of part 1",\$Partition1_Size,\$Part1_Size], ["Size of part 2",\$Partition2_Size,\$Part2_Size], ["Mouse port",\$Mouse,\$Mouses], ["Lilo Configuration", \$Lilo, \$Lilos] ); while ($Answer ne "go") { system "clear"; my $Temp = $Commands[1]->[1]; $Temp = $$Temp; $Temp = $Temp->{Item}; $Cylinders = &Calculate_Cylinders($Temp); print "This is the configuration for your new hard drive burn.\n"; for (my $i = 1; $i < @Commands; $i++) { my $Entry = $Commands[$i]; my ($Name,$Object) = @$Entry; $Object = $$Object; if (!(exists $Object->{Item})) { $Object->{Name} = "---------- ERROR, Undefined."; $Object->{Item} = "---------- ERROR, Undefined."; $Object->{Vaild} = 0; } elsif (!(exists $Object->{Name})) {$Object->{Name} = $Object->{Item};} my $Tab = "\t"; if (length ($Name) < 11) {$Tab="\t\t";} print "$i\. $Name $Tab = $Object->{Name}\n"; } print "\n q\t\t quit this program go\t\t go ahead and do this stuff. Changing hard drive to $Cylinders cylinders. \n>"; my $R = ; chomp $R; $R =~ s/[^0-9a-z]//g; if ($R eq "q") {exit;} elsif ($R eq "go") {$Answer = "go"} elsif (($R < 1) || ($R > @Commands -1)) {print "Error, not understood. Press Enter.\n>"; $R=;} else { my $Value = &Choose($Commands[$R][1],$Commands[$R][2]); my $Pointer = $Commands[$R][1]; $$Pointer = $Value; } } #-------------------------------------------------------- ## Okay, now go ahead and do this stuff. #----------------------------- ## Go ahead and get all the values. my $Hard_Drive = $Drive->{Item}; my $Swap_Size = $Swap->{Item}; my $CheckIt = $Check->{Item}; #------------------------- # Now process the items #-------------- # Now execute stuff. my $Fdisk = Expect->spawn("/sbin/fdisk /dev/$Hard_Drive"); ### Deleting all the partitions on the hard drive. &DeletePartitions($Fdisk,$Hard_Drive,$Pre_Partition); ### &Make_Partitions($Fdisk,$Hard_Drive,$Swap_Size,$Linux,$Partition1,$Partition2,$Pre_Partition); my @Extended; if ($Partition2->{Item} eq "Extended") {@Extended = &Extended($Hard_Drive,$Partition2_Size->{Item})} #/dev/hda: 1027 cylinders, 255 heads, 63 sectors/track #---------------------- ### Write out the partitions #print $Fdisk "p\n"; $Fdisk->expect(30,"Command (m for help):"); ### Make any logical partitions my $Ex = &Make_Logical($Fdisk, $Hard_Drive,\@Extended,); ### Active partition 4 or 1 my $Active_Part = 4; if ($Partition1->{Item} ne "None") {$Active_Part = 1} print $Fdisk "a\n"; $Fdisk->expect(30,"Partition number"); print $Fdisk "$Active_Part\n"; $Fdisk->expect(30,"Command"); print $Fdisk "w\n"; $Fdisk->expect(30,"Command (m for help):"); #----------------------- ### Format the various partitions and mount them my $Command = "/sbin/mkswap -c /dev/$Hard_Drive"."3"; &Execute("$Command"); my $Command = "/sbin/mkfs -t ext2 $CheckIt /dev/$Hard_Drive"."4"; &Execute("$Command"); if (!(-e "$Mounts/New_RedHat6.0_$Hard_Drive")) {system "mkdir $Mounts/New_RedHat6.0_$Hard_Drive"} my $Command = "/bin/mount /dev/$Hard_Drive"."4 $Mounts/New_RedHat6.0_$Hard_Drive"; &Execute("$Command"); foreach my $Mount (keys %$Ex) { my $Point = $Ex->{$Mount}; my $Command = "/sbin/mkfs -t ext2 $CheckIt /dev/$Hard_Drive"."$Mount"; &Execute($Command); my $Command = "mkdir -p $Mounts/New_RedHat6.0_$Hard_Drive/$Point"; &Execute($Command); $Command = "/bin/mount /dev/$Hard_Drive"."$Mount $Mounts/New_RedHat6.0_$Hard_Drive/$Point"; &Execute($Command); } #----------------------------- # Untar linux to the fourth partition and ungzip images of Windows # to their partitions (if any) open(LogFile,">>/tmp/Log_Install"); my $Date = `date`; print LogFile "START hard drive copying $Date\n"; close LogFile; open(FILE,">$Temp_Dir/$Hard_Drive\.bat"); print FILE " for Test in `echo var etc TCU bin dev home lost+found mnt sbin usr TCU_Archives boot lib misc opt root tmp proc ` ; do tar -C $Base/ --same-owner -csp \$Test | tar --same-owner -C $Mounts/New_RedHat6.0_$Hard_Drive -pxv done "; close FILE; &Execute("cat $Home/Temp/$Hard_Drive\.bat"); &Execute("chmod 755 $Home/Temp/$Hard_Drive\.bat"); &Execute("$Home/Temp/$Hard_Drive\.bat"); open(LogFile,">>/tmp/Log_Install"); my $Date = `date`; print LogFile "STOP hard drive copying $Date\n"; close LogFile; #----------------------------- # Configure the ethernet card, modem, Xwindows, mouse, lilo, fstab ### Configure the ethernet card if ($Ethernet->{Item} ne "None") { my $Module = $Ethernet->{Item}; my $Command = "echo \"alias eth0 $Module\" >> $Mounts/New_RedHat6.0_$Hard_Drive/etc/conf.modules"; $Command = $Command .";\n cp $Configs/networking/ifcfg-eth0 $Mounts/\New_RedHat6.0_$Hard_Drive/etc/sysconfig/network-scripts "; $Command = $Command .";\n cp -f $Configs/networking/network $Mounts/\New_RedHat6\.\0_$Hard_Drive/etc/sysconfig/network "; &Execute($Command); } ### Configure the modem if ($Modem->{Item} ne "None") { my $Port = $Modem->{Item}; my $Command = "rm -f $Mounts/New_RedH\at6\.\0_$Hard_Drive/dev/modem; ln -s /dev/$Port $Mounts/New_RedHat6.0_$Letter/dev/modem"; $Command = $Command .";\n cp $Configs/networking/ifcfg-ppp0 $Mounts/New_RedHat6.0_$Hard_Drive/etc/sysconfig/network-scripts "; $Command = $Command .";\n cp $Configs/networking/chat-ppp0 $Mounts/New_RedHat6.0_$Hard_Drive/etc/sysconfig/network-scripts "; &Execute($Command); } ##### Configure the mouse if ($Mouse->{Item} ne "None") { my $Port = $Modem->{Item}; my $Command = "rm -f $Mounts/New_RedHat6\.\0_$Hard_Drive/dev/modem; ln -s /dev/$Port $Mounts/New_RedHat6.0_$Hard_Drive/dev/mouse"; &Execute($Command); } ###### Configure Xwindows $Command = "cp $Configs/X/$Video->{Item} $Mounts/New_RedHat6.0_$Hard_Drive/etc/X11/XF86Config"; $Command = $Command ."\n cd $Mounts/New_RedHat6.0_$Hard_Drive/etc/X11"; $Command = $Command ."\n ln -s ../../usr/X11R6/bin/$Video->{Server} X"; &Execute($Command); ###### Configure Lilo $Command = " cp -f $Configs/lilo/$Lilo->{Item} $Mounts/New_RedHat6\.0_$Hard_Drive/etc/lilo.conf "; #$Command = $Command . "\nlilo -C $Mounts/New_RedHat6\.0_$Letter/etc/lilo.conf"; &Execute($Command); ###### Configure Fstab open(File,"$Configs/fstab"); @File = ; close File; ### If IDE, make it /dev/hda, if SCSI, /dev/sda, otherwise just ### replace with whatever it is. my $New_Hard_Drive = $Hard_Drive; if ($Hard_Drive =~ /^hd/) {$New_Hard_Drive =~ s/hd[a-z]/hda/;} elsif ($Hard_Drive =~ /^sd/) {grep($_ =~ s/\/dev\/hda/\/dev\/sda/g, @File ); $New_Hard_Drive =~ s/sd[a-z]/sda/;} else {grep($_ =~ s/\/dev\/hda/\/dev\/$Hard_Drive/g, @File );} open(File,">$Mounts/New_RedHat6.0_$Hard_Drive/etc/fstab"); print File @File; if ($Partition1->{Name} eq "Win98") { print File "\n/dev/$New_Hard_Drive"."1 /Win98 vfat defaults 1 1 \n"; Execute("mkdir $Mounts/New_RedHat6.0_$Hard_Drive/Win98", 1); my $Item = $Partition1->{Item}; my $Command = "gunzip -cv $Images/$Item \| dd of=/dev/$Hard_Drive"."1"; Execute("$Command"); } elsif ($Partition1->{Name} eq "WinNT40") { my $Command = "gunzip -cv $Images/$Item \| dd of=/dev/$Hard_Drive"."1"; Execute("$Command"); } if ($Partition2->{Name} eq "Win98") { print File "\n/dev/$New_Hard_Drive"."2 /Win98 vfat defaults 1 1 \n"; Execute("mkdir $Mounts/New_RedHat6.0_$Hard_Drive/Win98"); my $Command = "gunzip -cv $Images/$Item \| dd of=/dev/$Hard_Drive"."2"; Execute("$Command"); } elsif ($Partition2->{Name} eq "Cdrom") { print File "\n/dev/$New_Hard_Drive"."2 /CDROM ext2 defaults 1 1 \n"; Execute("mkdir $Mounts/New_RedHat6.0_$Hard_Drive/CDROM", 1); my $Command = "/sbin/mkfs -t ext2 $CheckIt /dev/$Hard_Drive"."2"; &Execute($Command); } elsif ($Partition2->{Name} eq "Extended") { foreach my $Mount (keys %$Ex) { my $Point = $Ex->{$Mount}; if (!($Point =~ /^\//)) {$Point = "/$Point";} print File "\n/dev/$New_Hard_Drive"."$Mount $Point ext2 defaults 1 1 \n"; Execute("mkdir $Mounts/New_RedHat6.0_$Hard_Drive/CDROM", 1); } } close File; ####### open(LogFile,">>/tmp/Log_Install"); my $Date = `date`; print LogFile "$Date\n"; close LogFile; #!/usr/bin/perl sub Calculate_Cylinders { my $Hard_Drive = shift; my $Cylinders; my $Geometry = `/sbin/sfdisk -g /dev/$Hard_Drive`; chomp $Geometry; my ($Junk,$Temp1) = split(/\: /,$Geometry,2); my ($Cyl,$Heads,$Sec) = split(/\, /,$Temp1,3); ($Cyl,$Junk) = split(/ /,$Cyl,2); ($Heads,$Junk) = split(/ /,$Heads,2); ($Sec,$Junk) = split(/ /,$Sec,2); # print "$Total1 = $Heads*$Sec*$Cyl;\n"; my $Total1 = $Heads*$Sec*$Cyl; if (grep($_ < 1, ($Heads,$Sec,$Cyl))) { print "ERROR, $Hard_Drive $Heads,$Sec,$Cyl, no detection of hard drive\n"; print "sbin/sfdisk -g /dev/$Hard_Drive"; $R = ; } my $Cylinders; if ($Sec > 0) {$Cylinders = $Total1/255/$Sec;} if ($Cylinders =~ /\./) {($Cylinders,$Junk) = split(/\./,$Cylinders,2);} return ($Cylinders); } 1; #!/usr/bin/perl sub Choose { my $Value = shift; $Value = $$Value; my $Array = shift; $Array = $$Array; my $Clear = shift; if ($Clear < 1) {system "clear";} my $Message = $Array->[0]; print "$Message\n\n"; my $Item; for ($ItemNo=1; $ItemNo< @$Array; $ItemNo++) { my $P = $Array->[$ItemNo]; if (!(exists $P->{Valid}) || ($P->{Valid} == 1)) { print "$ItemNo\t"; my $Name; if (exists $P->{Name}) { $Name = $P->{Name}} elsif (exists $P->{Item}) {$Name = $P->{Item}; $P->{Name} = $P->{Item}} else {$Name = "Error, none.";} print "$Name\n"; } } print "\n>"; my $Item = ; chomp $Item; my $Item2; if (($Item < @$Array +1) && ($Item > 0)) {$Item2 = $Array->[$Item];} else {$Item2 = {Item=>"__ERROR__ $Item", Valid=>0, Name=>"__ERROR__ $Item"} ; } return($Item2); } 1; #!/usr/bin/perl sub DeletePartitions { my $Fdisk = shift; my $Drive = shift; my $Dont = shift; if (!($Drive =~ /[a-z]/)) {print "ERROR, no hard drive selected to delete partitions from.\n"; exit;} # my $Fdisk = Expect->spawn("/sbin/fdisk /dev/$Drive"); # $match=$Fdisk->expect(30,"Command (m for help):"); print $Fdisk "p\n"; $match=$Fdisk->expect(30,"Device Boot Start"); my $Temp = $Fdisk->exp_after(); my @Temp = split(/\n/, $Temp); my @Partitions = grep($_ =~ /^\/dev\//, @Temp); ### Clear of the rest of the returned info. # $Fdisk->expect(30,"Command (m for help):"); foreach my $Line (reverse @Partitions) { my ($Part,$Junk) = split(/[\t ]/, $Line,2); my $No = $Part; $No =~ s/^\/dev\/$Drive//; if (($Dont eq "leave") && (grep($_ == $No, (1,2)))) {} else { print "Deleting no $Drive $No\n"; print $Fdisk "d\n"; $match=$Fdisk->expect(30,"Partition number"); print $Fdisk "$No\n"; $match=$Fdisk->expect(30,"Command (m for help):"); } } #if (@Partitions > 0) { #print $Fdisk "w\n"; #$match=$Fdisk->expect(30,"Command (m for help):"); #} $Fdisk->clear_accum(); } 1; #!/usr/bin/perl sub Execute { my $Command = shift; my $ErrorCheck = shift; open(LogFile,">>/tmp/Log_Install"); print LogFile "$Command\n"; my $Error = system "$Command"; if (($ErrorCheck < 1) && ($Error > 0)) { print "__ERROR__ The Command\n \"$Command\"\n had error\n \"$Error\"\n"; print LogFile "__ERROR__ The Command\n \"$Command\"\n had error\n \"$Error\"\n"; exit; } elsif ($Error > 0) { ; print LogFile "__ERROR_2__ The Command\n \"$Command\"\n had error\n \"$Error\"\n"; } close LogFile; } 1; #!/usr/bin/perl sub Extended { my $Drive = shift; my $Partition_Size = shift; my $Cylinders = &Calculate_Cylinders($Drive); my $Size = `/sbin/sfdisk -s /dev/$Drive`; chomp $Size; $Size = $Size /1000; $Partition_Cyl = $Partition_Size * $Cylinders / $Size; my ($Partition_Cyl,$Temp) = split(/\./,$Partition_Cyl,2); my $Ratio_2 = $Partition_Size/$Partition_Cyl; ($Ratio_2,$Temp) = split(/\./,$Ratio_2,2); system "clear"; print "Extended hard drives detected. Please enter the sizes for the partitions (in cylinders)and where they should be mounted separated by a space. EX: >200 /usr This mounts 200 megs of diskspace to /usr. If you enter nothing, it will finish the list. If you enter \"delete\", it will clear the list. The hard drive is $Size megs and has $Cylinders cylinders. You have $Partition_Cyl cylinders for the extended partition. This partition has the size of $Partition_Size megs. There are $Ratio_2 megs per cylinder.\n\n>"; $R = ; chomp $R; while ($R =~ /[a-zA-Z0-9]/) { $R =~ s/^ +//; $R =~ s/ +$//; my ($Part_Size,$Mount) = split(/ +/, $R); if (($Part_Size > 1) && ($Mount =~ /\/[a-zA-Z0-9]/)) { my $Cyl = $Part_Size * $Partition_Size / $Size; my ($Cyl,$Junk) = split(/\./, $Cyl,2); push(@Mounts,"$Cyl $Mount -- $Part_Size megs"); } print "Current mounts are,\n"; foreach my $Part (@Mounts) {print "\t$Part\n";} print "\n>"; $R = ; chomp $R; if ($R =~ /delete/i) {@Mounts = ()} } return (@Mounts); } 1; #!/usr/bin/perl sub Make_Logical { my $Fdisk = shift; my $Drive = shift; my $Mounts = shift; my %Array; #system "clear"; my $No = 5; foreach $Temp (@$Mounts) { my ($Cyl, $Mount, $Junk) = split(/ +/,$Temp,3); $Array{$No} = $Mount; &MP_1($Fdisk,"n\n","("); my $Temp = $Fdisk->exp_after(); if ($Temp =~ /First cylinder/) {} else {&MP_1($Fdisk,"l\n",":");} &MP_1($Fdisk,"\n",":"); &MP_1($Fdisk,"\+$Cyl\n",":"); $No++; } #&MP_1($Fdisk,"w\n",""); return (\%Array) } 1; #!/usr/bin/perl sub Make_Partitions { my ($Fdisk, $Drive,$Swap_Size,$Linux,$Partition1,$Partition2,$Dont) = @_; #my $Fdisk = Expect->spawn("/sbin/fdisk /dev/$Drive"); ## Redo the cylinders my $Cylinders = &Calculate_Cylinders($Drive); #$match=$Fdisk->expect(30,"Command (m for help):"); #$Fdisk->clear_accum(); &MP_1($Fdisk,"x\n",":"); &MP_1($Fdisk,"h\n",":"); &MP_1($Fdisk,"255\n",":"); &MP_1($Fdisk,"c\n",":"); &MP_1($Fdisk,"$Cylinders\n",":"); &MP_1($Fdisk,"r\n",":"); my $Start = 1; my $Stop = $Cylinders; my $Size = `/sbin/sfdisk -s /dev/$Drive`; chomp $Size; my $Ratio = $Size/$Cylinders/1000; ($Ratio,$Junk) = split(/\./, $Ratio,2); ## Make the swap partition &MP_1($Fdisk,"n\n","primary"); &MP_1($Fdisk,"p\n",":"); &MP_1($Fdisk,"3\n",":"); my $Swap_Start = $Stop - $Swap_Size/$Ratio; ($Swap_Start,$Junk) = split(/\./, $Swap_Start,2); &MP_1($Fdisk, "$Swap_Start\n",":"); &MP_1($Fdisk, "$Stop\n",":"); $Stop = $Swap_Start - 1; &MP_1($Fdisk, "t\n",":"); &MP_1($Fdisk, "3\n",":"); &MP_1($Fdisk, "82\n",":"); ### Make the first partition, if any, always 3.1 gigabytes for ### Windiows98 or WindowsNT my $Part1_Type = $Partition1->{Name}; if (($Part1_Type ne "None") && ($Dont ne "leave")) { &MP_1($Fdisk,"n\n","primary"); &MP_1($Fdisk,"p\n",":"); &MP_1($Fdisk,"1\n",":"); my $Part1_Stop = $Start + 3200/$Ratio; ($Part1_Stop,$Junk) = split(/\./, $Part1_Stop,2); if ($Part1_Stop > $Stop -1) {print "ERROR, first partition cannot be made equal to 3.1 gigs, aborting.\n"; exit;} else { &MP_1($Fdisk,"$Start\n",":"); &MP_1($Fdisk,"$Part1_Stop\n",":"); $Start = $Part1_Stop +1; } if ($Part1_Type eq "Win98") {$Part1_Type = "b"} elsif ($Part1_Type eq "WinNT40") {$Part1_Type = "7"} elsif ($Part1_Type eq "WinNT40Server") {$Part1_Type = "7"} else {$Part1_Type = "83"} &MP_1($Fdisk, "t\n",":"); &MP_1($Fdisk, "1\n",":"); &MP_1($Fdisk, "$Part1_Type\n",":"); } ### Make the second partition, if any, always 3.1 gigabytes for ### Windiows98 or WindowsNT or an extended partition my $Part2_Type = $Partition2->{Name}; if (($Part2_Type ne "None") && ($Dont ne "leave")) { my $Part2_Size = $Partition2_Size->{Item}; my $Type = "p"; if ($Part2_Type eq "Extended") {$Type = "e"} &MP_1($Fdisk,"n\n","primary"); &MP_1($Fdisk,"$Type\n",":"); &MP_1($Fdisk,"2\n",":"); if ($Part2_Type eq "Win98") {$Part2_Size = "3100"} elsif ($Part2_Type eq "WinNT40") {$Part2_Size = "3100"} elsif ($Part2_Type eq "WinNT40Server") {$Part2_Size = "3100"} my $Part2_Start = $Stop - $Part2_Size/$Ratio; ($Part2_Start,$Junk) = split(/\./, $Part2_Start,2); if ($Part2_Start < $Start + 1) {print "ERROR, Partition 2 couldn't fit in.\n"; exit;} else { &MP_1($Fdisk,"$Part2_Start\n",":"); &MP_1($Fdisk,"$Stop\n",":"); $Stop = $Part2_Start - 1; } if ($Part2_Type eq "Win98") {$Part2_Type = "b"} elsif ($Part2_Type eq "WinNT40") {$Part2_Type = "7"} elsif ($Part2_Type eq "WinNT40Server") {$Part2_Type = "7"} elsif ($Part2_Type eq "Extended") {$Part2_Type = "5";} else {$Part2_Type = "83"} &MP_1($Fdisk, "t\n",":"); &MP_1($Fdisk, "2\n",":"); &MP_1($Fdisk, "$Part2_Type\n",":"); } ### Make the last partition for partition 4, or Linux. #print "TEST ------\n"; &MP_1($Fdisk,"n\n","primary"); &MP_1($Fdisk,"p\n",":"); &MP_1($Fdisk,"4\n",":"); &MP_1($Fdisk,"$Start\n",":"); if ($Stop > 1023) {$Stop = 1023} if ($Linux->{Item} ne "Rest") { my $No = $Linux->{Item}; my $Linux_Stop = $Start + $No/$Ratio; ($Stop,$Junk) = split(/\./, $Linux_Stop,2); } &MP_1($Fdisk,"$Stop\n",":"); if ($Start > 1001) {print "\n\nERROR, cannot make the partition start past cy\linder 1001 (technically 1023) for the root partition for Linux.\n"; exit;} elsif ($Stop > 1023) {print "\n\nERROR, cannot make the partition exist past cylinder 1023 for the root partition for Linux.\n"; exit;} #print $Fdisk "p\n"; $Fdisk->expect(30,"Command (m for help):"); my $Temp = $Fdisk->exp_before(); #print "\nTEST \n$Temp\nTEST\n"; #$R = ; #print $Fdisk "w\n"; $Fdisk->expect(30,"Command (m for help):"); } #-------------------------------- sub MP_1 { my ($Fdisk,$Message,$Match) = @_; print $Fdisk $Message; $Fdisk->expect(3,"$Match"); my $Temp = $Fdisk->exp_before(); print "$Temp\n"; $Fdisk->clear_accum(); } 1;