From 6ef59e9232c170ff33166ac31858b72551ccc479 Mon Sep 17 00:00:00 2001
From: James Meyer <james.meyer@operamail.com>
Date: Fri, 31 May 2013 17:06:06 -0500
Subject: LinHES-config:  redo of partition, dropped pyparted and using parted
 directly from the cmdline. This change also switches to using gpt only and
 dropping the mbr.  Partition layout remains the same p1 = / p2 = swap p3 =
 null p4 = gpt boot p5 = home p6 = database p7 = remaining space

This also fixes  using drives larger then 2TB  and attempting to install with no swap partition.

refs #917
---
 abs/core/LinHES-config/PKGBUILD      |   4 +-
 abs/core/LinHES-config/mv_install.py | 136 +++++++++++++++++++++++++++++------
 2 files changed, 115 insertions(+), 25 deletions(-)

diff --git a/abs/core/LinHES-config/PKGBUILD b/abs/core/LinHES-config/PKGBUILD
index 449f456..3b083a2 100755
--- a/abs/core/LinHES-config/PKGBUILD
+++ b/abs/core/LinHES-config/PKGBUILD
@@ -1,6 +1,6 @@
 pkgname=LinHES-config
 pkgver=8.0
-pkgrel=2
+pkgrel=3
 conflicts=(MythVantage-config MythVantage-config-dev LinHES-config-dev LinHes-config )
 pkgdesc="Install and configure your system"
 depends=('bc' 'libstatgrab'  'mysql-python' 'expect' 'curl' 'dnsutils' 'parted'
@@ -133,7 +133,7 @@ build() {
     install -o root -g root  -D -m 0755 blacklist_pcspkr.conf $startdir/pkg/etc/modprobe.d/blacklist_pcspkr.conf
     install -o root -g root  -D -m 0755 blacklist_nouveau.conf $startdir/pkg/etc/modprobe.d/blacklist_nouveau.conf
 }
-md5sums=('7cdc9bc678ab02a2d30444e20a3c71eb'
+md5sums=('70d0e964788d1d7bc622c20d7d8d8f5c'
          '3f6855b7bb860a44f96a972c2e80f497'
          'aaeb581275433649ff74e05da5e61a78'
          '2596460462cf6c889cf8f95485537b20'
diff --git a/abs/core/LinHES-config/mv_install.py b/abs/core/LinHES-config/mv_install.py
index 1128571..2712a60 100755
--- a/abs/core/LinHES-config/mv_install.py
+++ b/abs/core/LinHES-config/mv_install.py
@@ -259,7 +259,7 @@ def blank_table(diskdevice):
     cmd = "parted %s --script -- mklabel msdos" %diskdevice
     runcmd(cmd)
 
-    logging.debug("parition table after:")
+    logging.debug("partition table after:")
     cmd = "fdisk -l %s" %diskdevice
     runcmd(cmd)
 
@@ -392,35 +392,128 @@ def set_active_parition(diskdevice):
             logging.info("    Depending on your system this may not matter")
 
 
+#def partition_disk():
+    #global hostoptions
+    #logging.info("Partitioning")
+    #logging.debug("____start of partition_disk____")
+    #rootdisk = hostoptions["rootdisk"]
+    #datadisk = hostoptions["datadisk"]
+    #label = "root"
+    #partitions_removeall("/dev/"+rootdisk, label)
+    #label = "data"
+    #partitions_removeall("/dev/"+datadisk, label)
+    #hostoptions["rootpartition"] = create_partitions("/dev/"+rootdisk, hostoptions["rootsize"], "NORMAL", 0)
+    #set_active_parition("/dev/"+rootdisk)
+
+    #hostoptions["swappartition"] = create_partitions("/dev/"+rootdisk, hostoptions["swapsize"], "SWAP", 1)
+
+    ##create extended partition
+    #hostoptions["extended_partition"] = create_partitions("/dev/"+rootdisk, "all", "EXTENDED", 1)
+
+    ##create the logical in the extended
+    #hostoptions["home_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["homesize"], "LOGICAL", 1)
+    #hostoptions["sql_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["sqlsize"], "LOGICAL", 1)
+
+    #if datadisk != rootdisk:
+        #hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 0)
+    #else:
+        #hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "LOGICAL", 1)
+
+    #logging.debug("sleeping for 5 seconds")
+    #time.sleep(5)
+
+
+#parted /dev/sda -a optimal --script  mklabel gpt
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  1 500
+#parted /dev/sda -a optimal --script unit MB  -- mkpart swap  501 600
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  601 601
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  601 601
+
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  604 700
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  700 800
+#parted /dev/sda -a optimal --script unit MB  -- mkpart primary  800 -1
+
+def create_partitions_gpt(diskdevice, start,size,partition_type):
+    logging.debug("_____Create partitions gpt ______")
+    if size == "NO" or size == "no":
+        logging.info("Size is 0,  skipping")
+        last_sector  = start
+    elif size == "all" or size == "ALL":
+        logging.info("Size is all, using rest of disk")
+        last_sector = "-1"
+    else:
+        last_sector = start + int(size)
+
+    cmd = "parted %s  -a optimal --script unit MB  -- mkpart primary  %s %s" %(diskdevice, start, last_sector)
+    runcmd(cmd)
+    
+    newstart = last_sector
+    #print newstart
+    return newstart
+    
+    
+    
+
+
+
 def partition_disk():
     global hostoptions
     logging.info("Partitioning")
     logging.debug("____start of partition_disk____")
-    rootdisk = hostoptions["rootdisk"]
-    datadisk = hostoptions["datadisk"]
+    rootdisk = "/dev/%s" %(hostoptions["rootdisk"])
+    datadisk = "/dev/%s" %(hostoptions["datadisk"])
     label = "root"
-    partitions_removeall("/dev/"+rootdisk, label)
+    partitions_removeall(rootdisk, label)
     label = "data"
-    partitions_removeall("/dev/"+datadisk, label)
-    hostoptions["rootpartition"] = create_partitions("/dev/"+rootdisk, hostoptions["rootsize"], "NORMAL", 0)
-    set_active_parition("/dev/"+rootdisk)
+    partitions_removeall(datadisk, label)
+    #create gpt table
+    cmd = "parted %s -a optimal --script  mklabel gpt" %rootdisk
+    runcmd(cmd)
+    cmd = "parted %s -a optimal --script  mklabel gpt" %datadisk
+    runcmd(cmd)
+    
+    start_sector = 1
+    start_sector = create_partitions_gpt(rootdisk, start_sector, hostoptions["rootsize"], "primary")
+    start_sector = create_partitions_gpt(rootdisk, start_sector, hostoptions["swapsize"], "primary")
+    hostoptions["rootpartition"] = hostoptions["rootdisk"]+str(1)  
+    hostoptions["swappartition"]  =  hostoptions["rootdisk"] + str(2)
+    hostoptions["home_partition"] = hostoptions["rootdisk"]+str(5)
+    hostoptions["sql_partition"] = hostoptions["rootdisk"]+str(6)
+    hostoptions["datapartition"] = hostoptions["datadisk"]+str(7)
+        
+    
+    #create 1 blank to match up with extended/logical layout from 8.0
+    start_sector = create_partitions_gpt(rootdisk, start_sector, "NO", "primary")
+
+    #create gtp boot
+    start_sector = start_sector + 1
+    start_sector = create_partitions_gpt(rootdisk, start_sector, 2 , "primary")
+    cmd = "parted %s set 4 bios_grub on" %rootdisk
+    runcmd(cmd)
+    
+    #create home_partition
+    start_sector = start_sector + 1
+    start_sector = create_partitions_gpt(rootdisk, start_sector, hostoptions["homesize"], "primary")
+    
+    ##create mysql
+    start_sector = start_sector + 1
+    start_sector  = create_partitions_gpt(rootdisk, start_sector, hostoptions["sqlsize"], "primary")
+    
+    start_sector = start_sector + 1
+    #create data
+    if datadisk != rootdisk:
+        create_partitions_gpt(datadisk, 1, hostoptions["datasize"], "primary")
+    else:
+        create_partitions_gpt(datadisk, start_sector, hostoptions["datasize"], "primary")
+    
+    logging.debug("sleeping for 5 seconds")
+    time.sleep(5)
+
 
-    hostoptions["swappartition"] = create_partitions("/dev/"+rootdisk, hostoptions["swapsize"], "SWAP", 1)
 
-    #create extended partition
-    hostoptions["extended_partition"] = create_partitions("/dev/"+rootdisk, "all", "EXTENDED", 1)
 
-    #create the logical in the extended
-    hostoptions["home_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["homesize"], "LOGICAL", 1)
-    hostoptions["sql_partition"] = create_partitions("/dev/"+rootdisk, hostoptions["sqlsize"], "LOGICAL", 1)
 
-    if datadisk != rootdisk:
-        hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "NORMAL", 0)
-    else:
-        hostoptions["datapartition"] = create_partitions("/dev/"+datadisk, hostoptions["datasize"], "LOGICAL", 1)
 
-    logging.debug("sleeping for 5 seconds")
-    time.sleep(5)
 
 
 def fscmd(fstype):
@@ -1530,7 +1623,7 @@ def full_install(hostoptions):
         partition_disk()
     else:
         logging.debug("     Debug mode,  skipping partitioning step")
-
+    #sys.exit(0)
 #   Format disk
     statusmsg = "Preparing  %s"  %( hostoptions["rootdisk"])
     update_status(statusmsg)
@@ -2163,9 +2256,6 @@ for line in config_file:
 
 
 
-
-
-
 if __name__ == "__main__":
     config_file = "mv_config"
     data_config = __import__(config_file,  globals(),  locals(),  [])
-- 
cgit v0.12

