Beispiel #1
0
 def on_grub2_edit_button_clicked(self, widget, data=None):
     partition = os.path.join("/dev", self.cfg.cur_boot_partition)
     if slt.isMounted(partition):
         mp = slt.getMountPoint(partition)
         doumount = False
     else:
         mp = slt.mountDevice(partition)
         doumount = True
     grub2cfg = os.path.join(mp, "etc/default/grub")
     if os.path.exists(grub2cfg):
         launched = False
         for editor in self._editors:
             try:
                 cmd = editor.split(" ") + [grub2cfg]
                 slt.execCall(cmd, shell=True, env=None)
                 launched = True
                 break
             except:
                 pass
         if not launched:
             self._bootsetup.error_dialog(
                 _(
                     "Sorry, BootSetup is unable to find a suitable text editor in your system. You will not be able to manually modify the Grub2 default configuration.\n"
                 )
             )
     if doumount:
         slt.umountDevice(mp)
Beispiel #2
0
 def install(self):
   """
   Assuming that last configuration editing didn't modified mount point.
   """
   if self._mbrDevice:
     self._bootsMounted = []
     mp = None
     mpList = None
     try:
       mp = self._mountBootPartition()
       if not mp:
         raise Exception("Cannot mount the main boot partition.")
       self.__debug("mp = " + unicode(mp))
       mpList = {}
       self._mountPartitions(mpList)
       self.__debug("mount point lists: " + unicode(mpList))
       # copy the configuration to the boot_partition
       try:
         self.__debug("create etc/bootsetup directory in " + mp)
         os.makedirs(os.path.join(mp, 'etc/bootsetup'))
       except os.error:
         pass
       self.__debug("copy lilo.conf to etc/bootsetup")
       shutil.copyfile(self.getConfigurationPath(), os.path.join(mp, '/etc/bootsetup/lilo.conf'))
       # run lilo
       if self.isTest:
         self.__debug('/sbin/lilo -t -v -C {mp}/etc/bootsetup/lilo.conf'.format(mp=mp))
         slt.execCall('/sbin/lilo -t -v -C {mp}/etc/bootsetup/lilo.conf'.format(mp=mp))
       else:
         slt.execCall('/sbin/lilo -C {mp}/etc/bootsetup/lilo.conf'.format(mp=mp))
     finally:
       self._umountAll(mp, mpList)
Beispiel #3
0
 def _umountAll(self, mountPoint):
   self.__debug("umountAll")
   if mountPoint:
     self.__debug("umounting main mount point " + mountPoint)
     self._unbindProcSysDev(mountPoint)
     if self._bootInBootMounted:
       self.__debut("/boot mounted in " + mountPoint + ", so umount it")
       slt.execCall("chroot {mp} /sbin/umount /boot".format(mp=mountPoint))
     if mountPoint != '/':
       self.__debug("umain mount point ≠ '/' → umount " + mountPoint)
       slt.umountDevice(mountPoint)
   self._bootInBootMounted = False
   self._procInBootMounted = False
Beispiel #4
0
 def _installGrub2Config(self, mountPoint):
   if os.path.exists(os.path.join(mountPoint, 'etc/default/grub')) and os.path.exists(os.path.join(mountPoint, 'usr/sbin/update-grub')):
     self.__debug("grub2 package is installed on the target partition, so it will be used to generate the grub.cfg file")
     # assume everything is installed on the target partition, grub2 package included.
     if self.isTest:
       self.__debug("chroot {mp} /usr/sbin/update-grub".format(mp=mountPoint))
     else:
       slt.execCall("chroot {mp} /usr/sbin/update-grub".format(mp=mountPoint))
   else:
     self.__debug("grub2 not installed on the target partition, so grub_mkconfig will directly be used to generate the grub.cfg file")
     # tiny OS installed on that mount point, so we cannot chroot on it to install grub2 config.
     if self.isTest:
       self.__debug("/usr/sbin/grub-mkconfig -o {cfg}".format(cfg=os.path.join(mountPoint, "boot/grub/grub.cfg")))
     else:
       slt.execCall("/usr/sbin/grub-mkconfig -o {cfg}".format(cfg=os.path.join(mountPoint, "boot/grub/grub.cfg")))
