Package: fai
Version: 2.8.4sarge1
Severity: wishlist

FAI's default nfsroot has long included LVM utilities.
However, the setup_harddisks script still lacks support for making a
"Linux LVM" (0x8e) partition.

The FAI wiki has a heavily-modified version of setup_harddisks, made
three years ago by Sam Vilain as a fork of version 0.16fai. This has
rather comprehensive RAID and LVM support, but (a) it hasn't been
updated in three years, (b) it introduced a few bugs, (c) it contains
profane language, (d) coding style changes tend to hide the real
differences from the version on the main branch. Having looked at it,
I get the impression that it's better to continue enhancing the
standard setup_harddisks than to switch to that branch.

The attached patch is a first step towards adding LVM support to
setup_harddisks. It adds a new pseudo-filesystem option, lvm, 
to cause a partition to be given type 0x8e (Linux LVM) and
initialised with pvcreate.

In order to run, pvcreate must have write access to /var/lock/lvm/.
That requires a simple change to make-fai-nfsroot, also included in the
patch. 

I think it will also be a good idea to remove /etc/lvm/.cache from the
nfsroot, since its contents describe the server's disks rather than the
client's; but the impact of not doing so seems limited to a few spurious
warning messages from pvcreate.

The patch also makes it clearer that the values in %MPID are to be
interpreted as strings, not as decimal numbers. (They are really
hexadecimal byte values, but the conversion to/from the string
representation is sfdisk's job.)

Where to go from here? Three obvious next steps are:
* supporting various options to pvcreate (-M, -u, etc.)
* supporting pvcreate on a whole unpartitioned disk
* assigning PVs to new or preexisting volume groups

Once support for setting up VGs is in place, one can think of
"partitioning" them by creating LVs.

Or should one look at EVMS as a possibly cleaner and more systematic
approach to these issues?
--- old/scripts/setup_harddisks 2005-11-10 23:37:18.000000000 +0100
+++ new/scripts/setup_harddisks 2006-03-13 21:14:49.834097285 +0100
@@ -139,6 +139,7 @@
 #     reiser       : reiserfs
 #       -h <hash>  : set reiserfs hash
 #       -v <ver>   : set reiserfs version
+#     lvm          : LVM physical volume
 #
 use strict;
 # getopts variables:
@@ -163,6 +164,7 @@
 my $mkreiserfs_options = "";
 my $mkxfs_options = "-f";
 my $mkswap_options = "";
+my $pvcreate_options = "";
 
 # FAI input variables
 my $ClassPath = "$ENV{FAI}/disk_config";# this directory contains the classes
@@ -288,7 +290,7 @@
        if($line =~ m'# partition table of /dev/(\S+)$'i){
           $disk = $1;
         }
-       if($line =~ 
m#^/dev/(.+?)\s*:\s+start=\s*(\d+),\s+size=\s*(\d+),\s+Id=\s*([a-z0-9]+)\b(.*)$#i){
+       if($line =~ 
m#^/dev/(.+?)\s*:\s+start=\s*(\d+),\s+size=\s*(\d+),\s+Id=\s*([a-f0-9]+)\b(.*)$#i){
            $device = $1;
             # Sectors
             $PartOldStartSec{$device} = $2;
@@ -455,9 +457,9 @@
                        $MPPrimary{$extmp} = "yes";
                        $MPMinSize{$extmp} = 0;
                        $MPMaxSize{$extmp} = 0;
-                       $MPID{$extmp} = 5;
+                       $MPID{$extmp} = "5";
                        $PrimPartNo++;
-                       ($PrimPartNo == 3) && ($disk =~ /^sd/) && 
($PrimPartNo++);
+#                      ($PrimPartNo == 3) && ($disk =~ /^sd/) && 
($PrimPartNo++);
                         ($PrimPartNo >4 ) 
                          && die "ERROR: too much primary partitions (max 4).".
                                " All logicals together need one primary 
too.\n";
@@ -502,7 +504,7 @@
                      && 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|xfs)\b/i ) && ($options .= " 
auto");
+                   ($options !~ 
/\b(ext2|ext3|auto|swap|dosfat16|winfat32|reiser|xfs|lvm)\b/i ) && ($options .= 
" auto");
                  }
                if($size =~ /^(\d*)(\-?)(\d*)$/){
                    $Min = $1;
@@ -529,9 +531,10 @@
                # 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 =~ /\b(ext[23]|auto)\b/i) && ($MPID{$mountpoint} = 
"83"); # Linux native
+               ($options =~ /\bswap\b/i) && ($MPID{$mountpoint} = "82"); # 
Linux swap
+               ($options =~ /\blvm\b/i) && ($MPID{$mountpoint} = "8e"); # 
Linux LVM
+               ($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
                $MPOptions{$mountpoint} = $options;
                if($test == 1){
@@ -632,7 +635,7 @@
     foreach $mountpoint(split(/\s/,$DiskMountpoints{$disk})) {
        ($MPOptions{$mountpoint} =~ /\bdosfat16\b/i)
            && (($MPSize{$mountpoint} * $DiskUnits{$disk} * $sectorsize) < 32 * 
$megabyte)
-               && ($MPID{$mountpoint} = 4); # DOS 16-bit FAT <32MB
+               && ($MPID{$mountpoint} = "4"); # DOS 16-bit FAT <32MB
     }
 }
 
@@ -862,6 +865,18 @@
                }
                next;
            }
+           # Linux LVM
+           if ($MPOptions{$mountpoint} =~ /\b(lvm)\b/i) {
+#              print "Make LVM physical volume:\n";
+               $command = "pvcreate $pvcreate_options";
+               $command .= " /dev/$device";
+               print "  $command\n";
+               if ($test != 1){
+                   $result = `$command`;
+                   (($? >> 8) == 0) || die "\nPVCREATE ERROR:\n $result\n";
+               }
+               next;
+           }
            # DOS 16bit FAT / Win95 FAT 32
            if ($MPOptions{$mountpoint} =~ /\b(dosfat16|winfat32)\b/i) {
                print "Clear first sector for DOS/Windows\n";
@@ -905,6 +920,7 @@
     # 4. sorted others
     foreach my $mountpoint (sort %PartMountpoint){
        next if ( ($mountpoint !~ m#^/#) || ($mountpoint eq "/"));
+       next if ($MPOptions{$mountpoint} =~ /\b(lvm)\b/i);
        $device = $MountpointPart{$mountpoint};
        $type = "ext2";
        ($MPOptions{$mountpoint} =~ /\b(dosfat16|winfat32)\b/i) && ($type = 
"vfat");
--- old/scripts/make-fai-nfsroot        2005-11-10 23:37:18.000000000 +0100
+++ new/scripts/make-fai-nfsroot        2006-03-13 22:52:39.642389725 +0100
@@ -294,8 +294,9 @@
 
     # make little changes to nfsroot, because nfsroot is
     # read only for the install clients 
-    rm -rf etc/mtab var/run etc/sysconfig
+    rm -rf etc/mtab var/lock var/run etc/sysconfig
     ln -s /proc/mounts etc/mtab
+    ln -s /tmp/var/lock var/lock
     ln -s /tmp/var/run var/run
     ln -sf /tmp/var/state/discover var/state/discover
     ln -sf /tmp/var/lib/discover var/lib/discover

Reply via email to