Hi all,

here is a new patch for the LVM stuff (made from the CVS source). I've added also the commands to create LVM groups.

Before to continue the development I'd like to know what do you think about an opportune syntax to express and define LVM volumes, groups, etc... For now I've tried to use a syntax to integrate this features as easy as possible in the XML schema.

This is the definition of the tags I've used:

---
Disk Section
...
part - ...
...
lvm_group - name of the LVM group the partition will be added.

LVM Section
This section is used to create LVM groups and volumes. The section is indicated with the "lvm" tag.


lvm_group - LVM group definition.
    name - volume group name.
    lv - start information about a new logical volume.
        name - logical volume name.
        size - the size of the logical volume.
---

And this is an example of a possible autoinstallscript.conf with LVM decalarations:

---
<disk dev="/dev/sda" label_type="msdos" unit_of_measurement="MB">
<part num="1" size="24" p_type="primary" fs="ext2" p_name="-" flags="-" />
<part num="2" size="256" p_type="primary" fs="linux-swap" p_name="-" flags="-" />
<part num="3" size="3000" p_type="primary" p_name="-" flags="lvm" lvm_group="user" />
<part num="4" size="end_of_disk" p_type="primary" p_name="-" flags="lvm" lvm_group="system" />
</disk>
<disk dev="/dev/sdb" label_type="msdos" unit_of_measurement="MB">
<part num="1" size="1500" p_type="primary" fs="ext2" p_name="-" flags="-" />
<part num="2" size="1500" p_type="primary" p_name="-" flags="lvm" lvm_group="system" />
<part num="3" size="end_of_disk" p_type="primary" p_name="-" flags="lvm" lvm_group="user" />
</disk>


<lvm>
<lvm_group name="system">
<lv name="usrlv" size="500" />
<lv name="optlv" size="1500" />
<lv name="varlv" size="256" />
</lvm_group>
<lvm_group name="user">
<lv name="homelv" size="5000" fs="xfs" mp="/home" options="defaults,rw,user" />
<lv name="scratchlv" size="2000" fs="xfs" mp="/scratch" options="defaults,rw,user" />
</lvm_group>
</lvm>


<fsinfo line="10" real_dev="/dev/sdb1" mp="/" fs="ext3" options="defaults,errors=remount-ro" />
<fsinfo line="20" real_dev="/dev/sda1" mp="/boot" fs="ext3" options="defaults,ro,noexec" dump="0" pass="2" />


<fsinfo line="30" real_dev="/dev/system/usrlv" fs="ext3" mp="/usr" options="defaults,rw,user,exec" />
<fsinfo line="40" real_dev="/dev/system/optlv" fs="reiserfs" mp="/opt" options="defaults,rw,user" />
<fsinfo line="50" real_dev="/dev/system/varlv" fs="ext3" mp="/var" options="defaults,rw,user,noexec" />
<fsinfo line="60" real_dev="/dev/user/homelv" fs="xfs" mp="/home" options="defaults,rw,user,exec" />
<fsinfo line="70" real_dev="/dev/system/scratchlv" fs="ext3" mp="/scratch" options="defaults,rw,user,noexec" />


<fsinfo line="80" real_dev="/dev/fd0" mp="/floppy" fs="auto" options="defaults,user,noauto" dump="0" pass="0" format="no" />
<fsinfo line="90" real_dev="proc" mp="/proc" fs="proc" options="defaults" dump="0" pass="0" />
---


Regards,
-Andrea
Index: etc/autoinstallscript.template
===================================================================
RCS file: /cvsroot/systemimager/systemimager/etc/autoinstallscript.template,v
retrieving revision 1.17
diff -u -r1.17 autoinstallscript.template
--- etc/autoinstallscript.template	17 Apr 2004 14:47:53 -0000	1.17
+++ etc/autoinstallscript.template	24 Jan 2005 17:51:30 -0000
@@ -95,6 +95,22 @@
 modprobe jfs
 modprobe xfs
 
