示例#1
0
def setup_luks(luks_device, luks_name, luks_pass=None, luks_key=None):
    """ Setups a luks device """

    if (luks_pass is None or luks_pass == "") and luks_key is None:
        txt = "Can't setup LUKS in device {0}. A password or a key file are needed".format(
            luks_device)
        logging.error(txt)
        return

    # For now, we we'll use the same password for root and /home
    # If instead user wants to use a key file, we'll have two different key files.

    logging.debug("Cnchi will setup LUKS on device %s", luks_device)

    # Wipe LUKS header (just in case we're installing on a pre LUKS setup)
    # For 512 bit key length the header is 2MiB
    # If in doubt, just be generous and overwrite the first 10MiB or so
    wrapper.dd("/dev/zero", luks_device, bs=512, count=20480)

    err_msg = "Can't format and open the LUKS device {0}".format(luks_device)

    if luks_pass is None or luks_pass == "":
        # No key password given, let's create a random keyfile
        wrapper.dd("/dev/urandom", luks_key, bs=1024, count=4)

        # Set up luks with a keyfile
        cmd = [
            "cryptsetup", "luksFormat", "-q", "-c", "aes-xts-plain", "-s",
            "512", luks_device, luks_key
        ]
        call(cmd, msg=err_msg, fatal=True)

        cmd = [
            "cryptsetup", "luksOpen", luks_device, luks_name, "-q",
            "--key-file", luks_key
        ]
        call(cmd, msg=err_msg, fatal=True)
    else:
        # Set up luks with a password key

        luks_pass_bytes = bytes(luks_pass, 'UTF-8')

        # https://code.google.com/p/cryptsetup/wiki/Cryptsetup160
        # aes-xts-plain
        # aes-cbc-essiv:sha256
        cmd = [
            "cryptsetup", "luksFormat", "-q", "-c", "aes-xts-plain64", "-s",
            "512", "--key-file=-", luks_device
        ]
        proc = popen(cmd, msg=err_msg, fatal=True)
        proc.communicate(input=luks_pass_bytes)

        cmd = [
            "cryptsetup", "luksOpen", luks_device, luks_name, "-q",
            "--key-file=-"
        ]
        proc = popen(cmd, msg=err_msg, fatal=True)
        proc.communicate(input=luks_pass_bytes)
示例#2
0
def setup_luks(luks_device, luks_name, luks_pass=None, luks_key=None):
    """ Setups a luks device """

    if (luks_pass is None or luks_pass == "") and luks_key is None:
        txt = "Can't setup LUKS in device {0}. A password or a key file are needed".format(luks_device)
        logging.error(txt)
        return

    # For now, we we'll use the same password for root and /home
    # If instead user wants to use a key file, we'll have two different key files.

    logging.debug("Cnchi will setup LUKS on device %s", luks_device)

    # Wipe LUKS header (just in case we're installing on a pre LUKS setup)
    # For 512 bit key length the header is 2MiB
    # If in doubt, just be generous and overwrite the first 10MiB or so
    wrapper.dd("/dev/zero", luks_device, bs=512, count=20480)

    err_msg = "Can't format and open the LUKS device {0}".format(luks_device)

    if luks_pass is None or luks_pass == "":
        # No key password given, let's create a random keyfile
        wrapper.dd("/dev/urandom", luks_key, bs=1024, count=4)

        # Set up luks with a keyfile
        cmd = [
            "cryptsetup", "luksFormat", "-q", "-c", "aes-xts-plain",
            "-s", "512", luks_device, luks_key]
        call(cmd, msg=err_msg, fatal=True)

        cmd = [
            "cryptsetup", "luksOpen", luks_device, luks_name, "-q",
            "--key-file", luks_key]
        call(cmd, msg=err_msg, fatal=True)
    else:
        # Set up luks with a password key

        luks_pass_bytes = bytes(luks_pass, 'UTF-8')

        # https://code.google.com/p/cryptsetup/wiki/Cryptsetup160
        # aes-xts-plain
        # aes-cbc-essiv:sha256
        cmd = [
            "cryptsetup", "luksFormat", "-q", "-c", "aes-xts-plain64",
            "-s", "512", "--key-file=-", luks_device]
        proc = popen(cmd, msg=err_msg, fatal=True)
        proc.communicate(input=luks_pass_bytes)

        cmd = [
            "cryptsetup", "luksOpen", luks_device, luks_name, "-q",
            "--key-file=-"]
        proc = popen(cmd, msg=err_msg, fatal=True)
        proc.communicate(input=luks_pass_bytes)
