예제 #1
0
    def run_format(self):
        """ Create partitions and file systems """
        # https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_ZFS
        # https://wiki.archlinux.org/index.php/ZFS#GRUB-compatible_pool_creation

        device_paths = self.zfs_options["device_paths"]
        logging.debug("Configuring ZFS in %s", ",".join(device_paths))

        # Read all preexisting zfs pools. If there's an antergos one, delete it.
        self.do_destroy_zfs_pools()

        # Wipe all disks that will be part of the installation.
        # This cannot be undone!
        self.init_device(device_paths[0], self.zfs_options["scheme"])
        for device_path in device_paths[1:]:
            self.init_device(device_path, "GPT")

        device_path = device_paths[0]
        solaris_partition_number = -1

        self.settings.set('bootloader_device', device_path)

        if self.zfs_options["scheme"] == "GPT":
            part_num = 1

            if not self.uefi:
                # BIOS and GPT
                # 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_path, part_num, "BIOS_BOOT", 2,
                                   "EF02")
                part_num += 1

                # Create BOOT partition
                wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT", 512,
                                   "8300")
                fs.create_fs(device_path + str(part_num), "ext4",
                             "ANTERGOS_BOOT")
                self.devices['boot'] = "{0}{1}".format(device_path, part_num)
                self.fs_devices[self.devices['boot']] = "ext4"
                self.mount_devices['/boot'] = self.devices['boot']
                part_num += 1
            else:
                # UEFI and GPT
                if self.bootloader == "grub2":
                    # Create EFI System Partition (ESP)
                    # GPT GUID: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
                    wrapper.sgdisk_new(device_path, part_num, "UEFI_SYSTEM",
                                       200, "EF00")
                    self.devices['efi'] = "{0}{1}".format(
                        device_path, part_num)
                    self.fs_devices[self.devices['efi']] = "vfat"
                    self.mount_devices['/boot/efi'] = self.devices['efi']
                    part_num += 1

                    # Create BOOT partition
                    wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT",
                                       512, "8300")
                    fs.create_fs(device_path + str(part_num), "ext4",
                                 "ANTERGOS_BOOT")
                    self.devices['boot'] = "{0}{1}".format(
                        device_path, part_num)
                    self.fs_devices[self.devices['boot']] = "ext4"
                    self.mount_devices['/boot'] = self.devices['boot']
                    part_num += 1
                else:
                    # systemd-boot, refind
                    # Create BOOT partition
                    wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT",
                                       512, "EF00")
                    fs.create_fs(device_path + str(part_num), "vfat",
                                 "ANTERGOS_BOOT")
                    self.devices['boot'] = "{0}{1}".format(
                        device_path, part_num)
                    self.fs_devices[self.devices['boot']] = "vfat"
                    self.mount_devices['/boot'] = self.devices['boot']
                    part_num += 1

            # The rest of the disk will be of solaris type
            wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_ZFS", 0,
                               "BF00")
            solaris_partition_number = part_num
            self.devices['root'] = "{0}{1}".format(device_path, part_num)
            # self.fs_devices[self.devices['root']] = "zfs"
            self.mount_devices['/'] = self.devices['root']
        else:
            # MBR

            # 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 = 512
            part = "1"
            wrapper.parted_mkpart(device_path, "primary", start, end)

            # Set boot partition as bootable
            wrapper.parted_set(device_path, part, "boot", "on")

            # Format the boot partition as well as any other system partitions.
            # Do not do anything to the Solaris partition nor to the BIOS boot
            # partition. ZFS will manage the first, and the bootloader the
            # second.

            if self.uefi:
                fs_boot = "vfat"
            else:
                fs_boot = "ext4"

            fs.create_fs(device_path + part, fs_boot, "ANTERGOS_BOOT")
            self.devices['boot'] = "{0}{1}".format(device_path, part)
            self.fs_devices[self.devices['boot']] = fs_boot
            self.mount_devices['/boot'] = self.devices['boot']

            # The rest of the disk will be of solaris type
            start = end
            wrapper.parted_mkpart(device_path, "primary", start, "-1s")
            solaris_partition_number = 2
            self.devices['root'] = "{0}{1}".format(device_path, 2)
            # self.fs_devices[self.devices['root']] = "zfs"
            self.mount_devices['/'] = self.devices['root']

        # Wait until /dev initialized correct devices
        call(["udevadm", "settle"])
        call(["sync"])
        '''
        if self.zfs_options["encrypt_disk"]:
            vol_name = self.devices['root'].split("/")[-1]
            password = self.zfs_options["encrypt_password"]

            ap.setup_luks(
                luks_device=self.devices['root'],
                luks_name=vol_name,
                luks_pass=password)

            self.settings.set("use_luks", True)
            self.settings.set("luks_root_password",  password)
            self.settings.set("luks_root_device",  self.devices['root'])

            # Encrypt the rest of drives
            for device_path in device_paths[1:]:
                vol_name = device_path.split("/")[-1]
                ap.setup_luks(
                    luks_device=device_path,
                    luks_name=vol_name,
                    luks_pass=password)
        '''

        self.create_zfs(solaris_partition_number)