+echo "Load device mapper driver (for LVM)."
+grep "dm-mod" /proc/modules > /dev/null
+if [ $? -eq 1 ]; then modprobe dm-mod; fi
+
+### BEGIN LVM initialization commands -AR- ###
+##INITIALIZE_LVM_PARTITIONS##
+### END LVM initialization commands ###
+
+### BEGIN LVM groups creation commands -AR- ###
+##CREATE_LVM_GROUPS##
+### END LVM groups creation commands ###
+
+### BEGIN LVM volumes creation commands -AR- ###
+##CREATE_LVM_VOLUMES##
+### END LVM volumes creation commands ###
+
 ### BEGIN swap and filesystem creation commands ###
 ##CREATE_FILESYSTEMS##
 ### END swap and filesystem creation commands ###
Index: lib/SystemImager/Server.pm
===================================================================
RCS file: /cvsroot/systemimager/systemimager/lib/SystemImager/Server.pm,v
retrieving revision 1.91
diff -u -r1.91 Server.pm
--- lib/SystemImager/Server.pm	15 Dec 2004 15:46:11 -0000	1.91
+++ lib/SystemImager/Server.pm	24 Jan 2005 17:51:31 -0000
@@ -34,6 +34,9 @@
 #   _imageexists 
 #   _in_script_add_standard_header_stuff 
 #   _read_partition_info_and_prepare_parted_commands 
+#   _read_partition_info_and_prepare_pvcreate_commands -AR-
+#   _write_lvm_groups_commands -AR-
+#   _write_lvm_volumes_commands -AR-
 #   _write_boel_devstyle_entry
 #   _write_elilo_conf
 #   _write_out_mkfs_commands 
@@ -774,6 +777,134 @@
     }
 }
 
