def on_cli_button_clicked(self, widget, data=None): try: subprocess.Popen(["cinnarch-setup"]) except: warning(_("Can't load the CLI installer")) finally: self.remove_temp_files()
def on_cli_button_clicked(self, widget, data=None): cli_installer = "antergos-setup" try: subprocess.Popen([cli_installer]) except: warning(_("Can't load the CLI installer")) finally: self.remove_temp_files()
def set_resize_widget(self, device_to_shrink): new_device = self.get_new_device(device_to_shrink) if new_device is None: # No device is available logging.error("There are no primary partitions available") return txt = "Will shrink device {0} and create new device {1}".format( device_to_shrink, new_device) logging.debug(txt) (min_size, part_size) = get_partition_size_info(device_to_shrink) max_size = part_size - (MIN_ROOT_SIZE * 1000.0) if max_size < 0: # Full Reborn does not fit but maybe base fits... ask user. txt = _( "Cnchi recommends at least 6.5GB free to install Reborn OS." ) + "\n\n" txt += _( "New partition {0} resulting of shrinking {1} will not have enough free space for a full installation." ).format(new_device, device_to_shrink) + "\n\n" txt += _( "You can still install Reborn OS, but be carefull on which DE you choose as it might not fit in." ) + "\n\n" txt += _("Install at your own risk!") show.warning(self.get_main_window(), txt) max_size = part_size # print(min_size, max_size, part_size) if self.resize_widget: self.resize_widget.set_property('part_size', int(part_size)) self.resize_widget.set_property('min_size', int(min_size)) self.resize_widget.set_property('max_size', int(max_size)) else: self.resize_widget = gtkwidgets.ResizeWidget( part_size, min_size, max_size) main_box = self.ui.get_object('alongside') main_box.pack_start(self.resize_widget, True, False, 5) self.resize_widget.set_part_title('existing', self.oses[device_to_shrink], device_to_shrink) icon_file = self.get_distributor_icon_file(self.oses[device_to_shrink]) self.resize_widget.set_part_icon('existing', icon_file=icon_file) self.resize_widget.set_part_title('new', 'New Reborn OS', new_device) icon_file = self.get_distributor_icon_file('Reborn') self.resize_widget.set_part_icon('new', icon_file=icon_file) self.resize_widget.set_pref_size(max_size) self.resize_widget.show_all()
def set_resize_widget(self, device_to_shrink): new_device = self.get_new_device(device_to_shrink) if new_device is None: # No device is available logging.warning(_("There are no primary partitions available")) return txt = _("Will shrink device {0} and create new device {1}") txt = txt.format(device_to_shrink, new_device) logging.debug(txt) (min_size, part_size) = get_partition_size_info(device_to_shrink) max_size = part_size - (MIN_ROOT_SIZE * 1000.0) if max_size < 0: # Full Manjaro does not fit but maybe base fits... ask user. txt = _("Thus recommends at least 6.5GB free to install Manjaro.") + "\n\n" txt += _("New partition {0} resulting of shrinking {1} will not have enough free space for a full installation.").format(new_device, device_to_shrink) + "\n\n" txt += _("You can still install Manjaro, but be carefull on which DE you choose as it might not fit in.") + "\n\n" txt += _("Install at your own risk!") show.warning(self.get_toplevel(), txt) max_size = part_size # print(min_size, max_size, part_size) if self.resize_widget: self.resize_widget.set_property('part_size', int(part_size)) self.resize_widget.set_property('min_size', int(min_size)) self.resize_widget.set_property('max_size', int(max_size)) else: self.resize_widget = gtkwidgets.ResizeWidget(part_size, min_size, max_size) main_box = self.ui.get_object('alongside') main_box.pack_start(self.resize_widget, True, False, 5) self.resize_widget.set_part_title('existing', self.oses[device_to_shrink], device_to_shrink) icon_file = self.get_distributor_icon_file(self.oses[device_to_shrink]) self.resize_widget.set_part_icon('existing', icon_file=icon_file) self.resize_widget.set_part_title('new', 'New Manjaro', new_device) icon_file = self.get_distributor_icon_file('Manjaro') self.resize_widget.set_part_icon('new', icon_file=icon_file) self.resize_widget.set_pref_size(max_size) self.resize_widget.show_all()
def run(self): key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"] # Partition sizes are expressed in MiB if self.efi: gpt_bios_grub_part_size = 2 uefisys_part_size = 100 empty_space_size = 2 else: gpt_bios_grub_part_size = 0 uefisys_part_size = 0 # we start with a 1MiB offset before the first partition empty_space_size = 1 # Get just the disk size in MiB device = self.auto_device device_name = check_output("basename %s" % device) base_path = "/sys/block/%s" % device_name disk_size = 0 if os.path.exists("%s/size" % base_path): with open("%s/queue/logical_block_size" % base_path, 'r') as f: logical_block_size = int(f.read()) with open("%s/size" % base_path, 'r') as f: size = int(f.read()) disk_size = ((logical_block_size * size) / 1024) / 1024 else: txt = _("Setup cannot detect size of your device, please use advanced " "installation routine for partitioning and mounting devices.") logging.error(txt) show.warning(txt) return start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disk_size, start_part_sizes) self.show_part_sizes(part_sizes) # Disable swap and all mounted partitions, umount / last! unmount_all(self.dest_dir) 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. # We assume a /dev/hdX format (or /dev/sdX) if self.efi: # GPT (GUID) is supported only by 'parted' or 'sgdisk' # clean partition table to avoid issues! subprocess.check_call(["sgdisk", "--zap", device]) # Clear all magic strings/signatures - mdadm, lvm, partition tables etc. subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create fresh GPT subprocess.check_call(["sgdisk", "--clear", device]) # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table. subprocess.check_call(["partprobe", device]) # Create actual partitions subprocess.check_call(['sgdisk --set-alignment="2048" --new=1:1M:+%dM --typecode=1:EF02 --change-name=1:BIOS_GRUB %s' % (gpt_bios_grub_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=2:0:+%dM --typecode=2:EF00 --change-name=2:UEFI_SYSTEM %s' % (uefisys_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=3:0:+%dM --typecode=3:8300 --attributes=3:set:2 --change-name=3:KAOS_BOOT %s' % (part_sizes['boot'], device)], shell=True) if self.lvm: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8E00 --change-name=4:KAOS_LVM %s' % (part_sizes['lvm_pv'], device)], shell=True) else: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8300 --change-name=4:KAOS_ROOT %s' % (part_sizes['root'], device)], shell=True) if self.home: subprocess.check_call(['sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8300 --change-name=5:KAOS_HOME %s' % (part_sizes['home'], device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=6:0:+%dM --typecode=6:8200 --change-name=6:KAOS_SWAP %s' % (part_sizes['swap'], device)], shell=True) else: subprocess.check_call(['sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8200 --change-name=5:KAOS_SWAP %s' % (part_sizes['swap'], device)], shell=True) logging.debug(check_output("sgdisk --print %s" % device)) else: # DOS MBR partition table # Start at sector 1 for 4k drive compatibility and correct alignment # Clean partitiontable to avoid issues! subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create DOS MBR with parted subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mktable", "msdos"]) if self.separate_boot: # Create boot partition (all sizes are in MiB) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "1", "%dMiB" % part_sizes['boot']]) # Set boot partition as bootable subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on"]) if self.lvm: start = part_sizes['boot'] if part_sizes['boot'] is 0: start = 1 end = start + part_sizes['lvm_pv'] # Create partition for lvm (will store root, swap and home (if desired) logical volumes) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "100%"]) # Set lvm flag subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "2", "lvm", "on"]) else: start = part_sizes['boot'] if part_sizes['boot'] is 0: start = 1 # Create root partition end = start + part_sizes['root'] subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "%dMiB" % end]) if not self.separate_boot: # Set this partition as bootable subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on"]) if self.home: # Create home partition start = end end = start + part_sizes['home'] subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "%dMiB" % end]) # Create swap partition start = end subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "linux-swap", "%dMiB" % start, "100%"]) printk(True) # Wait until /dev initialized correct devices subprocess.check_call(["udevadm", "settle"]) (efi_device, boot_device, swap_device, root_device, luks_devices, lvm_device, home_device) = self.get_devices() if not self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s", efi_device, boot_device, swap_device, root_device) elif not self.home and not self.efi: logging.debug("Boot %s, Swap %s, Root %s", boot_device, swap_device, root_device) elif self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s, Home %s", efi_device, boot_device, swap_device, root_device, home_device) else: logging.debug("Boot %s, Swap %s, Root %s, Home %s", boot_device, swap_device, root_device, home_device) if self.luks: self.setup_luks(luks_devices[0], "cryptKaOS", key_files[0]) if self.home and not self.lvm: self.setup_luks(luks_devices[1], "cryptKaOSHome", key_files[1]) if self.lvm: logging.debug(_("Will setup LVM on device %s"), lvm_device) subprocess.check_call(["pvcreate", "-f", "-y", lvm_device]) subprocess.check_call(["vgcreate", "-f", "-y", "KaOSVG", lvm_device]) # Fix issue 180 (https://github.com/Antergos/Cnchi/issues/180) try: # Check space we have now for creating logical volumes vg_info = check_output("vgdisplay -c KaOSVG") # 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 KaOSVG volume group size: %d MiB", vg_size) logging.debug("Reajusting logical volume sizes") diff_size = part_sizes['lvm_pv'] - vg_size start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disk_size - diff_size, start_part_sizes) self.show_part_sizes(part_sizes) except Exception as err: logging.exception(err) subprocess.check_call(["lvcreate", "--name", "KaOSRoot", "--size", str(int(part_sizes['root'])), "KaOSVG"]) if not self.home: # Use the remaining space for our swap volume subprocess.check_call(["lvcreate", "--name", "KaOSSwap", "--extents", "100%FREE", "KaOSVG"]) else: subprocess.check_call(["lvcreate", "--name", "KaOSHome", "--size", str(int(part_sizes['home'])), "KaOSVG"]) # Use the remaining space for our swap volume subprocess.check_call(["lvcreate", "--name", "KaOSSwap", "--extents", "100%FREE", "KaOSVG"]) # Make sure the "root" partition is defined first! self.mkfs(root_device, "xfs", "/", "KaOSRoot") self.mkfs(swap_device, "swap", "", "KaOSSwap") if self.separate_boot: logging.debug("Boot device is " + boot_device + ", about to mkfs") self.mkfs(boot_device, "ext2", "/boot", "KaOSBoot") # Format the EFI partition if self.efi: self.mkfs(efi_device, "vfat", "/boot/efi", "UEFI_SYSTEM", "-F 32") if self.home: self.mkfs(home_device, "xfs", "/home", "KaOSHome") # NOTE: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in installation_process.py if necessary # NOTE: /etc/default/grub, /etc/stab and /etc/crypttab will be modified in installation_process.py, too. if self.luks and self.luks_key_pass == "": # 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) subprocess.check_call(['chmod', '0400', key_files[0]]) subprocess.check_call(['mv', key_files[0], '%s/boot' % self.dest_dir]) if self.home and not self.lvm: subprocess.check_call(['chmod', '0400', key_files[1]]) subprocess.check_call(["mkdir", "-p", '%s/etc/luks-keys' % self.dest_dir]) subprocess.check_call(['mv', key_files[1], '%s/etc/luks-keys' % self.dest_dir])
def run(self): key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"] # Partition sizes are expressed in MiB if self.efi: gpt_bios_grub_part_size = 2 uefisys_part_size = 100 empty_space_size = 2 else: gpt_bios_grub_part_size = 0 uefisys_part_size = 0 # we start with a 1MiB offset before the first partition empty_space_size = 1 # Get just the disk size in MiB device = self.auto_device device_name = check_output("basename %s" % device) base_path = "/sys/block/%s" % device_name disk_size = 0 if os.path.exists("%s/size" % base_path): with open("%s/queue/logical_block_size" % base_path, 'r') as f: logical_block_size = int(f.read()) with open("%s/size" % base_path, 'r') as f: size = int(f.read()) disk_size = ((logical_block_size * size) / 1024) / 1024 else: txt = _( "Setup cannot detect size of your device, please use advanced " "installation routine for partitioning and mounting devices.") logging.error(txt) show.warning(txt) return start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disk_size, start_part_sizes) self.show_part_sizes(part_sizes) # Disable swap and all mounted partitions, umount / last! unmount_all(self.dest_dir) 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. # We assume a /dev/hdX format (or /dev/sdX) if self.efi: # GPT (GUID) is supported only by 'parted' or 'sgdisk' # clean partition table to avoid issues! subprocess.check_call(["sgdisk", "--zap", device]) # Clear all magic strings/signatures - mdadm, lvm, partition tables etc. subprocess.check_call([ "dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer" ]) subprocess.check_call(["wipefs", "-a", device]) # Create fresh GPT subprocess.check_call(["sgdisk", "--clear", device]) # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table. subprocess.check_call(["partprobe", device]) # Create actual partitions subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=1:1M:+%dM --typecode=1:EF02 --change-name=1:BIOS_GRUB %s' % (gpt_bios_grub_part_size, device) ], shell=True) subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=2:0:+%dM --typecode=2:EF00 --change-name=2:UEFI_SYSTEM %s' % (uefisys_part_size, device) ], shell=True) subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=3:0:+%dM --typecode=3:8300 --attributes=3:set:2 --change-name=3:MANJARO_BOOT %s' % (part_sizes['boot'], device) ], shell=True) if self.lvm: subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8E00 --change-name=4:MANJARO_LVM %s' % (part_sizes['lvm_pv'], device) ], shell=True) else: subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8300 --change-name=4:MANJARO_ROOT %s' % (part_sizes['root'], device) ], shell=True) if self.home: subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8300 --change-name=5:MANJARO_HOME %s' % (part_sizes['home'], device) ], shell=True) subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=6:0:+%dM --typecode=6:8200 --change-name=6:MANJARO_SWAP %s' % (part_sizes['swap'], device) ], shell=True) else: subprocess.check_call([ 'sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8200 --change-name=5:MANJARO_SWAP %s' % (part_sizes['swap'], device) ], shell=True) logging.debug(check_output("sgdisk --print %s" % device)) else: # DOS MBR partition table # Start at sector 1 for 4k drive compatibility and correct alignment # Clean partitiontable to avoid issues! subprocess.check_call([ "dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer" ]) subprocess.check_call(["wipefs", "-a", device]) # Create DOS MBR with parted subprocess.check_call( ["parted", "-a", "optimal", "-s", device, "mktable", "msdos"]) if self.separate_boot: # Create boot partition (all sizes are in MiB) subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "mkpart", "primary", "1", "%dMiB" % part_sizes['boot'] ]) # Set boot partition as bootable subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on" ]) if self.lvm: start = part_sizes['boot'] if part_sizes['boot'] is 0: start = 1 end = start + part_sizes['lvm_pv'] # Create partition for lvm (will store root, swap and home (if desired) logical volumes) subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "100%" ]) # Set lvm flag subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "set", "2", "lvm", "on" ]) else: start = part_sizes['boot'] if part_sizes['boot'] is 0: start = 1 # Create root partition end = start + part_sizes['root'] subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "%dMiB" % end ]) if not self.separate_boot: # Set this partition as bootable subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on" ]) if self.home: # Create home partition start = end end = start + part_sizes['home'] subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "mkpart", "primary", "%dMiB" % start, "%dMiB" % end ]) # Create swap partition start = end subprocess.check_call([ "parted", "-a", "optimal", "-s", device, "mkpart", "primary", "linux-swap", "%dMiB" % start, "100%" ]) printk(True) # Wait until /dev initialized correct devices subprocess.check_call(["udevadm", "settle"]) (efi_device, boot_device, swap_device, root_device, luks_devices, lvm_device, home_device) = self.get_devices() if not self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s", efi_device, boot_device, swap_device, root_device) elif not self.home and not self.efi: logging.debug("Boot %s, Swap %s, Root %s", boot_device, swap_device, root_device) elif self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s, Home %s", efi_device, boot_device, swap_device, root_device, home_device) else: logging.debug("Boot %s, Swap %s, Root %s, Home %s", boot_device, swap_device, root_device, home_device) if self.luks: self.setup_luks(luks_devices[0], "cryptManjaro", key_files[0]) if self.home and not self.lvm: self.setup_luks(luks_devices[1], "cryptManjaroHome", key_files[1]) if self.lvm: logging.debug(_("Will setup LVM on device %s"), lvm_device) subprocess.check_call(["pvcreate", "-f", "-y", lvm_device]) subprocess.check_call( ["vgcreate", "-f", "-y", "ManjaroVG", lvm_device]) # Fix issue 180 (https://github.com/Antergos/Cnchi/issues/180) try: # Check space we have now for creating logical volumes vg_info = check_output("vgdisplay -c ManjaroVG") # 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 ManjaroVG volume group size: %d MiB", vg_size) logging.debug("Reajusting logical volume sizes") diff_size = part_sizes['lvm_pv'] - vg_size start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disk_size - diff_size, start_part_sizes) self.show_part_sizes(part_sizes) except Exception as err: logging.exception(err) subprocess.check_call([ "lvcreate", "--name", "ManjaroRoot", "--size", str(int(part_sizes['root'])), "ManjaroVG" ]) if not self.home: # Use the remaining space for our swap volume subprocess.check_call([ "lvcreate", "--name", "ManjaroSwap", "--extents", "100%FREE", "ManjaroVG" ]) else: subprocess.check_call([ "lvcreate", "--name", "ManjaroHome", "--size", str(int(part_sizes['home'])), "ManjaroVG" ]) # Use the remaining space for our swap volume subprocess.check_call([ "lvcreate", "--name", "ManjaroSwap", "--extents", "100%FREE", "ManjaroVG" ]) # Make sure the "root" partition is defined first! self.mkfs(root_device, "ext4", "/", "ManjaroRoot") self.mkfs(swap_device, "swap", "", "ManjaroSwap") if self.separate_boot: logging.debug("Boot device is " + boot_device + ", about to mkfs") self.mkfs(boot_device, "ext2", "/boot", "ManjaroBoot") # Format the EFI partition if self.efi: self.mkfs(efi_device, "vfat", "/boot/efi", "UEFI_SYSTEM", "-F 32") if self.home: self.mkfs(home_device, "ext4", "/home", "ManjaroHome") # NOTE: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in installation_process.py if necessary # NOTE: /etc/default/grub, /etc/stab and /etc/crypttab will be modified in installation_process.py, too. if self.luks and self.luks_key_pass == "": # 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) subprocess.check_call(['chmod', '0400', key_files[0]]) subprocess.check_call( ['mv', key_files[0], '%s/boot' % self.dest_dir]) if self.home and not self.lvm: subprocess.check_call(['chmod', '0400', key_files[1]]) subprocess.check_call( ["mkdir", "-p", '%s/etc/luks-keys' % self.dest_dir]) subprocess.check_call( ['mv', key_files[1], '%s/etc/luks-keys' % self.dest_dir])
def on_cli_button_clicked(self, widget, data=None): try: subprocess.Popen(["antergos-setup"]) self.quit_cnchi() except: warning(_("Can't load the CLI installer"))
def run(self): key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"] # Partition sizes are expressed in MB if self.efi: gpt_bios_grub_part_size = 2 efisys_part_size = 100 empty_space_size = 2 else: gpt_bios_grub_part_size = 0 efisys_part_size = 0 empty_space_size = 0 boot_part_size = 200 # Get just the disk size in 1000*1000 MB device = self.auto_device device_name = check_output("basename %s" % device) base_path = "/sys/block/%s" % device_name disk_size = 0 if os.path.exists("%s/size" % base_path): with open("%s/queue/logical_block_size" % base_path, 'r') as f: logical_block_size = int(f.read()) with open("%s/size" % base_path, 'r') as f: size = int(f.read()) disk_size = ((logical_block_size * size) / 1024) / 1024 else: txt = _("Setup cannot detect size of your device, please use advanced " "installation routine for partitioning and mounting devices.") logging.error(txt) show.warning(txt) return mem_total = check_output("grep MemTotal /proc/meminfo") mem_total = int(mem_total.split()[1]) mem = mem_total / 1024 # Suggested sizes from Anaconda installer if mem < 2048: swap_part_size = 2 * mem elif 2048 <= mem < 8192: swap_part_size = mem elif 8192 <= mem < 65536: swap_part_size = mem / 2 else: swap_part_size = 4096 # Max swap size is 10% of all available disk size max_swap = disk_size * 0.1 if swap_part_size > max_swap: swap_part_size = max_swap root_part_size = disk_size - (empty_space_size + gpt_bios_grub_part_size + efisys_part_size + boot_part_size + swap_part_size) home_part_size = 0 if self.home: # Decide how much we leave to root and how much we leave to /home new_root_part_size = root_part_size / 5 if new_root_part_size > MAX_ROOT_SIZE: new_root_part_size = MAX_ROOT_SIZE elif new_root_part_size < MIN_ROOT_SIZE: new_root_part_size = MIN_ROOT_SIZE home_part_size = root_part_size - new_root_part_size root_part_size = new_root_part_size lvm_pv_part_size = swap_part_size + root_part_size + home_part_size logging.debug("disk_size %dMB", disk_size) logging.debug("gpt_bios_grub_part_size %dMB", gpt_bios_grub_part_size) logging.debug("efisys_part_size %dMB", efisys_part_size) logging.debug("boot_part_size %dMB", boot_part_size) if self.lvm: logging.debug("lvm_pv_part_size %dMB", lvm_pv_part_size) logging.debug("swap_part_size %dMB", swap_part_size) logging.debug("root_part_size %dMB", root_part_size) if self.home: logging.debug("home_part_size %dMB", home_part_size) # Disable swap and all mounted partitions, umount / last! unmount_all(self.dest_dir) printk(False) # We assume a /dev/hdX format (or /dev/sdX) if self.efi: # GPT (GUID) is supported only by 'parted' or 'sgdisk' # clean partition table to avoid issues! subprocess.check_call(["sgdisk", "--zap", device]) # Clear all magic strings/signatures - mdadm, lvm, partition tables etc. subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create fresh GPT subprocess.check_call(["sgdisk", "--clear", device]) # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table. subprocess.check_call(["partprobe", device]) # Create actual partitions subprocess.check_call(['sgdisk --set-alignment="2048" --new=1:1M:+%dM --typecode=1:EF02 --change-name=1:BIOS_GRUB %s' % (gpt_bios_grub_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=2:0:+%dM --typecode=2:EF00 --change-name=2:UEFI_SYSTEM %s' % (efisys_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=3:0:+%dM --typecode=3:8300 --attributes=3:set:2 --change-name=3:MANJARO_BOOT %s' % (boot_part_size, device)], shell=True) if self.lvm: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8E00 --change-name=4:MANJARO_LVM %s' % (lvm_pv_part_size, device)], shell=True) else: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8200 --change-name=4:MANJARO_SWAP %s' % (swap_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8300 --change-name=5:MANJARO_ROOT %s' % (root_part_size, device)], shell=True) if self.home: subprocess.check_call(['sgdisk --set-alignment="2048" --new=6:0:+%dM --typecode=6:8300 --change-name=5:MANJARO_HOME %s' % (home_part_size, device)], shell=True) logging.debug(check_output("sgdisk --print %s" % device)) else: # Start at sector 1 for 4k drive compatibility and correct alignment # Clean partitiontable to avoid issues! subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create DOS MBR with parted subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mktable", "msdos"]) # Create boot partition (all sizes are in MB) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "1", str(boot_part_size)]) # Set boot partition as bootable subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on"]) if self.lvm: start = boot_part_size end = start + lvm_pv_part_size # Create partition for lvm (will store root, swap and home (if desired) logical volumes) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), "100%"]) # Set lvm flag subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "2", "lvm", "on"]) else: # Create swap partition start = boot_part_size end = start + swap_part_size subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "linux-swap", str(start), str(end)]) # Create root partition start = end end = start + root_part_size subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), str(end)]) if self.home: # Create home partition start = end subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), "100%"]) printk(True) # Wait until /dev initialized correct devices subprocess.check_call(["udevadm", "settle", "--quiet"]) (efi_device, boot_device, swap_device, root_device, luks_devices, lvm_device, home_device) = self.get_devices() if not self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s", efi_device, boot_device, swap_device, root_device) elif not self.home and not self.efi: logging.debug("Boot %s, Swap %s, Root %s", boot_device, swap_device, root_device) elif self.home and self.efi: logging.debug("EFI %s, Boot %s, Swap %s, Root %s, Home %s", efi_device, boot_device, swap_device, root_device, home_device) else: logging.debug("Boot %s, Swap %s, Root %s, Home %s", boot_device, swap_device, root_device, home_device) if self.luks: self.setup_luks(luks_devices[0], "cryptManjaro", key_files[0]) if self.home and not self.lvm: self.setup_luks(luks_devices[1], "cryptManjaroHome", key_files[1]) if self.lvm: logging.debug(_("Will setup LVM on device %s"), lvm_device) subprocess.check_call(["pvcreate", "-f", "-y", lvm_device]) subprocess.check_call(["vgcreate", "-f", "-y", "ManjaroVG", lvm_device]) subprocess.check_call(["lvcreate", "--name", "ManjaroRoot", "--size", str(int(root_part_size)), "ManjaroVG"]) if not self.home: # Use the remainig space for our swap volume subprocess.check_call(["lvcreate", "--name", "ManjaroSwap", "--extents", "100%FREE", "ManjaroVG"]) else: subprocess.check_call(["lvcreate", "--name", "ManjaroSwap", "--size", str(int(swap_part_size)), "ManjaroVG"]) # Use the remainig space for our home volume subprocess.check_call(["lvcreate", "--name", "ManjaroHome", "--extents", "100%FREE", "ManjaroVG"]) # Make sure the "root" partition is defined first! self.mkfs(root_device, "ext4", "/", "ManjaroRoot") self.mkfs(swap_device, "swap", "", "ManjaroSwap") self.mkfs(boot_device, "ext2", "/boot", "ManjaroBoot") # Format the EFI partition if self.efi: self.mkfs(efi_device, "vfat", "/boot/efi", "UEFI_SYSTEM", "-F 32") if self.home: self.mkfs(home_device, "ext4", "/home", "ManjaroHome") # NOTE: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in installation_process.py if necessary # NOTE: /etc/default/grub, /etc/stab and /etc/crypttab will be modified in installation_process.py, too. if self.luks and self.luks_key_pass == "": # 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) subprocess.check_call(['chmod', '0400', key_files[0]]) subprocess.check_call(['mv', key_files[0], '%s/boot' % self.dest_dir]) if self.home and not self.lvm: subprocess.check_call(['chmod', '0400', key_files[1]]) subprocess.check_call(["mkdir", "-p", '%s/etc/luks-keys' % self.dest_dir]) subprocess.check_call(['mv', key_files[1], '%s/etc/luks-keys' % self.dest_dir])
def run(self): key_files = ["/tmp/.keyfile-root", "/tmp/.keyfile-home"] # TODO: Fix GPT # if self.uefi: # gpt_bios_grub_part_size = 2 # uefisys_part_size = 512 # empty_space_size = 2 #else: gpt_bios_grub_part_size = 0 uefisys_part_size = 0 empty_space_size = 0 # Get just the disk size in 1000*1000 MB device = self.auto_device device_name = check_output("basename %s" % device) base_path = "/sys/block/%s" % device_name disc_size = 0 if os.path.exists("%s/size" % base_path): with open("%s/queue/logical_block_size" % base_path, 'r') as f: logical_block_size = int(f.read()) with open("%s/size" % base_path, 'r') as f: size = int(f.read()) # Divide to get MB 1000*1000 disc_size = logical_block_size * size / 1000000 logging.debug(_("The device %s has a size of %dMB"), self.auto_device, disc_size) # leave 1MB alone disc_size -= 1 else: txt = _("Setup cannot detect size of your device, please use advanced " "installation method for partitioning and mounting devices.") logging.error(txt) show.warning(txt) return # Note: Partition sizes are expressed in MB start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disc_size, start_part_sizes) self.show_part_sizes(part_sizes) # Disable swap and all mounted partitions, umount / last! unmount_all(self.dest_dir) printk(False) # We assume a /dev/hdX format (or /dev/sdX) # We are not using GPT for UEFI at this time # TODO: Fix GPT use_gpt = False if self.uefi and use_gpt: # GPT (GUID) is supported only by 'parted' or 'sgdisk' # clean partition table to avoid issues! subprocess.check_call(["sgdisk", "--zap", device]) # Clear all magic strings/signatures - mdadm, lvm, partition tables etc. subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create fresh GPT subprocess.check_call(["sgdisk", "--clear", device]) # Inform the kernel of the partition change. Needed if the hard disk had a MBR partition table. subprocess.check_call(["partprobe", device]) # Create actual partitions subprocess.check_call(['sgdisk --set-alignment="2048" --new=1:1M:+%dM --typecode=1:EF02 --change-name=1:BIOS_GRUB %s' % (gpt_bios_grub_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=2:0:+%dM --typecode=2:EF00 --change-name=2:UEFI_SYSTEM %s' % (uefisys_part_size, device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=3:0:+%dM --typecode=3:8300 --attributes=3:set:2 --change-name=3:ANTERGOS_BOOT %s' % (part_sizes['boot'], device)], shell=True) if self.lvm: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8E00 --change-name=4:ANTERGOS_LVM %s' % (part_sizes['lvm_pv'], device)], shell=True) else: subprocess.check_call(['sgdisk --set-alignment="2048" --new=4:0:+%dM --typecode=4:8200 --change-name=4:ANTERGOS_SWAP %s' % (part_sizes['swap'], device)], shell=True) subprocess.check_call(['sgdisk --set-alignment="2048" --new=5:0:+%dM --typecode=5:8300 --change-name=5:ANTERGOS_ROOT %s' % (part_sizes['root'], device)], shell=True) if self.home: subprocess.check_call(['sgdisk --set-alignment="2048" --new=6:0:+%dM --typecode=6:8300 --change-name=5:ANTERGOS_HOME %s' % (part_sizes['home'], device)], shell=True) logging.debug(check_output("sgdisk --print %s" % device)) else: # Start at sector 1 for 4k drive compatibility and correct alignment # Clean partitiontable to avoid issues! subprocess.check_call(["dd", "if=/dev/zero", "of=%s" % device, "bs=512", "count=2048", "status=noxfer"]) subprocess.check_call(["wipefs", "-a", device]) # Create DOS MBR with parted subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mktable", "msdos"]) # Create boot partition (all sizes are in MB) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "1", str(part_sizes['boot'])]) # Set boot partition as bootable subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "1", "boot", "on"]) if self.lvm: start = part_sizes['boot'] end = start + part_sizes['lvm_pv'] # Create partition for lvm (will store root, swap and home (if desired) logical volumes) subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), "100%"]) # Set lvm flag subprocess.check_call(["parted", "-a", "optimal", "-s", device, "set", "2", "lvm", "on"]) else: # Create swap partition start = part_sizes['boot'] end = start + part_sizes['swap'] subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", "linux-swap", str(start), str(end)]) if self.home: # Create root partition start = end end = start + part_sizes['root'] subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), str(end)]) # Create home partition start = end subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), "100%"]) else: # Create root partition start = end subprocess.check_call(["parted", "-a", "optimal", "-s", device, "mkpart", "primary", str(start), "100%"]) printk(True) # Wait until /dev initialized correct devices subprocess.check_call(["udevadm", "settle", "--quiet"]) (boot_device, swap_device, root_device, luks_devices, lvm_device, home_device) = self.get_devices() if self.home: logging.debug("Boot: %s, Swap: %s, Root: %s, Home: %s", boot_device, swap_device, root_device, home_device) else: logging.debug("Boot: %s, Swap: %s, Root: %s", boot_device, swap_device, root_device) if self.luks: self.setup_luks(luks_devices[0], "cryptAntergos", key_files[0]) if self.home and not self.lvm: self.setup_luks(luks_devices[1], "cryptAntergosHome", key_files[1]) if self.lvm: logging.debug(_("Cnchi will setup LVM on device %s"), lvm_device) subprocess.check_call(["pvcreate", "-f", "-y", lvm_device]) subprocess.check_call(["vgcreate", "-f", "-y", "AntergosVG", lvm_device]) # Fix issue 180 try: # Check space we have now for creating logical volumes vg_info = check_output("vgdisplay -c AntergosVG") # 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 MB", vg_size) logging.debug("Reajusting logical volume sizes") diff_size = part_sizes['lvm_pv'] - vg_size start_part_sizes = empty_space_size + gpt_bios_grub_part_size + uefisys_part_size part_sizes = self.get_part_sizes(disc_size - diff_size, start_part_sizes) self.show_part_sizes(part_sizes) except Exception as err: logging.exception(err) subprocess.check_call(["lvcreate", "--name", "AntergosRoot", "--size", str(int(part_sizes['root'])), "AntergosVG"]) if not self.home: # Use the remainig space for our swap volume subprocess.check_call(["lvcreate", "--name", "AntergosSwap", "--extents", "100%FREE", "AntergosVG"]) else: subprocess.check_call(["lvcreate", "--name", "AntergosSwap", "--size", str(int(part_sizes['swap'])), "AntergosVG"]) # Use the remainig space for our home volume subprocess.check_call(["lvcreate", "--name", "AntergosHome", "--extents", "100%FREE", "AntergosVG"]) # We have all partitions and volumes created. Let's create its filesystems with mkfs. # Note: Make sure the "root" partition is defined first! self.mkfs(root_device, "ext4", "/", "AntergosRoot") self.mkfs(swap_device, "swap", "", "AntergosSwap") if self.uefi: # Format /boot partition with vfat self.mkfs(boot_device, "vfat", "/boot", "AntergosEFI", "-F 32") else: self.mkfs(boot_device, "ext2", "/boot", "AntergosBoot") if self.home: self.mkfs(home_device, "ext4", "/home", "AntergosHome") # Note: encrypted and/or lvm2 hooks will be added to mkinitcpio.conf in installation_process.py if necessary # Note: /etc/default/grub, /etc/fstab and /etc/crypttab will be modified in installation_process.py, too. if self.luks and self.luks_key_pass == "": # Copy 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) subprocess.check_call(['chmod', '0400', key_files[0]]) subprocess.check_call(['mv', key_files[0], '%s/boot' % self.dest_dir]) if self.home and not self.lvm: subprocess.check_call(['chmod', '0400', key_files[1]]) subprocess.check_call(["mkdir", "-p", '%s/etc/luks-keys' % self.dest_dir]) subprocess.check_call(['mv', key_files[1], '%s/etc/luks-keys' % self.dest_dir])