示例#3
0
文件: zfs.py 项目: imsory/Cnchi
    def init_device(self, device_path, scheme="GPT"):
        """ Initialize device """

        logging.debug("Zapping device %s...", device_path)

        offset = 20480

        # Zero out all GPT and MBR data structures
        wrapper.sgdisk("zap-all", device_path)

        # Clear all magic strings/signatures
        # Wipe out first "offset" sectors
        wrapper.dd("/dev/zero", device_path, bs=512, count=offset)

        # Clear the end "offset" sectors of the disk, too.
        try:
            seek = int(call(["blockdev", "--getsz", device_path])) - offset
            wrapper.dd("/dev/zero", device_path, bs=512, count=offset, seek=seek)
        except ValueError as ex:
            logging.warning(ex)

        if not wrapper.wipefs(device_path, fatal=False):
            pname, pid, _n = self.get_pool_id('_', include_offline=True)

            if self.do_destroy_zfs_pool():
                call(["udevadm", "settle"])
                call(["sync"])
                wrapper.wipefs(device_path, fatal=True)

        if scheme == "GPT":
            # Create fresh GPT table
            wrapper.sgdisk("clear", device_path)

            # Inform the kernel of the partition change.
            # Needed if the hard disk had a MBR partition table.
            call(["partprobe", device_path])
        else:
            # Create fresh MBR table
            wrapper.parted_mklabel(device_path, "msdos")

        """
        if self.zfs_options["encrypt_disk"]:
            from installation import auto_partition as ap
            vol_name = device_path.split("/")[-1]
            ap.setup_luks(
                luks_device=device_path,
                luks_name=vol_name,
                luks_pass=self.zfs_options["encrypt_password"])
            self.settings.set("use_luks", True)
        """

        call(["sync"])
示例#4
0
    def init_device(self, device_path, scheme="GPT"):
        """ Initialize device """

        logging.debug("Zapping device %s...", device_path)

        offset = 20480

        # Zero out all GPT and MBR data structures
        wrapper.sgdisk("zap-all", device_path)

        # Clear all magic strings/signatures
        # Wipe out first "offset" sectors
        wrapper.dd("/dev/zero", device_path, bs=512, count=offset)

        # Clear the end "offset" sectors of the disk, too.
        try:
            seek = int(call(["blockdev", "--getsz", device_path])) - offset
            wrapper.dd("/dev/zero",
                       device_path,
                       bs=512,
                       count=offset,
                       seek=seek)
        except ValueError as ex:
            logging.warning(ex)

        wrapper.wipefs(device_path, fatal=True)

        if scheme == "GPT":
            # Create fresh GPT table
            wrapper.sgdisk("clear", device_path)

            # Inform the kernel of the partition change.
            # Needed if the hard disk had a MBR partition table.
            call(["partprobe", device_path])
        else:
            # Create fresh MBR table
            wrapper.parted_mklabel(device_path, "msdos")
        """
        if self.zfs_options["encrypt_disk"]:
            from installation import auto_partition as ap
            vol_name = device_path.split("/")[-1]
            ap.setup_luks(
                luks_device=device_path,
                luks_name=vol_name,
                luks_pass=self.zfs_options["encrypt_password"])
            self.settings.set("use_luks", True)
        """

        call(["sync"])
