Ejemplo n.º 1
0
    def setup_disks(self):
        parted = self.parted.prefix("-s", "--", self.image_path)

        parted("mklabel", "gpt")

        parted("mkpart", "nofs", "1", "2", "set", "1", "bios_grub", "on")

        parted("mkpart", "primary", "2", "-1", "set", "2", "lvm", "on")

        parted("print")

        with mounted_loopback(self.image_path) as devices:
            for loop_device, partitions in devices.items():
                if len(partitions) < 2:
                    log.warning("Ignoring {0}: too few partitions")
                    continue

                self.lvm("pvcreate", partitions[1])
                self.lvm("vgcreate", self.volume_group, partitions[1])

                self.lvm("lvcreate", "-L", "512M", "-n", "boot",
                         self.volume_group)

                self.lvm("lvcreate", "-L", self.root_size.formatted, "-n",
                         "root", self.volume_group)

                self.lvm("lvcreate", "-l", '100%FREE', "-n", "swap",
                         self.volume_group)

                with available_lvm(self.volume_group) as lv:
                    log.info("formatting logical volumes")
                    self.mkfs_ext4(lv['boot'])
                    self.mkfs_ext4(lv['root'])
                    self.mkswap("-f", lv['swap'])
Ejemplo n.º 2
0
def action(ns):
    """
    Create base image with lvm.
    """
    if not ns.force and os.path.isfile(ns.path):
        raise Exception("path already exists: {0}".format(ns.path))

    with open(ns.path, "w") as f:
        f.truncate(ns.size.size)

    parted("-s", "--", ns.path, "mklabel", "gpt")
    parted("-s", "--", ns.path, "mkpart", "no-fs", "1", "2", "set", "1",
           "bios_grub", "on")
    parted("-s", "--", ns.path, "mkpart", "primary", "2", "-1", "set", "2",
           "lvm", "on")
    parted("-s", "--", ns.path, "print")

    with mounted_loopback(ns.path) as devices:
        for loop_device, subdevices in devices.items():
            if len(subdevices) < 2:
                log.warning("Ignoring {0}: too few partitions")
                continue

            lvm("pvcreate", subdevices[1])
            lvm("vgcreate", ns.volume_group, subdevices[1])
            lvm("lvcreate", "-L", "7G", "-n", "root", ns.volume_group)
            lvm("lvcreate", "-l", '100%FREE', "-n", "swap", ns.volume_group)

            with available_lvm(ns.volume_group) as logical_volumes:
                log.info("formatting logical volumes")
                mkfs_ext4(logical_volumes[0])
                mkswap("-f", logical_volumes[1])

    return 0
Ejemplo n.º 3
0
    def setup_disks(self):
        parted = self.parted.prefix("-s", "--", self.image_path)

        parted("mklabel", "gpt")

        parted(
            "mkpart", "nofs", "1", "2",
            "set", "1", "bios_grub", "on"
        )

        parted(
            "mkpart", "primary", "2", "-1",
            "set", "2", "lvm", "on"
        )

        parted("print")

        with mounted_loopback(self.image_path) as devices:
            for loop_device, partitions in devices.items():
                if len(partitions) < 2:
                    log.warning("Ignoring {0}: too few partitions")
                    continue

                self.lvm("pvcreate", partitions[1])
                self.lvm("vgcreate", self.volume_group, partitions[1])

                self.lvm(
                    "lvcreate", "-L", "512M", "-n", "boot", self.volume_group
                )

                self.lvm(
                    "lvcreate", "-L", self.root_size.formatted,
                    "-n", "root", self.volume_group
                )

                self.lvm(
                    "lvcreate", "-l", '100%FREE', "-n", "swap", self.volume_group
                )

                with available_lvm(self.volume_group) as lv:
                    log.info("formatting logical volumes")
                    self.mkfs_ext4(lv['boot'])
                    self.mkfs_ext4(lv['root'])
                    self.mkswap("-f", lv['swap'])
Ejemplo n.º 4
0
def action(ns):
    """
    Invoke debootstrap on an already created image.
    """
    if not os.path.isfile(ns.path):
        raise Exception("No such file: {0}".format(ns.path))

    if not os.path.isdir(ns.mountpoint):
        log.info("Creating mountpoint: {0}".format(ns.mountpoint))
        os.makedirs(ns.mountpoint)

    with mounted_loopback(ns.path):
        with available_lvm(ns.volume_group) as logical_volumes:
            with mounted_device(logical_volumes[0], ns.mountpoint):
                log.info("Installing on {0}".format(ns.mountpoint))
                debootstrap("--arch", ns.arch, ns.suite, ns.mountpoint,
                            ns.mirror)

    return 0
Ejemplo n.º 5
0
def action(ns):
    """
    Invoke debootstrap on an already created image.
    """
    if not os.path.isfile(ns.path):
        raise Exception("No such file: {0}".format(ns.path))

    if not os.path.isdir(ns.mountpoint):
        log.info("Creating mountpoint: {0}".format(ns.mountpoint))
        os.makedirs(ns.mountpoint)

    with mounted_loopback(ns.path):
        with available_lvm(ns.volume_group) as logical_volumes:
            with mounted_device(logical_volumes[0], ns.mountpoint):
                log.info("Installing on {0}".format(ns.mountpoint))
                debootstrap("--arch", ns.arch, ns.suite,
                            ns.mountpoint, ns.mirror)

    return 0
Ejemplo n.º 6
0
def action(ns):
    """
    Create base image with lvm.
    """
    if not ns.force and os.path.isfile(ns.path):
        raise Exception("path already exists: {0}".format(ns.path))

    with open(ns.path, "w") as f:
        f.truncate(ns.size.size)

    parted("-s", "--", ns.path,
           "mklabel", "gpt")
    parted("-s", "--", ns.path,
           "mkpart", "no-fs", "1", "2",
           "set", "1", "bios_grub", "on")
    parted("-s", "--", ns.path,
           "mkpart", "primary", "2", "-1",
           "set", "2", "lvm", "on")
    parted("-s", "--", ns.path, "print")

    with mounted_loopback(ns.path) as devices:
        for loop_device, subdevices in devices.items():
            if len(subdevices) < 2:
                log.warning("Ignoring {0}: too few partitions")
                continue

            lvm("pvcreate", subdevices[1])
            lvm("vgcreate", ns.volume_group, subdevices[1])
            lvm("lvcreate", "-L", "7G", "-n", "root", ns.volume_group)
            lvm("lvcreate", "-l", '100%FREE', "-n", "swap", ns.volume_group)

            with available_lvm(ns.volume_group) as logical_volumes:
                log.info("formatting logical volumes")
                mkfs_ext4(logical_volumes[0])
                mkswap("-f", logical_volumes[1])

    return 0