예제 #2
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)
예제 #3
0
파일: zfs.py 프로젝트: FrankDev14/Cnchi
    def run_format(self):
        """ Create partitions and file systems """
        # https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_ZFS
        # https://wiki.archlinux.org/index.php/ZFS#GRUB-compatible_pool_creation

        device_paths = self.zfs_options["device_paths"]
        logging.debug("Configuring ZFS in %s", ",".join(device_paths))

        # Read all preexisting zfs pools. If there's an antergos one, delete it.
        self.do_destroy_zfs_pools()

        # Wipe all disks that will be part of the installation.
        # This cannot be undone!
        self.init_device(device_paths[0], self.zfs_options["scheme"])
        for device_path in device_paths[1:]:
            self.init_device(device_path, "GPT")

        device_path = device_paths[0]
        solaris_partition_number = -1

        self.settings.set('bootloader_device', device_path)

        if self.zfs_options["scheme"] == "GPT":
            part_num = 1

            if not self.uefi:
                # BIOS and GPT
                # 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_path, part_num, "BIOS_BOOT", 2, "EF02")
                part_num += 1

                # Create BOOT partition
                wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT", 512, "8300")
                fs.create_fs(device_path + str(part_num), "ext4", "ANTERGOS_BOOT")
                self.devices['boot'] = "{0}{1}".format(device_path, part_num)
                self.fs_devices[self.devices['boot']] = "ext4"
                self.mount_devices['/boot'] = self.devices['boot']
                part_num += 1
            else:
                # UEFI and GPT
                if self.bootloader == "grub2":
                    # Create EFI System Partition (ESP)
                    # GPT GUID: C12A7328-F81F-11D2-BA4B-00A0C93EC93B
                    wrapper.sgdisk_new(device_path, part_num, "UEFI_SYSTEM", 200, "EF00")
                    self.devices['efi'] = "{0}{1}".format(device_path, part_num)
                    self.fs_devices[self.devices['efi']] = "vfat"
                    self.mount_devices['/boot/efi'] = self.devices['efi']
                    part_num += 1

                    # Create BOOT partition
                    wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT", 512, "8300")
                    fs.create_fs(device_path + str(part_num), "ext4", "ANTERGOS_BOOT")
                    self.devices['boot'] = "{0}{1}".format(device_path, part_num)
                    self.fs_devices[self.devices['boot']] = "ext4"
                    self.mount_devices['/boot'] = self.devices['boot']
                    part_num += 1
                else:
                    # systemd-boot, refind
                    # Create BOOT partition
                    wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_BOOT", 512, "EF00")
                    fs.create_fs(device_path + str(part_num), "vfat", "ANTERGOS_BOOT")
                    self.devices['boot'] = "{0}{1}".format(device_path, part_num)
                    self.fs_devices[self.devices['boot']] = "vfat"
                    self.mount_devices['/boot'] = self.devices['boot']
                    part_num += 1

            # The rest of the disk will be of solaris type
            wrapper.sgdisk_new(device_path, part_num, "ANTERGOS_ZFS", 0, "BF00")
            solaris_partition_number = part_num
            self.devices['root'] = "{0}{1}".format(device_path, part_num)
            # self.fs_devices[self.devices['root']] = "zfs"
            self.mount_devices['/'] = self.devices['root']
        else:
            # MBR

            # 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 = 512
            part = "1"
            wrapper.parted_mkpart(device_path, "primary", start, end)

            # Set boot partition as bootable
            wrapper.parted_set(device_path, part, "boot", "on")

            # Format the boot partition as well as any other system partitions.
            # Do not do anything to the Solaris partition nor to the BIOS boot
            # partition. ZFS will manage the first, and the bootloader the
            # second.

            if self.uefi:
                fs_boot = "vfat"
            else:
                fs_boot = "ext4"

            fs.create_fs(device_path + part, fs_boot, "ANTERGOS_BOOT")
            self.devices['boot'] = "{0}{1}".format(device_path, part)
            self.fs_devices[self.devices['boot']] = fs_boot
            self.mount_devices['/boot'] = self.devices['boot']

            # The rest of the disk will be of solaris type
            start = end
            wrapper.parted_mkpart(device_path, "primary", start, "-1s")
            solaris_partition_number = 2
            self.devices['root'] = "{0}{1}".format(device_path, 2)
            # self.fs_devices[self.devices['root']] = "zfs"
            self.mount_devices['/'] = self.devices['root']

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

        self.create_zfs(solaris_partition_number)
예제 #4
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)