Disk labels in setup_harddisks
Devlin
devlin at softhome.net
Thu Jul 11 21:55:57 CEST 2002
The following patch fixes my last setup_harddisks patch. I forgot to
make $MPOptions{} use CheckOption() in the last one; this one does use
it. This is a patch to a clean setup_harddisks.
--- setup_harddisks.orig Thu Jul 11 15:49:11 2002
+++ setup_harddisks Thu Jul 11 15:49:02 2002
@@ -107,29 +107,28 @@
# "fstab-options":
# These options are copied to the fstab-file. The
# default is "default"
#
# After the semicolon there could be extra options like:
-# -i <bytes> : Bytes per inodes
-# (only ext2/3 filesystem)
-# -m <blocks>% : reserved blocks percentage for superuser
-# (only ext2/3 filesystem)
-# -j : format in ext3
-# -c : check for bad blocks
-# format : Always format this partition even if preserve
-# lazyformat : Do not format if partition has not moved
-# (useful for testing the installation)
-# boot : make this partition the boot-partition (the
-# linux root filesystem is the default)
-# ext2 : Extended 2 filesystem (this is the default)
-# swap : swap partition
-# dosfat16 : DOS 16bit FAT file system
-# winfat32 : Win95 FAT32 file system
-# writable : mounts a preserved partition writable
-# reiser : reiserfs
-# -h <hash> : set reiserfs hash
-# -v <ver> : set reiserfs version
+# -c : check for bad blocks
+# format : Always format this partition even if preserve
+# lazyformat : Do not format if partition has not moved
+# (useful for testing the installation)
+# boot : make this partition the boot-partition (the
+# linux root filesystem is the default)
+# ext2 : Extended 2 filesystem (this is the default)
+# -i <bytes> : Bytes per inodes
+# -m <blocks>% : reserved blocks percentage for superuser
+# -j : format in ext3
+# -L <label> : use a disk label
+# swap : swap partition
+# dosfat16 : DOS 16bit FAT file system
+# winfat32 : Win95 FAT32 file system
+# writable : mounts a preserved partition writable
+# reiser : reiserfs
+# -h <hash> : set reiserfs hash
+# -v <ver> : set reiserfs version
#
use strict;
# getopts variables:
our ($opt_X, $opt_f, $opt_c, $opt_d);
my $test;
@@ -307,10 +306,21 @@
}
($ConfigFileExists == 0) && die "ERROR: no config file found\n";
}
#****************************************************
+# check for an option
+#****************************************************
+sub CheckOption{
+ # a list of all options that take string parameters
+ my $stringopts = "L";
+
+ if ( $_[1] == "" ) { return 1==0; }
+ return $_[0] =~ /\b(?<!-[$stringopts] )(?i:$_[1])\b/;
+}
+
+#****************************************************
# parse config-file
#****************************************************
sub ParseConfigFile{
my $size=""; my $mountpoint=""; my $device ="";
my $fstaboptions=""; my $options=""; my $disk=""; my $command = "";
@@ -322,10 +332,11 @@
(print "parsing config file: $filename\n");
$disk = "";
my $a = 1, my $paras ="", my $number=0;
while (my $line = <FILE>){
chomp($line);
+ $line =~ s/\s+/ /g;
$a++;
next if( $line =~ /^#|^\s*$/ );
# disk_config - command
if ($line =~ /^disk_config(.*)/i){
@@ -380,11 +391,11 @@
$mountpoint = "no$NofNotMoPart";
}
if($mountpoint eq "swap"){
$NofSwapPart++;
$mountpoint = "swap$NofSwapPart";
- ($options !~ /\bswap\b/i) && ($options .= " swap");
+ !CheckOption($options, "swap") && ($options .= "
swap");
($fstaboptions) || ($fstaboptions = "sw");
}
if($mountpoint =~ m#^/#){
($fstaboptions) || ($fstaboptions = "defaults");
}
@@ -394,11 +405,11 @@
$PrimPartNo++;
($PrimPartNo == 3) && ($disk =~ /^sd/) &&
($PrimPartNo++);
($PrimPartNo >4 ) && die "ERROR: Too much primary
partitions (max 4).".
" All logicals together need one
primary too.\n";
$MountpointPart{$mountpoint} =
PartName($disk,$PrimPartNo);
- if($options =~ /\bboot\b/i){
+ if(CheckOption($options, "boot")){
($BootPartition) && die "ERROR: only one
partition can be bootable at a time.";
$BootPartition = $MountpointPart{$mountpoint};
$BOOT_DEVICE = $disk;
}
} else {
@@ -418,11 +429,11 @@
&& die "ERROR: too much primary partitions
(max 4).".
" All logicals together need one primary
too.\n";
$MountpointPart{$extmp} =
PartName($disk,$PrimPartNo);
$DiskMountpoints{$disk} .= " $extmp";
}
- ($options =~ /\bboot\b/i) && die "ERROR: line $a,
only primary partitions can be bootable.\n";
+ CheckOption($options, "boot") && die "ERROR: line
$a, only primary partitions can be bootable.\n";
}
($DiskMountpoints{$disk} =~ /\b$mountpoint\b/)
&& die "ERROR in config file line $a, Mountpoint
redefined: $mountpoint\n$line\n";
$DiskMountpoints{$disk} .= " $mountpoint";
# size
@@ -458,11 +469,11 @@
$LastPresPart = $device;
($MPMinSize{$mountpoint} < 1)
&& die "ERROR: unable to preserve partitions of
size 0.\n$line\n ";
} else {
# If not preserve we must know the filesystemtype
- ($options !~
/\b(ext2|ext3|auto|swap|dosfat16|winfat32|reiser)\b/i ) &&
($options .= " auto");
+ CheckOption($options,
"(ext2|ext3|auto|swap|dosfat16|winfat32|reiser)" ) && ($options .= "
auto");
}
if($size =~ /^(\d*)(\-?)(\d*)$/){
$Min = $1;
$Min||= 1;
$Max = $3;
@@ -485,14 +496,14 @@
$MPPreserve{$mountpoint} = "";
}
# fstaboptions
$MPfstaboptions{$mountpoint} = $fstaboptions;
# extra options
- ($options =~ /\b(ext[23]|auto)\b/i) &&
($MPID{$mountpoint} = 83); # Linux native
- ($options =~ /\bswap\b/i) && ($MPID{$mountpoint} =
82); # Linux swap
- ($options =~ /\bdosfat16\b/i) && ($MPID{$mountpoint} =
6); # DOS FAT 16bit (>=32MB, will be changed later)
- ($options =~ /\bwinfat32\b/i) && ($MPID{$mountpoint} =
"b"); # Win 95 FAT 32
+ CheckOption($options, "(ext[23]|auto)") &&
($MPID{$mountpoint} = 83); # Linux native
+ CheckOption($options, "swap") && ($MPID{$mountpoint} =
82); # Linux swap
+ CheckOption($options, "dosfat16") &&
($MPID{$mountpoint} = 6); # DOS FAT 16bit (>=32MB, will be changed later)
+ CheckOption($options, "winfat32") &&
($MPID{$mountpoint} = "b"); # Win 95 FAT 32
$MPOptions{$mountpoint} = $options;
if($test == 1){
print
"$mountpoint,$MPMinSize{$mountpoint}-$MPMaxSize{$mountpoint},";
print "$fstaboptions,$options";
($MPPreserve{$mountpoint} eq "yes") && (print "
Preserve: $MountpointPart{$mountpoint}");
@@ -586,11 +597,11 @@
}
}
$EndPos = $DiskSize{$disk} - 1;
&SetGroupPos($DynGroup,$StartPos,$EndPos);
foreach $mountpoint(split(/\s/,$DiskMountpoints{$disk})) {
- ($MPOptions{$mountpoint} =~ /\bdosfat16\b/i)
+ CheckOption($MPOptions{$mountpoint}, "dosfat16")
&& (($MPSize{$mountpoint} * $DiskUnits{$disk} *
$sectorsize) < 32 * $megabyte)
&& ($MPID{$mountpoint} = 4); # DOS 16-bit FAT <32MB
}
}
@@ -740,21 +751,21 @@
$mountpointname = "no mountpoint";
} else {
$mountpointname = $mountpoint;
}
# preserved partition
- if ( ($MPPreserve{$mountpoint} eq "yes") &&
($MPOptions{$mountpoint} !~ /\bformat\b/i)){
+ if ( ($MPPreserve{$mountpoint} eq "yes") &&
!CheckOption($MPOptions{$mountpoint}, "format")){
print "Preserve Partition $device";
if ($mountpoint =~ /^no$1/){
print " with no mountpoint\n";
} else {
print " with mountpoint $mountpoint\n";
}
next;
}
# lazy format
- if ( ( $MPOptions{$mountpoint} =~ /\blazyformat\b/i )
+ if ( CheckOption( $MPOptions{$mountpoint}, "lazyformat" )
&& ($MPStart{$mountpoint} == $PartOldStartSec{$device})
&& (($MPStart{$mountpoint} + $MPSize{$mountpoint} - 1) ==
$PartOldEndSec{$device}) ){
print "Lazy format: $device";
if ($mountpoint =~ /^no$1/){
print " with no mountpoint";
@@ -777,11 +788,11 @@
(($? >> 8) == 0) || (die "\nMKSWAP ERROR:\n
$result\n");
}
next;
}
# Linux Reiser file system
- if ($MPOptions{$mountpoint} =~ /\breiser\b/i) {
+ if (CheckOption($MPOptions{$mountpoint}, "reiser")) {
print "Make Reiser Filesystem:\n";
$command = "echo y | mkreiserfs $mkreiserfs_options";
($MPOptions{$mountpoint} =~ /(\-h\s*\w+)\b/) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-v\s*\d+)\b/) &&
($command .= " $1");
$command .= " /dev/$device";
@@ -791,27 +802,28 @@
(($? >> 8) == 0) || die "\nMKREISERFS ERROR:\n
$result\n";
}
next;
}
# Linux Extended 2 file system
- if ($MPOptions{$mountpoint} =~ /\b(ext[23]|auto)\b/i) {
+ if (CheckOption($MPOptions{$mountpoint}, "(ext[23]|auto)")) {
print "Make Extended 2/3 Filesystem:\n";
$command = "mke2fs $mke2fs_options";
($MPOptions{$mountpoint} =~ /(\-c)\b/i) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-i\s*\d+)\b/) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-m\s*\d+)\b/) &&
($command .= " $1");
($MPOptions{$mountpoint} =~ /(\-j)\b/) && ($command .= "
$1");
+ ($MPOptions{$mountpoint} =~ /(\-L\s*\S+)\b/) &&
($command .= " $1");
$command .= " /dev/$device";
print " $command\n";
if ($test != 1){
$result = `$command`;
(($? >> 8) == 0) || die "\nMKE2FS ERROR:\n
$result\n";
}
next;
}
# DOS 16bit FAT / Win95 FAT 32
- if ($MPOptions{$mountpoint} =~ /\b(dosfat16|winfat32)\b/i) {
+ if (CheckOption($MPOptions{$mountpoint},
"(dosfat16|winfat32)")) {
print "Clear first sector for DOS/Windows\n";
$command = "dd if=/dev/zero
of=/dev/$MountpointPart{$mountpoint} bs=512 count=1";
print " $command\n";
if ($test != 1){
$result = `$command`;
@@ -834,13 +846,13 @@
#
#<file sys> <mount point> <type> <options> <dump>
<pass>
EOM
# 1. /
$type = "ext2";
- ($MPOptions{'/'} =~ /\b(reiser)\b/i) && ($type = "reiserfs");
- ($MPOptions{'/'} =~ /\b(ext3)\b/i) && ($type = "ext3");
- ($MPOptions{'/'} =~ /\b(ext2)\b/i) && ($type = "ext2");
+ CheckOption($MPOptions{'/'}, "(reiser)") && ($type = "reiserfs");
+ CheckOption($MPOptions{'/'}, "(ext3)") && ($type = "ext3");
+ CheckOption($MPOptions{'/'}, "(ext2)") && ($type = "ext2");
$FileSystemTab .=
BuildfstabLine("/dev/$MountpointPart{'/'}","/",$type,$MPfstaboptions{'/'},0,
1);
# 2. swap partitions
foreach my $mountpoint (%PartMountpoint){
next if( $mountpoint !~ /^swap/i);
$FileSystemTab .=
BuildfstabLine("/dev/$MountpointPart{$mountpoint}",
@@ -851,14 +863,14 @@
# 4. sorted others
foreach my $mountpoint (sort %PartMountpoint){
next if ( ($mountpoint !~ m#^/#) || ($mountpoint eq "/"));
$device = $MountpointPart{$mountpoint};
$type = "ext2";
- ($MPOptions{$mountpoint} =~ /\b(dosfat16|winfat32)\b/i) &&
($type = "vfat");
- ($MPOptions{$mountpoint} =~ /\b(reiser)\b/i) && ($type =
"reiserfs");
- ($MPOptions{$mountpoint} =~ /\b(ext3)\b/i) && ($type = "ext3");
- ($MPOptions{$mountpoint} =~ /\b(ext2)\b/i) && ($type = "ext2");
+ CheckOption($MPOptions{$mountpoint}, "(dosfat16|winfat32)") &&
($type = "vfat");
+ CheckOption($MPOptions{$mountpoint}, "(reiser)") && ($type =
"reiserfs");
+ CheckOption($MPOptions{$mountpoint}, "(ext3)") && ($type =
"ext3");
+ CheckOption($MPOptions{$mountpoint}, "(ext2)") && ($type =
"ext2");
$FileSystemTab .=
BuildfstabLine("/dev/$device",$mountpoint,$type,$MPfstaboptions
{$mountpoint},0,2);
}
# write it
$filename = "$ENV{LOGDIR}/fstab";
print $FileSystemTab;
More information about the linux-fai
mailing list