summaryrefslogtreecommitdiffstats
path: root/scripts/lib/mic/utils/partitionedfs.py
diff options
context:
space:
mode:
Diffstat (limited to 'scripts/lib/mic/utils/partitionedfs.py')
-rw-r--r--scripts/lib/mic/utils/partitionedfs.py94
1 files changed, 40 insertions, 54 deletions
diff --git a/scripts/lib/mic/utils/partitionedfs.py b/scripts/lib/mic/utils/partitionedfs.py
index 04758440e1..e8cded26e0 100644
--- a/scripts/lib/mic/utils/partitionedfs.py
+++ b/scripts/lib/mic/utils/partitionedfs.py
@@ -25,6 +25,7 @@ from mic.utils import runner
25from mic.utils.errors import MountError 25from mic.utils.errors import MountError
26from mic.utils.fs_related import * 26from mic.utils.fs_related import *
27from mic.utils.gpt_parser import GptParser 27from mic.utils.gpt_parser import GptParser
28from mic.utils.oe.misc import *
28 29
29# Overhead of the MBR partitioning scheme (just one sector) 30# Overhead of the MBR partitioning scheme (just one sector)
30MBR_OVERHEAD = 1 31MBR_OVERHEAD = 1
@@ -93,7 +94,7 @@ class PartitionedMount(Mount):
93 self.partitions.append(part) 94 self.partitions.append(part)
94 self.__add_disk(part['disk_name']) 95 self.__add_disk(part['disk_name'])
95 96
96 def add_partition(self, size, disk_name, mountpoint, fstype = None, 97 def add_partition(self, size, disk_name, mountpoint, source_file = None, fstype = None,
97 label=None, fsopts = None, boot = False, align = None, 98 label=None, fsopts = None, boot = False, align = None,
98 part_type = None): 99 part_type = None):
99 """ Add the next partition. Prtitions have to be added in the 100 """ Add the next partition. Prtitions have to be added in the
@@ -141,6 +142,7 @@ class PartitionedMount(Mount):
141 part = { 'ks_pnum' : ks_pnum, # Partition number in the KS file 142 part = { 'ks_pnum' : ks_pnum, # Partition number in the KS file
142 'size': size, # In sectors 143 'size': size, # In sectors
143 'mountpoint': mountpoint, # Mount relative to chroot 144 'mountpoint': mountpoint, # Mount relative to chroot
145 'source_file': source_file, # partition contents
144 'fstype': fstype, # Filesystem type 146 'fstype': fstype, # Filesystem type
145 'fsopts': fsopts, # Filesystem mount options 147 'fsopts': fsopts, # Filesystem mount options
146 'label': label, # Partition label 148 'label': label, # Partition label
@@ -723,67 +725,51 @@ class PartitionedMount(Mount):
723 725
724 self.snapshot_created = True 726 self.snapshot_created = True
725 727
728 def __install_partition(self, num, source_file, start, size):
729 """
730 Install source_file contents into a partition.
731 """
732 if not source_file: # nothing to install
733 return
734
735 # Start is included in the size so need to substract one from the end.
736 end = start + size - 1
737 msger.debug("Installed %s in partition %d, sectors %d-%d, size %d sectors" % (source_file, num, start, end, size))
738
739 dd_cmd = "dd if=%s of=%s bs=%d seek=%d count=%d conv=notrunc" % \
740 (source_file, self.image_file, self.sector_size, start, size)
741 rc, out = exec_cmd(dd_cmd)
742
743
744 def install(self, image_file):
745 msger.debug("Installing partitions")
746
747 self.image_file = image_file
748
749 for p in self.partitions:
750 d = self.disks[p['disk_name']]
751 if d['ptable_format'] == "msdos" and p['num'] == 5:
752 # The last sector of the 3rd partition was reserved for the EBR
753 # of the first _logical_ partition. This is why the extended
754 # partition should start one sector before the first logical
755 # partition.
756 self.__install_partition(p['num'], p['source_file'],
757 p['start'] - 1,
758 d['offset'] - p['start'])
759
760 self.__install_partition(p['num'], p['source_file'],
761 p['start'], p['size'])
762
726 def mount(self): 763 def mount(self):
727 for dev in self.disks.keys(): 764 for dev in self.disks.keys():
728 d = self.disks[dev] 765 d = self.disks[dev]
729 d['disk'].create() 766 d['disk'].create()
730 767
731 self.__format_disks() 768 self.__format_disks()
732 self.__map_partitions()
733 self.__calculate_mountorder()
734 769
735 for mp in self.mountOrder: 770 self.__calculate_mountorder()
736 p = None
737 for p1 in self.partitions:
738 if p1['mountpoint'] == mp:
739 p = p1
740 break
741
742 if not p['label']:
743 if p['mountpoint'] == "/":
744 p['label'] = 'platform'
745 else:
746 p['label'] = mp.split('/')[-1]
747
748 if mp == 'swap':
749 import uuid
750 p['uuid'] = str(uuid.uuid1())
751 runner.show([self.mkswap,
752 '-L', p['label'],
753 '-U', p['uuid'],
754 p['device']])
755 continue
756 771
757 rmmountdir = False 772 return
758 if p['mountpoint'] == "/":
759 rmmountdir = True
760 if p['fstype'] == "vfat" or p['fstype'] == "msdos":
761 myDiskMount = VfatDiskMount
762 elif p['fstype'] in ("ext2", "ext3", "ext4"):
763 myDiskMount = ExtDiskMount
764 elif p['fstype'] == "btrfs":
765 myDiskMount = BtrfsDiskMount
766 else:
767 raise MountError("Fail to support file system " + p['fstype'])
768
769 if p['fstype'] == "btrfs" and not p['fsopts']:
770 p['fsopts'] = "subvolid=0"
771
772 pdisk = myDiskMount(RawDisk(p['size'] * self.sector_size, p['device']),
773 self.mountdir + p['mountpoint'],
774 p['fstype'],
775 4096,
776 p['label'],
777 rmmountdir,
778 self.skipformat,
779 fsopts = p['fsopts'])
780 pdisk.mount(pdisk.fsopts)
781 if p['fstype'] == "btrfs" and p['mountpoint'] == "/":
782 if not self.skipformat:
783 self.__create_subvolumes(p, pdisk)
784 self.__mount_subvolumes(p, pdisk)
785 p['mount'] = pdisk
786 p['uuid'] = pdisk.uuid
787 773
788 def resparse(self, size = None): 774 def resparse(self, size = None):
789 # Can't re-sparse a disk image - too hard 775 # Can't re-sparse a disk image - too hard