示例#5
0
    def init_device(self, device_path, scheme="GPT"):
        """ Initialize device """

        logging.debug("Zapping device %s...", device_path)

        offset = 20480

        # Zero out all GPT and MBR data structures
        wrapper.sgdisk("zap-all", device_path)

        # Clear all magic strings/signatures
        # Wipe out first "offset" sectors
        wrapper.dd("/dev/zero", device_path, bs=512, count=offset)

        # Clear the end "offset" sectors of the disk, too.
        try:
            seek = int(call(["blockdev", "--getsz", device_path])) - offset
            wrapper.dd("/dev/zero",
                       device_path,
                       bs=512,
                       count=offset,
                       seek=seek)
        except ValueError as ex:
            logging.warning(ex)

        wrapper.wipefs(device_path, fatal=True)

        if scheme == "GPT":
            # Create fresh GPT table
            wrapper.sgdisk("clear", device_path)

            # Inform the kernel of the partition change.
            # Needed if the hard disk had a MBR partition table.
            call(["partprobe", device_path])
        else:
            # Create fresh MBR table
            wrapper.parted_mklabel(device_path, "msdos")

        call(["sync"])
示例#6
0
    def run(self):
        key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"]

        # Partition sizes are expressed in MiB
        # Get just the disk size in MiB
        device = self.auto_device
        device_name = os.path.split(device)[1]
        size_path = os.path.join("/sys/block", device_name, 'size')
        base_path = os.path.split(size_path)[0]
        if os.path.exists(size_path):
            logical_path = os.path.join(base_path, "queue/logical_block_size")
            with open(logical_path, 'r') as f:
                logical_block_size = int(f.read())
            with open(size_path, 'r') as f:
                size = int(f.read())
            disk_size = ((logical_block_size * (size - 68)) / 1024) / 1024
        else:
            logging.error("Cannot detect %s device size", device)
            txt = _(
                "Setup cannot detect size of your device, please use advanced "
                "installation routine for partitioning and mounting devices.")
            raise InstallError(txt)

        start_part_sizes = 1

        part_sizes = self.get_part_sizes(disk_size, start_part_sizes)
        self.log_part_sizes(part_sizes)

        # Disable swap and unmount all partitions inside dest_dir
        unmount_all_in_directory(self.dest_dir)
        # Disable swap and unmount all partitions of device
        unmount_all_in_device(device)
        # Remove lvm in destination device
        remove_lvm(device)
        # Close luks devices in destination device
        close_reborn_luks_devices()

        printk(False)

        # WARNING:
        # Our computed sizes are all in mebibytes (MiB) i.e. powers of 1024, not metric megabytes.
        # These are 'M' in sgdisk and 'MiB' in parted.
        # If you use 'M' in parted you'll get MB instead of MiB, and you're gonna have a bad time.

        if self.gpt:
            # Clean partition table to avoid issues!
            wrapper.sgdisk("zap-all", device)

            # Clear all magic strings/signatures - mdadm, lvm, partition tables etc.
            wrapper.dd("/dev/zero", device, bs=512, count=2048)
            wrapper.wipefs(device)

            # Create fresh GPT
            wrapper.sgdisk("clear", device)
            wrapper.parted_mklabel(device, "gpt")

            # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table.
            err_msg = "Error informing the kernel of the partition change."
            call(["partprobe", device], msg=err_msg, fatal=True)

            part_num = 1

            if not self.uefi:
                # We don't allow BIOS+GPT right now, so this code will be never executed
                # We leave here just for future reference
                # Create BIOS Boot Partition
                # GPT GUID: 21686148-6449-6E6F-744E-656564454649
                # This partition is not required if the system is UEFI based,
                # as there is no such embedding of the second-stage code in that case
                wrapper.sgdisk_new(device, part_num, "BIOS_BOOT", 2, "EF02")
                part_num += 1

            if self.bootloader == "grub2":
                # Create EFI System Partition (ESP)
                # GPT GUID: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
                wrapper.sgdisk_new(device, part_num, "UEFI_SYSTEM",
                                   part_sizes['efi'], "EF00")
                part_num += 1

            # Create Boot partition
            if self.bootloader in ["systemd-boot", "refind"]:
                wrapper.sgdisk_new(device, part_num, "REBORN_BOOT",
                                   part_sizes['boot'], "EF00")
            else:
                wrapper.sgdisk_new(device, part_num, "REBORN_BOOT",
                                   part_sizes['boot'], "8300")
            part_num += 1

            if self.lvm:
                # Create partition for lvm (will store root, swap and home (if desired) logical volumes)
                wrapper.sgdisk_new(device, part_num, "REBORN_LVM",
                                   part_sizes['lvm_pv'], "8E00")
                part_num += 1
            else:
                wrapper.sgdisk_new(device, part_num, "REBORN_ROOT",
                                   part_sizes['root'], "8300")
                part_num += 1
                if self.home:
                    wrapper.sgdisk_new(device, part_num, "REBORN_HOME",
                                       part_sizes['home'], "8302")
                    part_num += 1
                wrapper.sgdisk_new(device, part_num, "REBORN_SWAP", 0, "8200")

            output = call(["sgdisk", "--print", device])
            logging.debug(output)
        else:
            # DOS MBR partition table
            # Start at sector 1 for 4k drive compatibility and correct alignment
            # Clean partitiontable to avoid issues!
            wrapper.dd("/dev/zero", device, bs=512, count=2048)
            wrapper.wipefs(device)

            # Create DOS MBR
            wrapper.parted_mklabel(device, "msdos")

            # Create boot partition (all sizes are in MiB)
            # if start is -1 wrapper.parted_mkpart assumes that our partition starts at 1 (first partition in disk)
            start = -1
            end = part_sizes['boot']
            wrapper.parted_mkpart(device, "primary", start, end)

            # Set boot partition as bootable
            wrapper.parted_set(device, "1", "boot", "on")

            if self.lvm:
                # Create partition for lvm (will store root, home (if desired), and swap logical volumes)
                start = end
                # end = start + part_sizes['lvm_pv']
                end = "-1s"
                wrapper.parted_mkpart(device, "primary", start, end)

                # Set lvm flag
                wrapper.parted_set(device, "2", "lvm", "on")
            else:
                # Create root partition
                start = end
                end = start + part_sizes['root']
                wrapper.parted_mkpart(device, "primary", start, end)

                if self.home:
                    # Create home partition
                    start = end
                    end = start + part_sizes['home']
                    wrapper.parted_mkpart(device, "primary", start, end)

                # Create an extended partition where we will put our swap partition
                start = end
                # end = start + part_sizes['swap']
                end = "-1s"
                wrapper.parted_mkpart(device, "extended", start, end)

                # Now create a logical swap partition
                start += 1
                end = "-1s"
                wrapper.parted_mkpart(device, "logical", start, end,
                                      "linux-swap")

        printk(True)

        # Wait until /dev initialized correct devices
        call(["udevadm", "settle"])

        devices = self.get_devices()

        if self.gpt and self.bootloader == "grub2":
            logging.debug("EFI: %s", devices['efi'])

        logging.debug("Boot: %s", devices['boot'])
        logging.debug("Root: %s", devices['root'])

        if self.home:
            logging.debug("Home: %s", devices['home'])

        logging.debug("Swap: %s", devices['swap'])

        if self.luks:
            setup_luks(devices['luks_root'], "cryptReborn", self.luks_password,
                       key_files[0])
            if self.home and not self.lvm:
                setup_luks(devices['luks_home'], "cryptRebornHome",
                           self.luks_password, key_files[1])

        if self.lvm:
            logging.debug("Cnchi will setup LVM on device %s", devices['lvm'])

            err_msg = "Error creating LVM physical volume in device {0}"
            err_msg = err_msg.format(devices['lvm'])
            cmd = ["pvcreate", "-f", "-y", devices['lvm']]
            call(cmd, msg=err_msg, fatal=True)

            err_msg = "Error creating LVM volume group in device {0}"
            err_msg = err_msg.format(devices['lvm'])
            cmd = ["vgcreate", "-f", "-y", "RebornVG", devices['lvm']]
            call(cmd, msg=err_msg, fatal=True)

            # Fix issue 180
            # Check space we have now for creating logical volumes
            cmd = ["vgdisplay", "-c", "RebornVG"]
            vg_info = call(cmd, fatal=True)
            # Get column number 12: Size of volume group in kilobytes
            vg_size = int(vg_info.split(":")[11]) / 1024
            if part_sizes['lvm_pv'] > vg_size:
                logging.debug("Real RebornVG volume group size: %d MiB",
                              vg_size)
                logging.debug("Reajusting logical volume sizes")
                diff_size = part_sizes['lvm_pv'] - vg_size
                part_sizes = self.get_part_sizes(disk_size - diff_size,
                                                 start_part_sizes)
                self.log_part_sizes(part_sizes)

            # Create LVM volumes
            err_msg = "Error creating LVM logical volume"

            size = str(int(part_sizes['root']))
            cmd = [
                "lvcreate", "--name", "RebornRoot", "--size", size, "RebornVG"
            ]
            call(cmd, msg=err_msg, fatal=True)

            if not self.home:
                # Use the remainig space for our swap volume
                cmd = [
                    "lvcreate", "--name", "RebornSwap", "--extents",
                    "100%FREE", "RebornVG"
                ]
                call(cmd, msg=err_msg, fatal=True)
            else:
                size = str(int(part_sizes['swap']))
                cmd = [
                    "lvcreate", "--name", "RebornSwap", "--size", size,
                    "RebornVG"
                ]
                call(cmd, msg=err_msg, fatal=True)
                # Use the remaining space for our home volume
                cmd = [
                    "lvcreate", "--name", "RebornHome", "--extents",
                    "100%FREE", "RebornVG"
                ]
                call(cmd, msg=err_msg, fatal=True)

        # We have all partitions and volumes created. Let's create its filesystems with mkfs.

        mount_points = {
            'efi': '/boot/efi',
            'boot': '/boot',
            'root': '/',
            'home': '/home',
            'swap': ''
        }

        labels = {
            'efi': 'UEFI_SYSTEM',
            'boot': 'RebornBoot',
            'root': 'RebornRoot',
            'home': 'RebornHome',
            'swap': 'RebornSwap'
        }

        fs_devices = self.get_fs_devices()

        # Note: Make sure the "root" partition is defined first!
        self.mkfs(devices['root'], fs_devices[devices['root']],
                  mount_points['root'], labels['root'])
        self.mkfs(devices['swap'], fs_devices[devices['swap']],
                  mount_points['swap'], labels['swap'])

        if self.gpt and self.bootloader in ["refind", "systemd-boot"]:
            # Format EFI System Partition (ESP) with vfat (fat32)
            self.mkfs(devices['boot'], fs_devices[devices['boot']],
                      mount_points['boot'], labels['boot'], "-F 32")
        else:
            self.mkfs(devices['boot'], fs_devices[devices['boot']],
                      mount_points['boot'], labels['boot'])

        # Note: Make sure the "boot" partition is defined before the "efi" one!
        if self.gpt and self.bootloader == "grub2":
            # Format EFI System Partition (ESP) with vfat (fat32)
            self.mkfs(devices['efi'], fs_devices[devices['efi']],
                      mount_points['efi'], labels['efi'], "-F 32")

        if self.home:
            self.mkfs(devices['home'], fs_devices[devices['home']],
                      mount_points['home'], labels['home'])

        # NOTE: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in process.py if necessary
        # NOTE: /etc/default/grub, /etc/stab and /etc/crypttab will be modified in process.py, too.

        if self.luks and self.luks_password == "":
            # Copy root keyfile to boot partition and home keyfile to root partition
            # user will choose what to do with it
            # THIS IS NONSENSE (BIG SECURITY HOLE), BUT WE TRUST THE USER TO FIX THIS
            # User shouldn't store the keyfiles unencrypted unless the medium itself is reasonably safe
            # (boot partition is not)

            err_msg = "Can't copy LUKS keyfile to the installation device."
            os.chmod(key_files[0], 0o400)
            boot_path = os.path.join(self.dest_dir, "boot")
            cmd = ['mv', key_files[0], boot_path]
            call(cmd, msg=err_msg)
            if self.home and not self.lvm:
                os.chmod(key_files[1], 0o400)
                luks_dir = os.path.join(self.dest_dir, 'etc/luks-keys')
                os.makedirs(luks_dir, mode=0o755, exist_ok=True)
                cmd = ['mv', key_files[1], luks_dir]
                call(cmd, msg=err_msg)