+# Usage:
+# _read_partition_info_and_prepare_pvcreate_commands( $out, $image_dir, $auto_install_script_conf );
+sub _read_partition_info_and_prepare_pvcreate_commands {
+    my ($out, $image_dir, $file) = @_;
+
+    my $xml_config = XMLin($file, keyattr => { disk => "+dev", part => "+num" }, forcearray => 1 );
+
+    my @all_devices = get_all_devices($file);
+    my %devfs_map = dev_to_devfs(@all_devices) or return undef;
+
+    foreach my $dev (sort (keys ( %{$xml_config->{disk}} ))) {
+
+        my (
+            $highest_part_num,
+            $m,
+            $cmd,
+            $part,
+        );
+
+        my $devfs_dev = $devfs_map{$dev};
+
+        ### BEGIN Populate the simple hashes. -BEF- ###
+        my (
+            %flags,
+            %p_type,
+            %p_name,
+        );
+
+        foreach my $m (sort (keys ( %{$xml_config->{disk}->{$dev}->{part}} ))) {
+            $flags{$m}       = $xml_config->{disk}->{$dev}->{part}{$m}->{flags};
+            $p_name{$m}      = $xml_config->{disk}->{$dev}->{part}{$m}->{p_name};
+            $p_type{$m}      = $xml_config->{disk}->{$dev}->{part}{$m}->{p_type};
+        }
+
+        # Figure out what the highest partition number is. -BEF-
+        foreach (sort { $a <=> $b } (keys ( %{$xml_config->{disk}->{$dev}->{part}} ))) {
+            $highest_part_num = $_;
+        }
+
+        $m = "0";
+        until ($m >= $highest_part_num) {
+
+            $m++;
+            unless (defined($p_type{$m})) { next; }
+
+            $part = &get_part_name($dev, $m);
+
+            # Extended partitions can't be used by LVM. -AR-
+            if ("$p_type{$m}" eq "extended") { next; }
+
+            ### Deal with LVM flag for each partition. -AR-
+            if (($flags{$m}) and ($flags{$m} ne "-")) {
+                my @flags = split (/,/, $flags{$m});
+                foreach my $flag (@flags) {
+                    if ("$flag" eq "lvm") {
+
+                        $cmd = "Initializing partition $part for use by LVM.";
+                        print $out qq(echo "$cmd"\n);
+
+                        $cmd = "pvcreate $part || shellout";
+                        print $out qq(echo "$cmd"\n);
+                        print $out "$cmd\n";
+                        last;
+                    }
+                }
+            }
+        }
+    }
+}
+
+# Usage:  
+# write_lvm_groups_commands( $out, $image_dir, $auto_install_script_conf );
+sub write_lvm_groups_commands {
+    
+    my ($out, $image_dir, $file) = @_;
+
+    my $xml_config = XMLin($file, keyattr => { lvm_group => "+name" }, forcearray => 1 );
+    
+    # Check if a LVM schema is present.
+    my $lvm = @{$xml_config->{lvm}}[0];
+    unless (defined($lvm)) { return; }
+
+    my @all_devices = get_all_devices($file);
+    my %devfs_map = dev_to_devfs(@all_devices) or return undef;
+
+    # Find the partitions assigned to each LVM group. -AR-    
+    foreach my $group_name (sort (keys ( %{$lvm->{lvm_group}} ))) {
+        my $part_list = "";
+
+        foreach my $disk (@{$xml_config->{disk}}) {
+            my $dev = $disk->{dev};
+            
+            # Figure out what the highest partition number is. -AR-
+            my $highest_part_num = 0;
+            foreach my $part ( @{$disk->{part}} ) {
+                my $num = $part->{num};
+                if ($num > $highest_part_num) {
+                    $highest_part_num = $num;
+                }
+            }
+            
+            # Evaluate the partition list for the current LVM group -AR-
+            my $m = "0";
+            foreach my $part (@{$disk->{part}}) {
+                $m++;
+                unless (defined($part->{lvm_group})) { next; }
+                if ($part->{lvm_group} eq $group_name) {
+                    my $part_name = &get_part_name($dev, $m);
+                    $part_list = $part_list . " $part_name";
+                }
+            }
+        }
+        
+        if ($part_list ne "") {
+            my $cmd = "vgcreate ${group_name}${part_list} || shellout";
+            print $out qq(echo "$cmd"\n);
+            print $out "$cmd\n";
+        } else {
+            print "WARNING: LVM group \"$group_name\" doesn't have partitions!\n";
+        }
+    }
+}
+
+# Usage:  
+# write_lvm_volumes_commands( $out, $image_dir, $auto_install_script_conf );
+sub write_lvm_volumes_commands {
+}
+
 # Usage:  
 # upgrade_partition_schemes_to_generic_style($image_dir, $config_dir);
 sub upgrade_partition_schemes_to_generic_style {
@@ -1448,7 +1579,28 @@
 	            last SWITCH;
 	        }
 
-	        if (/^\s*${delim}CREATE_FILESYSTEMS${delim}\s*$/) {
+                if (/^\s*${delim}INITIALIZE_LVM_PARTITIONS${delim}\s*$/) {
+ 	            _read_partition_info_and_prepare_pvcreate_commands( $MASTER_SCRIPT,
+ 	          						$image_dir,
+ 	          						$auto_install_script_conf);
+                     last SWITCH;
+                }
+
+                if (/^\s*${delim}CREATE_LVM_GROUPS${delim}\s*$/) {
+                    write_lvm_groups_commands( $MASTER_SCRIPT,
+                                            $image_dir,
+                                            $auto_install_script_conf);
+                     last SWITCH;
+                }
+
+                if (/^\s*${delim}CREATE_LVM_VOLUMES${delim}\s*$/) {
+                     write_lvm_volumes_commands( $MASTER_SCRIPT,
+                                            $image_dir,
+                                            $auto_install_script_conf);
+                     last SWITCH;
+                }
+	        
+                if (/^\s*${delim}CREATE_FILESYSTEMS${delim}\s*$/) {
 	            _write_out_mkfs_commands( $MASTER_SCRIPT, 
 	          			$image_dir, 
 	          			$auto_install_script_conf,

Reply via email to