From cdd5e1c3f45f9bced8f19866483c4e8397d72e99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A5=D0=B8=D1=80=D0=B5=D1=86=D0=BA=D0=B8=D0=B9=20=D0=9C?= =?UTF-8?q?=D0=B8=D1=85=D0=B0=D0=B8=D0=BB?= Date: Wed, 17 Oct 2018 11:58:40 +0300 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D1=91=D0=BD?= =?UTF-8?q?=D0=BE=20=D0=B2=D1=8B=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20grub-install?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * grub-install выполняется из устанавливаемой системы, для того, чтобы исключить возможное несоответствие версий grub --- pym/install/distr.py | 20 ++++++----- pym/install/install.py | 62 ++++++++++++++++++++++----------- pym/install/variables/system.py | 9 +++-- 3 files changed, 60 insertions(+), 31 deletions(-) diff --git a/pym/install/distr.py b/pym/install/distr.py index 439a5e3..466af30 100644 --- a/pym/install/distr.py +++ b/pym/install/distr.py @@ -652,19 +652,23 @@ class DirectoryDistributive(Distributive): if not parent: self._makeDirectory(self.directory) + def hasSystemDirectories(self): + return self.system_mounted or self.directory == '/' + def mountSystemDirectories(self, skip=("remote",)): """ Подключить к дистрибутиву системые ресурсы (/proc, /sys) :return: """ - for obj in filter(lambda x: x['name'] not in skip, self.data): - target_path = path.join(self.directory, obj['target']) - if obj['type'] == 'bind': - self._mountToBind(obj['source'], target_path) - else: - self._mountToDirectory(obj['source'], target_path, - "-t %s" % obj['type']) - self.system_mounted = True + if not self.system_mounted: + for obj in filter(lambda x: x['name'] not in skip, self.data): + target_path = path.join(self.directory, obj['target']) + if obj['type'] == 'bind': + self._mountToBind(obj['source'], target_path) + else: + self._mountToDirectory(obj['source'], target_path, + "-t %s" % obj['type']) + self.system_mounted = True def umountSystemDirectories(self): for obj in reversed(self.data): diff --git a/pym/install/install.py b/pym/install/install.py index 589e012..0de0e99 100644 --- a/pym/install/install.py +++ b/pym/install/install.py @@ -249,6 +249,9 @@ class Install(MethodsInterface): """ # получить загрузочный раздел (если есть /boot, то # он является загрузочным иначе корень) + chroot_cmd = getProgPath('/usr/bin/chroot') + chroot_dn = target.getDirectory() + for boot_path in ("/boot", "/"): boot_disk = self.clVars.Select("os_install_disk_dev", where="os_install_disk_mount", @@ -266,16 +269,25 @@ class Install(MethodsInterface): else: platform = [] # прописать GRUB2 на все указанные диски - for mbr_disk in self.clVars.Get('os_install_mbr'): - grub_process = process(cmd_grub_install, - "--boot-directory=%s" % pathJoin( - prefix_boot, - target.getBootDirectory()), - mbr_disk, "--force", *platform, - stderr=STDOUT, envdict=os.environ) - if grub_process.failed(): - raise DistributiveError( - _("Failed to install the bootloader")) + targetdir = target.convertToDirectory() + if not targetdir.hasSystemDirectories(): + targetdir.mountSystemDirectories() + try: + for mbr_disk in self.clVars.Get('os_install_mbr'): + grub_process = process( + chroot_cmd, + chroot_dn, + cmd_grub_install, + "--boot-directory=/%s" % path.relpath(target.getBootDirectory(), + chroot_dn), + mbr_disk, "--force", *platform, + stderr=STDOUT, envdict=os.environ) + if grub_process.failed(): + raise DistributiveError( + _("Failed to install the bootloader")) + finally: + if targetdir.system_mounted: + targetdir.umountSystemDirectories() def update_efi_fstab(self): """ @@ -384,14 +396,14 @@ class Install(MethodsInterface): """ Установить grub с UEFI загрузчиком """ - efifulldir = pathJoin(target.getDirectory(), efidir) + chroot_cmd = getProgPath('/usr/bin/chroot') + chroot_dn = target.getDirectory() grub_params = [ - "--boot-directory=%s" % pathJoin( - prefix_boot, - target.getBootDirectory()), + "--boot-directory=/%s" % path.relpath(target.getBootDirectory(), + chroot_dn), "--bootloader-id=%s" % efiname, "--target=x86_64-efi", - "--efi-directory=%s" % efifulldir, + "--efi-directory=%s" % efidir, "--force"] # проверяем наличие в nv-ram нужной нам записи для исключения повтора efi_boot_mgr = getProgPath('/usr/sbin/efibootmgr') @@ -414,11 +426,21 @@ class Install(MethodsInterface): # в efivars if self.clVars.Get('os_install_root_type') == 'usb-hdd': grub_params.append("--removable") - grub_process = process(cmd_grub_install, - *grub_params, stderr=STDOUT, - envdict=os.environ) - if grub_process.failed(): - raise DistributiveError(_("Failed to install the bootloader")) + targetdir = target.convertToDirectory() + if not targetdir.hasSystemDirectories(): + targetdir.mountSystemDirectories() + try: + grub_process = process( + chroot_cmd, + chroot_dn, + cmd_grub_install, + *grub_params, stderr=STDOUT, + envdict=os.environ) + if grub_process.failed(): + raise DistributiveError(_("Failed to install the bootloader")) + finally: + if targetdir.system_mounted: + targetdir.umountSystemDirectories() # проверяем успешность создания загрузочной записи # если среди загрузочных записей отсутствует запись # calculate и dmesg содержит сообщение об ошибке efivars - diff --git a/pym/install/variables/system.py b/pym/install/variables/system.py index c9fa3c4..fe678f2 100644 --- a/pym/install/variables/system.py +++ b/pym/install/variables/system.py @@ -765,13 +765,16 @@ class VariableOsGrub2Path(Variable): def get(self): # find grub2-install - grubInstall = getProgPath('/usr/sbin/grub2-install') + chroot_path = self.Get('cl_chroot_path') + chroot_cmd = getProgPath('/usr/bin/chroot') + grubInstall = getProgPath('/usr/sbin/grub2-install', prefix=chroot_path) if grubInstall: return grubInstall # find grub-install and check, that this is grub2-install (ver 1.99) - grubInstall = getProgPath('/usr/sbin/grub-install') + grubInstall = getProgPath('/usr/sbin/grub-install', prefix=chroot_path) if grubInstall and filter(lambda x: "1.99" in x or "2." in x, - process(grubInstall, '--version')): + process(chroot_cmd, chroot_path, + grubInstall, '--version')): return grubInstall return ""