示例#7
0
    def run(self):
        key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"]

        # Partition sizes are expressed in MiB
        # Get just the disk size in MiB
        device = self.auto_device
        device_name = os.path.split(device)[1]
        size_path = os.path.join("/sys/block", device_name, "size")
        base_path = os.path.split(size_path)[0]
        if os.path.exists(size_path):
            logical_path = os.path.join(base_path, "queue/logical_block_size")
            with open(logical_path, "r") as f:
                logical_block_size = int(f.read())
            with open(size_path, "r") as f:
                size = int(f.read())
            disk_size = ((logical_block_size * (size - 68)) / 1024) / 1024
        else:
            logging.error("Cannot detect %s device size", device)
            txt = _(
                "Setup cannot detect size of your device, please use advanced "
                "installation routine for partitioning and mounting devices."
            )
            raise InstallError(txt)

        start_part_sizes = 1

        part_sizes = self.get_part_sizes(disk_size, start_part_sizes)
        self.log_part_sizes(part_sizes)

        # Disable swap and unmount all partitions inside dest_dir
        unmount_all_in_directory(self.dest_dir)
        # Disable swap and unmount all partitions of device
        unmount_all_in_device(device)
        # Remove lvm in destination device
        remove_lvm(device)
        # Close luks devices in destination device
        close_antergos_luks_devices()

        printk(False)

        # WARNING:
        # Our computed sizes are all in mebibytes (MiB) i.e. powers of 1024, not metric megabytes.
        # These are 'M' in sgdisk and 'MiB' in parted.
        # If you use 'M' in parted you'll get MB instead of MiB, and you're gonna have a bad time.

        if self.gpt:
            # Clean partition table to avoid issues!
            wrapper.sgdisk("zap-all", device)

            # Clear all magic strings/signatures - mdadm, lvm, partition tables etc.
            wrapper.dd("/dev/zero", device, bs=512, count=2048)
            wrapper.wipefs(device)

            # Create fresh GPT
            wrapper.sgdisk("clear", device)
            wrapper.parted_mklabel(device, "gpt")

            # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table.
            err_msg = "Error informing the kernel of the partition change."
            call(["partprobe", device], msg=err_msg, fatal=True)

            part_num = 1

            if not self.uefi:
                # We don't allow BIOS+GPT right now, so this code will be never executed
                # We leave here just for future reference
                # Create BIOS Boot Partition
                # GPT GUID: 21686148-6449-6E6F-744E-656564454649
                # This partition is not required if the system is UEFI based,
                # as there is no such embedding of the second-stage code in that case
                wrapper.sgdisk_new(device, part_num, "BIOS_BOOT", 2, "EF02")
                part_num += 1

            if self.bootloader == "grub2":
                # Create EFI System Partition (ESP)
                # GPT GUID: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
                wrapper.sgdisk_new(device, part_num, "UEFI_SYSTEM", part_sizes["efi"], "EF00")
                part_num += 1

            # Create Boot partition
            if self.bootloader in ["systemd-boot", "refind"]:
                wrapper.sgdisk_new(device, part_num, "ANTERGOS_BOOT", part_sizes["boot"], "EF00")
            else:
                wrapper.sgdisk_new(device, part_num, "ANTERGOS_BOOT", part_sizes["boot"], "8300")
            part_num += 1

            if self.lvm:
                # Create partition for lvm (will store root, swap and home (if desired) logical volumes)
                wrapper.sgdisk_new(device, part_num, "ANTERGOS_LVM", part_sizes["lvm_pv"], "8E00")
                part_num += 1
            else:
                wrapper.sgdisk_new(device, part_num, "ANTERGOS_ROOT", part_sizes["root"], "8300")
                part_num += 1
                if self.home:
                    wrapper.sgdisk_new(device, part_num, "ANTERGOS_HOME", part_sizes["home"], "8302")
                    part_num += 1
                wrapper.sgdisk_new(device, part_num, "ANTERGOS_SWAP", 0, "8200")

            output = call(["sgdisk", "--print", device])
            logging.debug(output)
        else:
            # DOS MBR partition table
            # Start at sector 1 for 4k drive compatibility and correct alignment
            # Clean partitiontable to avoid issues!
            wrapper.dd("/dev/zero", device, bs=512, count=2048)
            wrapper.wipefs(device)

            # Create DOS MBR
            wrapper.parted_mklabel(device, "msdos")

            # Create boot partition (all sizes are in MiB)
            # if start is -1 wrapper.parted_mkpart assumes that our partition starts at 1 (first partition in disk)
            start = -1
            end = part_sizes["boot"]
            wrapper.parted_mkpart(device, "primary", start, end)

            # Set boot partition as bootable
            wrapper.parted_set(device, "1", "boot", "on")

            if self.lvm:
                # Create partition for lvm (will store root, home (if desired), and swap logical volumes)
                start = end
                # end = start + part_sizes['lvm_pv']
                end = "-1s"
                wrapper.parted_mkpart(device, "primary", start, end)

                # Set lvm flag
                wrapper.parted_set(device, "2", "lvm", "on")
            else:
                # Create root partition
                start = end
                end = start + part_sizes["root"]
                wrapper.parted_mkpart(device, "primary", start, end)

                if self.home:
                    # Create home partition
                    start = end
                    end = start + part_sizes["home"]
                    wrapper.parted_mkpart(device, "primary", start, end)

                # Create an extended partition where we will put our swap partition
                start = end
                # end = start + part_sizes['swap']
                end = "-1s"
                wrapper.parted_mkpart(device, "extended", start, end)

                # Now create a logical swap partition
                start += 1
                end = "-1s"
                wrapper.parted_mkpart(device, "logical", start, end, "linux-swap")

        printk(True)

        # Wait until /dev initialized correct devices
        call(["udevadm", "settle"])

        devices = self.get_devices()

        if self.gpt and self.bootloader == "grub2":
            logging.debug("EFI: %s", devices["efi"])

        logging.debug("Boot: %s", devices["boot"])
        logging.debug("Root: %s", devices["root"])

        if self.home:
            logging.debug("Home: %s", devices["home"])

        logging.debug("Swap: %s", devices["swap"])

        if self.luks:
            setup_luks(devices["luks_root"], "cryptAntergos", self.luks_password, key_files[0])
            if self.home and not self.lvm:
                setup_luks(devices["luks_home"], "cryptAntergosHome", self.luks_password, key_files[1])

        if self.lvm:
            logging.debug("Cnchi will setup LVM on device %s", devices["lvm"])

            err_msg = "Error creating LVM physical volume in device {0}"
            err_msg = err_msg.format(devices["lvm"])
            cmd = ["pvcreate", "-f", "-y", devices["lvm"]]
            call(cmd, msg=err_msg, fatal=True)

            err_msg = "Error creating LVM volume group in device {0}"
            err_msg = err_msg.format(devices["lvm"])
            cmd = ["vgcreate", "-f", "-y", "AntergosVG", devices["lvm"]]
            call(cmd, msg=err_msg, fatal=True)

            # Fix issue 180
            # Check space we have now for creating logical volumes
            cmd = ["vgdisplay", "-c", "AntergosVG"]
            vg_info = call(cmd, fatal=True)
            # Get column number 12: Size of volume group in kilobytes
            vg_size = int(vg_info.split(":")[11]) / 1024
            if part_sizes["lvm_pv"] > vg_size:
                logging.debug("Real AntergosVG volume group size: %d MiB", vg_size)
                logging.debug("Reajusting logical volume sizes")
                diff_size = part_sizes["lvm_pv"] - vg_size
                part_sizes = self.get_part_sizes(disk_size - diff_size, start_part_sizes)
                self.log_part_sizes(part_sizes)

            # Create LVM volumes
            err_msg = "Error creating LVM logical volume"

            size = str(int(part_sizes["root"]))
            cmd = ["lvcreate", "--name", "AntergosRoot", "--size", size, "AntergosVG"]
            call(cmd, msg=err_msg, fatal=True)

            if not self.home:
                # Use the remainig space for our swap volume
                cmd = ["lvcreate", "--name", "AntergosSwap", "--extents", "100%FREE", "AntergosVG"]
                call(cmd, msg=err_msg, fatal=True)
            else:
                size = str(int(part_sizes["swap"]))
                cmd = ["lvcreate", "--name", "AntergosSwap", "--size", size, "AntergosVG"]
                call(cmd, msg=err_msg, fatal=True)
                # Use the remaining space for our home volume
                cmd = ["lvcreate", "--name", "AntergosHome", "--extents", "100%FREE", "AntergosVG"]
                call(cmd, msg=err_msg, fatal=True)

        # We have all partitions and volumes created. Let's create its filesystems with mkfs.

        mount_points = {"efi": "/boot/efi", "boot": "/boot", "root": "/", "home": "/home", "swap": ""}

        labels = {
            "efi": "UEFI_SYSTEM",
            "boot": "AntergosBoot",
            "root": "AntergosRoot",
            "home": "AntergosHome",
            "swap": "AntergosSwap",
        }

        fs_devices = self.get_fs_devices()

        # Note: Make sure the "root" partition is defined first!
        self.mkfs(devices["root"], fs_devices[devices["root"]], mount_points["root"], labels["root"])
        self.mkfs(devices["swap"], fs_devices[devices["swap"]], mount_points["swap"], labels["swap"])

        if self.gpt and self.bootloader in ["refind", "systemd-boot"]:
            # Format EFI System Partition (ESP) with vfat (fat32)
            self.mkfs(devices["boot"], fs_devices[devices["boot"]], mount_points["boot"], labels["boot"], "-F 32")
        else:
            self.mkfs(devices["boot"], fs_devices[devices["boot"]], mount_points["boot"], labels["boot"])

        # Note: Make sure the "boot" partition is defined before the "efi" one!
        if self.gpt and self.bootloader == "grub2":
            # Format EFI System Partition (ESP) with vfat (fat32)
            self.mkfs(devices["efi"], fs_devices[devices["efi"]], mount_points["efi"], labels["efi"], "-F 32")

        if self.home:
            self.mkfs(devices["home"], fs_devices[devices["home"]], mount_points["home"], labels["home"])

        # NOTE: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in process.py if necessary
        # NOTE: /etc/default/grub, /etc/stab and /etc/crypttab will be modified in process.py, too.

        if self.luks and self.luks_password == "":
            # Copy root keyfile to boot partition and home keyfile to root partition
            # user will choose what to do with it
            # THIS IS NONSENSE (BIG SECURITY HOLE), BUT WE TRUST THE USER TO FIX THIS
            # User shouldn't store the keyfiles unencrypted unless the medium itself is reasonably safe
            # (boot partition is not)

            err_msg = "Can't copy LUKS keyfile to the installation device."
            os.chmod(key_files[0], 0o400)
            boot_path = os.path.join(self.dest_dir, "boot")
            cmd = ["mv", key_files[0], boot_path]
            call(cmd, msg=err_msg)
            if self.home and not self.lvm:
                os.chmod(key_files[1], 0o400)
                luks_dir = os.path.join(self.dest_dir, "etc/luks-keys")
                os.makedirs(luks_dir, mode=0o755, exist_ok=True)
                cmd = ["mv", key_files[1], luks_dir]
                call(cmd, msg=err_msg)