def size(self):
return self.device.length * self.device.sectorSize
+ @property
+ def partitions(self):
+ """
+ Returns a list of all partitions on this device
+ """
+ return [Partition(self.bricklayer, p) for p in self.parted.partitions]
+
def create_system_partitions(self):
"""
This method creates a basic partition layout on this disk with all
# Write the new partition table
self.parted.commit()
+ # For loop devices, we have to manually create the partition mappings
+ if self.path.startswith("/dev/loop"):
+ self.bricklayer.command(["kpartx", "-av", self.path])
+
+
+class Partition(object):
+ def __init__(self, bricklayer, parted):
+ self.bricklayer = bricklayer
+
+ # The parted device
+ self.parted = parted
+
+ def __repr__(self):
+ return "<%s %s>" % (self.__class__.__name__, self.name or self.path)
+
+ @property
+ def name(self):
+ return self.parted.name
+
+ @property
+ def path(self):
+ # Map path for loop devices
+ if self.parted.path.startswith("/dev/loop"):
+ return self.parted.path.replace("/dev/loop", "/dev/mapper/loop")
+
+ return self.parted.path
+
+ def wipe(self):
+ """
+ Wipes the entire partition (i.e. writes zeroes)
+ """
+ log.info("Wiping %s (%s)..." % (self.name, self.path))
+
+ zero = bytearray(1024)
+
+ with open(self.path, "wb") as f:
+ f.write(zero)
+
+ def format(self):
+ """
+ Formats the filesystem
+ """
+ # Wipe BIOS_GRUB partitions instead of formatting them
+ if self.parted.getFlag(parted.PARTITION_BIOS_GRUB):
+ return self.wipe()
+
+ # Fetch file-system type
+ filesystem = self.parted.fileSystem.type
+
+ log.info("Formatting %s (%s) with %s..." % (self.name, self.path, filesystem))
+
+ if filesystem == "fat32":
+ command = ["mkfs.vfat", self.path]
+ elif filesystem == "linux-swap(v1)":
+ command = ["mkswap", "-v1", self.path]
+ else:
+ command = ["mkfs.%s" % filesystem, self.path]
+
+ # Run command
+ self.bricklayer.command(command)
+
class SelectDisk(step.InteractiveStep):
"""
for disk in self.bricklayer.disks.selected:
disk.commit()
+
+
+class CreateFilesystems(step.Step):
+ """
+ Formats all newly created partitions
+ """
+ def run(self, tui):
+ for disk in self.bricklayer.disks.selected:
+ for partition in disk.partitions:
+ partition.format()