def run_mkconfig(self): """ Create grub.cfg file using grub-mkconfig """ logging.debug("Generating grub.cfg...") # Make sure that /dev and others are mounted (binded). special_dirs.mount(self.dest_dir) # if self.settings.get("zfs"): # # grub-mkconfig does not properly detect the ZFS filesystem, # # so it is necessary to edit grub.cfg manually. # zfs_pool_name = self.settings.get("zfs_pool_name") # grub_cfg_path = os.path.join(self.dest_dir, "boot/grub/grub.cfg") # with open(grub_cfg_path, "w") as grub_cfg: # grub_cfg.write('set timeout=2\n') # grub_cfg.write('set default=0\n\n') # grub_cfg.write('# (0) Antergos Linux\n') # grub_cfg.write('\tmenuentry "Antergos Linux (zfs)" {\n') # # grub_cfg.write('\tsearch --no-floppy --label --set=root {0}\n'.format(zfs_pool_name)) # grub_cfg.write('\tlinux /vmlinuz-linux zfs={0} rw\n'.format(zfs_pool_name)) # grub_cfg.write('\tinitrd /initramfs-linux.img\n') # grub_cfg.write('}\n') # else: # Add -l option to os-prober's umount call so that it does not hang self.apply_osprober_patch() logging.debug("Running grub-mkconfig...") locale = self.settings.get("locale") cmd = 'LANG={0} grub-mkconfig -o /boot/grub/grub.cfg'.format(locale) cmd_sh = ['sh', '-c', cmd] if not chroot_call(cmd_sh, self.dest_dir, timeout=300): msg = ("grub-mkconfig does not respond. Killing grub-mount and" "os-prober so we can continue.") logging.error(msg) call(['killall', 'grub-mount']) call(['killall', 'os-prober'])
def run_mkconfig(self): """ Create grub.cfg file using grub-mkconfig """ logging.debug("Generating grub.cfg...") # Make sure that /dev and others are mounted (binded). special_dirs.mount(self.dest_dir) # Add -l option to os-prober's umount call so that it does not hang self.apply_osprober_patch() logging.debug("Running grub-mkconfig...") locale = self.settings.get("locale") cmd = "LANG={0} grub-mkconfig -o /boot/grub/grub.cfg".format(locale) cmd_sh = ["sh", "-c", cmd] if not chroot_call(cmd_sh, self.dest_dir, timeout=300): msg = "grub-mkconfig does not respond. Killing grub-mount and" "os-prober so we can continue." logging.error(msg) call(["killall", "grub-mount"]) call(["killall", "os-prober"])
def run_mkconfig(self): """ Create grub.cfg file using grub-mkconfig """ logging.debug("Generating grub.cfg...") # Make sure that /dev and others are mounted (binded). special_dirs.mount(self.dest_dir) # Add -l option to os-prober's umount call so that it does not hang self.apply_osprober_patch() logging.debug("Running grub-mkconfig...") locale = self.settings.get("locale") cmd = 'LANG={0} grub-mkconfig -o /boot/grub/grub.cfg'.format(locale) cmd_sh = ['sh', '-c', cmd] if not chroot_call(cmd_sh, self.dest_dir, timeout=300): msg = ("grub-mkconfig does not respond. Killing grub-mount and" "os-prober so we can continue.") logging.error(msg) call(['killall', 'grub-mount']) call(['killall', 'os-prober'])
def install_bios(self): """ Install Grub2 bootloader in a BIOS system """ grub_location = self.settings.get("bootloader_device") txt = _("Installing GRUB(2) BIOS boot loader in {0}").format(grub_location) logging.info(txt) # /dev and others need to be mounted (binded). # We call mount_special_dirs here just to be sure special_dirs.mount(self.dest_dir) grub_install = [ "grub-install", "--directory=/usr/lib/grub/i386-pc", "--target=i386-pc", "--boot-directory=/boot", "--recheck", ] # Use --force when installing in /dev/sdXY or in /dev/mmcblk if len(grub_location) > len("/dev/sdX"): grub_install.append("--force") grub_install.append(grub_location) chroot_call(grub_install, self.dest_dir) self.install_locales() self.run_mkconfig() grub_cfg_path = os.path.join(self.dest_dir, "boot/grub/grub.cfg") with open(grub_cfg_path) as grub_cfg: if "Antergos" in grub_cfg.read(): txt = _("GRUB(2) BIOS has been successfully installed.") logging.info(txt) self.settings.set("bootloader_installation_successful", True) else: txt = _("ERROR installing GRUB(2) BIOS.") logging.warning(txt) self.settings.set("bootloader_installation_successful", False)
def install_bios(self): """ Install Grub2 bootloader in a BIOS system """ grub_location = self.settings.get('bootloader_device') txt = _("Installing GRUB(2) BIOS boot loader in {0}").format( grub_location) logging.info(txt) # /dev and others need to be mounted (binded). # We call mount_special_dirs here just to be sure special_dirs.mount(self.dest_dir) grub_install = [ 'grub-install', '--directory=/usr/lib/grub/i386-pc', '--target=i386-pc', '--boot-directory=/boot', '--recheck' ] # Use --force when installing in /dev/sdXY or in /dev/mmcblk if len(grub_location) > len("/dev/sdX"): grub_install.append("--force") grub_install.append(grub_location) chroot_call(grub_install, self.dest_dir) self.install_locales() self.run_mkconfig() grub_cfg_path = os.path.join(self.dest_dir, "boot/grub/grub.cfg") with open(grub_cfg_path) as grub_cfg: if "Antergos" in grub_cfg.read(): txt = _("GRUB(2) BIOS has been successfully installed.") logging.info(txt) self.settings.set('bootloader_installation_successful', True) else: txt = _("ERROR installing GRUB(2) BIOS.") logging.warning(txt) self.settings.set('bootloader_installation_successful', False)
def start(self): """ Run installation """ # From this point, on a warning situation, Cnchi should try to continue, # so we need to catch the exception here. If we don't catch the exception # here, it will be catched in run() and managed as a fatal error. # On the other hand, if we want to clarify the exception message we can # catch it here and then raise an InstallError exception. if not os.path.exists(DEST_DIR): with misc.raised_privileges(): os.makedirs(DEST_DIR, mode=0o755, exist_ok=True) msg = _("Installing using the '{0}' method").format(self.method) self.queue_event("info", msg) # Mount needed partitions (in automatic it's already done) if self.method in ["alongside", "advanced", "zfs"]: self.mount_partitions() # Nasty workaround: # If pacman was stoped and /var is in another partition than root # (so as to be able to resume install), database lock file will still # be in place. We must delete it or this new installation will fail db_lock = os.path.join(DEST_DIR, "var/lib/pacman/db.lck") if os.path.exists(db_lock): with misc.raised_privileges(): os.remove(db_lock) logging.debug("%s deleted", db_lock) # Create some needed folders folders = [ os.path.join(DEST_DIR, "var/lib/pacman"), os.path.join(DEST_DIR, "etc/pacman.d/gnupg"), os.path.join(DEST_DIR, "var/log"), ] for folder in folders: os.makedirs(folder, mode=0o755, exist_ok=True) # If kernel images exists in /boot they are most likely from a failed # install attempt and need to be removed otherwise pyalpm will raise a # fatal exception later on. kernel_imgs = ( "/install/boot/vmlinuz-linux", "/install/boot/vmlinuz-linux-lts", "/install/boot/initramfs-linux.img", "/install/boot/initramfs-linux-fallback.img", "/install/boot/initramfs-linux-lts.img", "/install/boot/initramfs-linux-lts-fallback.img", ) for img in kernel_imgs: if os.path.exists(img): os.remove(img) logging.debug("Preparing pacman...") self.prepare_pacman() logging.debug("Pacman ready") # Run pre-install scripts (only catalyst does something here atm) # Note: Catalyst is disabled in catalyst.py try: logging.debug("Running hardware drivers pre-install jobs...") proprietary = self.settings.get("feature_graphic_drivers") self.hardware_install = hardware.HardwareInstall(use_proprietary_graphic_drivers=proprietary) self.hardware_install.pre_install(DEST_DIR) except Exception as ex: template = "Error in hardware module. An exception of type {0} occured. Arguments:\n{1!r}" message = template.format(type(ex).__name__, ex.args) logging.error(message) logging.debug("Downloading packages...") self.download_packages() # This mounts (binds) /dev and others to /DEST_DIR/dev and others special_dirs.mount(DEST_DIR) logging.debug("Installing packages...") self.install_packages() logging.debug("Configuring system...") self.configure_system() # This unmounts (unbinds) /dev and others to /DEST_DIR/dev and others special_dirs.umount(DEST_DIR) # Finally, try to unmount DEST_DIR auto_partition.unmount_all_in_directory(DEST_DIR) self.running = False # Installation finished successfully self.queue_event("finished", _("Installation finished")) self.error = False return True