DeviceManager : support GPT
[vuplus_dvbapp] / lib / python / Components / Harddisk.py
old mode 100644 (file)
new mode 100755 (executable)
index 838e83f..7500c33
@@ -212,7 +212,32 @@ class Harddisk:
                 return False
 
        def createPartition(self):
-               cmd = 'printf "8,\n;0,0\n;0,0\n;0,0\ny\n" | sfdisk -f -uS ' + self.disk_path
+               def CheckPartedVer():
+                       cmd = 'parted --version'
+                       lines = popen(cmd).readlines()
+                       for l in lines:
+                               if l.find("parted (GNU parted)") != -1:
+                                       ver = l.split()[3].strip()
+                                       break
+                       try:
+                               ver = float(ver)
+                       except:
+                               print "[CheckPartedVer] check parted version Failed!"
+                               return 0
+                       return ver
+
+               disk_size = self.diskSize()
+
+               if disk_size > 2.2 * 1000 * 1000: # if 2.2 TB
+                       setAlign = ""
+                       partedVer = CheckPartedVer()
+                       if partedVer >= 2.1: # align option is supported in version 2.1 or later
+                               setAlign = "--align optimal"
+                       cmd = 'parted %s %s --script mklabel gpt mkpart disk ext2 0%% 100%%' % ( setAlign, self.disk_path )
+
+               else:
+                       cmd = 'printf "8,\n;0,0\n;0,0\n;0,0\ny\n" | sfdisk -f -uS ' + self.disk_path
+
                res = system(cmd)
                if not self.checkPartionPath(self.partitionPath("1")):
                        print "no exist : ", self.partitionPath("1")