for disk in self.disks:
disk.tear_down()
+ def write_fstab(self):
+ """
+ Writes the disk configuration to /etc/fstab
+ """
+ path = os.path.join(self.bricklayer.root, "etc/fstab")
+
+ with open(path, "w") as f:
+ for disk in self.selected:
+ for partition in disk.partitions:
+ e = partition.make_fstab_entry()
+
+ # Do nothing if the entry is empty
+ if not e:
+ continue
+
+ # Log the entry
+ log.debug(e)
+
+ # Write it to the file
+ f.write(e)
+
class Disk(object):
def __init__(self, bricklayer, device):
return self.parted.path
+ @property
+ def mountpoint(self):
+ """
+ Returns the mountpoint for this partition (or None)
+ """
+ if self.name == "ROOT":
+ return "/"
+
+ elif self.name == "ESP":
+ return "/boot/efi"
+
+ @property
+ def filesystem(self):
+ type = self.parted.fileSystem.type
+
+ # SWAP
+ if type == "linux-swap(v1)":
+ return "swap"
+
+ return type
+
def wipe(self):
"""
Wipes the entire partition (i.e. writes zeroes)
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))
+ log.info("Formatting %s (%s) with %s..." % \
+ (self.name, self.path, self.filesystem))
- if filesystem == "fat32":
+ if self.filesystem == "fat32":
command = ["mkfs.vfat", self.path]
- elif filesystem == "linux-swap(v1)":
+ elif self.filesystem == "swap":
command = ["mkswap", "-v1", self.path]
else:
- command = ["mkfs.%s" % filesystem, "-f", self.path]
+ command = ["mkfs.%s" % self.filesystem, "-f", self.path]
# Run command
self.bricklayer.command(command)
+ @property
+ def uuid(self):
+ """
+ Returns the UUID of the filesystem
+ """
+ uuid = self.bricklayer.command([
+ "blkid",
+
+ # Don't use the cache
+ "--probe",
+
+ # Return the UUID only
+ "--match-tag", "UUID",
+
+ # Only return the value
+ "--output", "value",
+
+ # Operate on this device
+ self.path,
+ ])
+
+ # Remove the trailing newline
+ return uuid.rstrip()
+
+ def make_fstab_entry(self):
+ """
+ Returns a /etc/fstab entry for this partition
+ """
+ # The bootloader partition does not get an entry
+ if self.name == "BOOTLDR":
+ return
+
+ return "UUID=%s %s %s defaults 0 0\n" % (
+ self.uuid,
+ self.mountpoint or "none",
+ self.filesystem,
+ )
+
class Scan(step.Step):
def run(self):
_("Umounting Filesystems"),
_("Umounting filesystems..."),
):
+ # Umount everything
self.bricklayer.disks.umount()
+
+
+class WriteFilesystemTable(step.Step):
+ def run(self):
+ self.bricklayer.disks.write_fstab()