[pve-devel] r6189 - pve-installer/pve2

svn-commits at proxmox.com svn-commits at proxmox.com
Tue Jun 28 10:02:43 CEST 2011


Author: dietmar
Date: 2011-06-28 10:02:43 +0200 (Tue, 28 Jun 2011)
New Revision: 6189

Modified:
   pve-installer/pve2/changelog
   pve-installer/pve2/proxinstall
Log:
use parted


Modified: pve-installer/pve2/changelog
===================================================================
--- pve-installer/pve2/changelog	2011-06-28 04:38:29 UTC (rev 6188)
+++ pve-installer/pve2/changelog	2011-06-28 08:02:43 UTC (rev 6189)
@@ -2,6 +2,12 @@
 
   * use ext4 fs
 
+  * align LVM on 128k boundary 
+
+  * use 'parted' to create partitions
+
+  * support > 2TB disks (use GPT partition tables)
+
   * mount with barrier=0 during install (speedup)
 	
   * write keyboard settings to /etc/pve-installer.cfg

Modified: pve-installer/pve2/proxinstall
===================================================================
--- pve-installer/pve2/proxinstall	2011-06-28 04:38:29 UTC (rev 6188)
+++ pve-installer/pve2/proxinstall	2011-06-28 08:02:43 UTC (rev 6189)
@@ -442,15 +442,15 @@
 }
 
 sub get_boot_part {
-    my ($target_hd) = @_;
+    my ($target_hd, $gpt) = @_;
 
-    return get_partition_dev ($target_hd, 1);
+    return get_partition_dev ($target_hd, $gpt ? 2 : 1);
 }
 
 sub get_lvm_part {
-    my ($target_hd) = @_;
+    my ($target_hd, $gpt) = @_;
 
-    return get_partition_dev ($target_hd, 2);
+    return get_partition_dev ($target_hd, $gpt ? 3 : 2);
 }
 
 sub write_config {
@@ -542,6 +542,8 @@
     my $datadev;
     my $swapfile;
 
+    my $ptype = 'msdos';
+
     eval {
 
 	my $maxper = 0.25;
@@ -553,24 +555,47 @@
 	    my $hdsize = hd_size ($target_hd); # size in blocks (1024 bytes)
 
 	    if ($hdsize >= 2*1024*1024*1024) { # MBR can only handle 2 TB
-		$hdsize = 2*1024*1024*1024 - 1;
+		$ptype = 'gpt';
 	    }
 
-	    my $bootsize = 512*1024;
-	    my $linuxstart = 32+$bootsize;
+	    my $bootsize_mb = 512;
+	    my $bootsize = $bootsize_mb * 1024;
+	    my $hdsize_mb = $hdsize/1024;
 
-	    run_command ("sfdisk --no-reread -f -uB ${target_hd}", undef, 
-			 "32,$bootsize,L,*\n$linuxstart,,0x8e\n", 1) == 0 ||
-			     die "unable to partition harddisk '${target_hd}'\n";
+	    my $pcmd = "parted --align optimal ${target_hd}";
+	    $pcmd .= " unit MiB";
+	    $pcmd .= " mklabel $ptype";
+
+	    my $pnum = 1;
+
+	    if ($ptype eq 'gpt') {
+		$pcmd .= " mkpart primary 1 2";
+		$pcmd .= " set $pnum bios_grub on";
+		$pnum++;
+	    };
+
+	    $pcmd .= " mkpart primary ext2 $pnum ${bootsize_mb}";
+	    $pcmd .= " set $pnum boot on";
+	    $pnum++;
+
+
+	    $pcmd .= " mkpart primary ext2 ${bootsize_mb} ${hdsize_mb}";
+	    $pcmd .= " set $pnum lvm on";
+
+	    syscmd($pcmd) == 0 ||
+		die "unable to partition harddisk '${target_hd}'\n";
+
 	    sleep(1); # give kernel time to reread part table
 
-	    my $lvmdev = get_lvm_part ($target_hd);
+	    my $lvmdev = get_lvm_part($target_hd, $ptype eq 'gpt');
 
 	    $rootdev = '/dev/pve/root';
 	    $datadev = '/dev/pve/data';
 	    $swapfile = '/dev/pve/swap';
 
-	    syscmd ("/sbin/pvcreate -y -ff $lvmdev") == 0 ||
+	    # we use --metadatasize 250k, which reseults in "pe_start = 512"
+	    # so pe_start is aligned on a 128k boundary (advantage for SSDs)
+	    syscmd ("/sbin/pvcreate --metadatasize 250k -y -ff $lvmdev") == 0 ||
 		die "unable to initialize physical volume $lvmdev";
 	    syscmd ("/sbin/vgcreate pve $lvmdev") == 0 ||
 		die "unable to create volume group";
@@ -598,7 +623,7 @@
 	    }
 
 	    my $rootsize = (($hdgb > ($maxroot*4)) ? $maxroot : $hdgb/4)*1024*1024;
-	    my $rest = int($hdsize) - $linuxstart - $swapsize - $space - $rootsize; # in KB
+	    my $rest = int($hdsize) - $bootsize - $swapsize - $space - $rootsize; # in KB
 	    syscmd ("/sbin/lvcreate -L${swapsize}K -nswap pve") == 0 ||
 		die "unable to create swap volume";
 
@@ -625,7 +650,7 @@
 	update_progress (0.05, 0, $maxper, "creating filesystems");
 
 	if ( -b $target_hd) {
-	    $bootdev = get_boot_part ($target_hd);
+	    $bootdev = get_boot_part ($target_hd, $ptype eq 'gpt');
 	    create_filesystem ($bootdev, 'boot', 'ext4', 0.05, $maxper, 0, 0.1);
 	    create_filesystem ($rootdev, 'root', 'ext4', 0.05, $maxper, 0.1, 0.5);
 	    create_filesystem ($datadev, 'data', 'ext4', 0.05, $maxper, 0.5, 1, '-m 0');



More information about the pve-devel mailing list