Beispiel #5
0
 def _editLiLoConf(self, button):
   lilocfg = self._lilo.getConfigurationPath()
   if not os.path.exists(lilocfg):
     self._custom_lilo = True
     self._create_lilo_config()
   if os.path.exists(lilocfg):
     launched = False
     for editor in self._editors:
       try:
         slt.execCall([editor, lilocfg], shell=True, env=None)
         launched = True
         break
       except:
         pass
     if not launched:
       self._custom_lilo = False
       self._errorDialog(_("Sorry, BootSetup is unable to find a suitable text editor in your system. You will not be able to manually modify the LiLo configuration.\n"))
   self._updateLiLoButtons()
Beispiel #6
0
 def _mountBootInBootPartition(self, mountPoint):
   # assume that if the mount_point is /, any /boot directory is already accessible/mounted
   if mountPoint != '/' and os.path.exists(os.path.join(mountPoint, 'etc/fstab')):
     self.__debug("mp != / and etc/fstab exists, will try to mount /boot by chrooting")
     try:
       self.__debug("grep -q /boot {mp}/etc/fstab && chroot {mp} /sbin/mount /boot".format(mp=mountPoint))
       if slt.execCall("grep -q /boot {mp}/etc/fstab && chroot {mp} /sbin/mount /boot".format(mp=mountPoint)):
         self.__debug("/boot mounted in " + mountPoint)
         self._bootInBootMounted = True
     except:
       pass
Beispiel #7
0
 def _editGrub2Conf(self, button):
   partition = os.path.join("/dev", self.cfg.cur_boot_partition)
   if slt.isMounted(partition):
     mp = slt.getMountPoint(partition)
     doumount = False
   else:
     mp = slt.mountDevice(partition)
     doumount = True
   grub2cfg = os.path.join(mp, "etc/default/grub")
   launched = False
   for editor in self._editors:
     try:
       slt.execCall([editor, grub2cfg], shell=True, env=None)
       launched = True
       break
     except:
       pass
   if not launched:
     self._errorDialog(_("Sorry, BootSetup is unable to find a suitable text editor in your system. You will not be able to manually modify the Grub2 default configuration.\n"))
   if doumount:
     slt.umountDevice(mp)
Beispiel #8
0
 def on_lilo_edit_button_clicked(self, widget, data=None):
     lilocfg = self._lilo.getConfigurationPath()
     if not os.path.exists(lilocfg):
         self._custom_lilo = True
         self.update_buttons()
         self._create_lilo_config()
     if os.path.exists(lilocfg):
         launched = False
         for editor in self._editors:
             try:
                 cmd = editor.split(" ") + [lilocfg]
                 slt.execCall(cmd, shell=True, env=None)
                 launched = True
                 break
             except:
                 pass
         if not launched:
             self._custom_lilo = False
             self._bootsetup.error_dialog(
                 _(
                     "Sorry, BootSetup is unable to find a suitable text editor in your system. You will not be able to manually modify the LiLo configuration.\n"
                 )
             )
Beispiel #9
0
 def _unbindProcSysDev(self, mountPoint):
   """
   unbind /proc /sys and /dev into the boot partition
   """
   if self._procInBootMounted:
     self.__debug("mount point ≠ / so umount /dev, /proc and /sys in " + mountPoint)
     slt.execCall('umount {mp}/dev'.format(mp=mountPoint))
     slt.execCall('umount {mp}/proc'.format(mp=mountPoint))
     slt.execCall('umount {mp}/sys'.format(mp=mountPoint))
Beispiel #10
0
 def _bindProcSysDev(self, mountPoint):
   """
   bind /proc /sys and /dev into the boot partition
   """
   if mountPoint != "/":
     self.__debug("mount point ≠ / so mount /dev, /proc and /sys in " + mountPoint)
     self._procInBootMounted = True
     slt.execCall('mount -o bind /dev {mp}/dev'.format(mp=mountPoint))
     slt.execCall('mount -o bind /proc {mp}/proc'.format(mp=mountPoint))
     slt.execCall('mount -o bind /sys {mp}/sys'.format(mp=mountPoint))
Beispiel #11
0
 def _copyAndInstallGrub2(self, mountPoint, device):
   if self.isTest:
     self.__debug("/usr/sbin/grub-install --boot-directory {bootdir} --no-floppy {dev}".format(bootdir=os.path.join(mountPoint, "boot"), dev=device))
     return True
   else:
     return slt.execCall("/usr/sbin/grub-install --boot-directory {bootdir} --no-floppy {dev}".format(bootdir=os.path.join(mountPoint, "boot"), dev=device))