Beispiel #1
0
    def start_installation(self):
        # Alongside method shrinks selected partition
        # and creates root and swap partition in the available space

        if self.is_room_available() == False:
            return

        partition_path = self.row[0]
        otherOS = self.row[1]
        fs_type = self.row[2]

        # what if path is sda10 (two digits) ? this is wrong
        device_path = self.row[0][:-1]

        # re.search(r'\d+$', self.row[0])

        new_size = self.new_size

        # first, shrink file system
        res = fs.resize(partition_path, fs_type, new_size)
        if res:
            # destroy original partition and create a new resized one
            pm.split_partition(device_path, partition_path, new_size)
        else:
            logging.error("Can't shrink %s(%s) filesystem" % (otherOS, fs_type))
            return

        """
Beispiel #2
0
    def start_installation(self):
        """ Alongside method shrinks selected partition
        and creates root and swap partition in the available space """

        if self.is_room_available() == False:
            return

        partition_path = self.row[0]
        otherOS = self.row[1]
        fs_type = self.row[2]

        # What if path is sda10 (two digits) ? this is wrong
        device_path = self.row[0][:-1]

        #re.search(r'\d+$', self.row[0])

        new_size = self.new_size

        # First, shrink filesystem
        res = fs.resize(partition_path, fs_type, new_size)
        if res:
            #logging.info("Filesystem on " + partition_path + " shrunk.\nWill recreate partition now on device " + device_path + " partition " + partition_path)
            txt = _("Filesystem on %s shrunk.") % partition_path
            txt += "\n"
            txt += _("Will recreate partition now on device %s partition %s") % (device_path, partition_path)
            logging.debug(txt)
            # destroy original partition and create a new resized one
            res = pm.split_partition(device_path, partition_path, new_size)
        else:
            txt = _("Can't shrink %s(%s) filesystem") % (otherOS, fs_type)
            logging.error(txt)
            show.error(txt)
            return

        # 'res' is either False or a parted.Geometry for the new free space
        if res is not None:
            txt = _("Partition %s shrink complete") % partition_path
            logging.debug(txt)
        else:
            txt = _("Can't shrink %s(%s) partition") % (otherOS, fs_type)
            logging.error(txt)
            show.error(txt)
            txt = _("*** FILESYSTEM IN UNSAFE STATE ***")
            txt += "\n"
            txt += _("Filesystem shrink succeeded but partition shrink failed.")
            logging.error(txt)
            return

        disc_dic = pm.get_devices()
        disk = disc_dic[device_path][0]
        mount_devices = {}
        fs_devices = {}

        mem_total = subprocess.check_output(["grep", "MemTotal", "/proc/meminfo"]).decode()
        mem_total = int(mem_total.split()[1])
        mem = mem_total / 1024

        # If geometry gives us at least 7.5GB (MIN_ROOT_SIZE + 1GB) we'll create ROOT and SWAP
        no_swap = False
        if res.getLength('MB') < MIN_ROOT_SIZE + 1:
            if mem < 2048:
                # Less than 2GB RAM and no swap? No way.
                txt = _("Cannot create new swap partition. Not enough free space")
                logging.error(txt)
                show.error(txt)
                return
            else:
                no_swap = True

        if no_swap:
            npart = pm.create_partition(device_path, 0, res)
            if npart is None:
                txt = _("Cannot create new partition.")
                logging.error(txt)
                show.error(txt)
                return
            pm.finalize_changes(disk)
            mount_devices["/"] = npart.path
            fs_devices[npart.path] = "ext4"
            fs.create_fs(npart.path, 'ext4', label='ROOT')
        else:
            # We know for a fact we have at least MIN_ROOT_SIZE + 1GB of space,
            # and at least MIN_ROOT_SIZE of those must go to ROOT.

            # 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 = res.getLength('MB') * 0.1
            if swap_part_size > max_swap:
                swap_part_size = max_swap

            # Create swap partition
            units = 1000000
            sec_size = disk.device.sectorSize
            new_length = int(swap_part_size * units / sec_size)
            new_end_sector = res.start + new_length
            my_geometry = pm.geom_builder(disk, res.start, new_end_sector, swap_part_size)
            logging.debug("create_partition %s", my_geometry)
            swappart = pm.create_partition(disk, 0, my_geometry)
            if swappart is None:
                txt = _("Cannot create new swap partition.")
                logging.error(txt)
                show.error(txt)
                return

            # Create new partition for /
            new_size_in_mb = res.getLength('MB') - swap_part_size
            start_sector = new_end_sector + 1
            my_geometry = pm.geom_builder(disk, start_sector, res.end, new_size_in_mb)
            logging.debug("create_partition %s", my_geometry)
            npart = pm.create_partition(disk, 0, my_geometry)
            if npart is None:
                txt = _("Cannot create new partition.")
                logging.error(txt)
                show.error(txt)
                return

            pm.finalize_changes(disk)

            # Mount points
            mount_devices["swap"] = swappart.path
            fs_devices[swappart.path] = "swap"
            fs.create_fs(swappart.path, 'swap', 'SWAP')

            mount_devices["/"] = npart.path
            fs_devices[npart.path] = "ext4"
            fs.create_fs(npart.path, 'ext4', 'ROOT')

        self.settings.set('install_bootloader', True)
        
        if self.settings.get('install_bootloader'):
            if self.settings.get('efi'):
                self.settings.set('bootloader_type', "UEFI_x86_64")
                self.settings.set('bootloader_location', '/boot')
            else:
                self.settings.set('bootloader_type', "GRUB2")
                self.settings.set('bootloader_location', device_path)

            logging.info(_("Thus will install the bootloader of type %s in %s") %
                          (self.settings.get('bootloader_type'),
                           self.settings.get('bootloader_location')))
        else:
            logging.warning("Cnchi will not install any boot loader")

        if not self.testing:
            self.process = installation_process.InstallationProcess( \
                            self.settings, \
                            self.callback_queue, \
                            mount_devices, \
                            fs_devices, \
                            None, \
                            self.alternate_package_list)

            self.process.start()
Beispiel #3
0
    def start_installation(self):
        """ Alongside method shrinks selected partition
        and creates root and swap partition in the available space """

        if self.is_room_available() == False:
            return

        partition_path = self.row[0]
        otherOS = self.row[1]
        fs_type = self.row[2]

        # What if path is sda10 (two digits) ? this is wrong
        device_path = self.row[0][:-1]

        #re.search(r'\d+$', self.row[0])

        new_size = self.new_size

        # First, shrink filesystem
        res = fs.resize(partition_path, fs_type, new_size)
        if res:
            #logging.info("Filesystem on " + partition_path + " shrunk.\nWill recreate partition now on device " + device_path + " partition " + partition_path)
            txt = _("Filesystem on %s shrunk.") % partition_path
            txt += "\n"
            txt += _("Will recreate partition now on device %s partition %s"
                     ) % (device_path, partition_path)
            logging.debug(txt)
            # destroy original partition and create a new resized one
            res = pm.split_partition(device_path, partition_path, new_size)
        else:
            txt = _("Can't shrink %s(%s) filesystem") % (otherOS, fs_type)
            logging.error(txt)
            show.error(txt)
            return

        # 'res' is either False or a parted.Geometry for the new free space
        if res is not None:
            txt = _("Partition %s shrink complete") % partition_path
            logging.debug(txt)
        else:
            txt = _("Can't shrink %s(%s) partition") % (otherOS, fs_type)
            logging.error(txt)
            show.error(txt)
            txt = _("*** FILESYSTEM IN UNSAFE STATE ***")
            txt += "\n"
            txt += _(
                "Filesystem shrink succeeded but partition shrink failed.")
            logging.error(txt)
            return

        disc_dic = pm.get_devices()
        disk = disc_dic[device_path][0]
        mount_devices = {}
        fs_devices = {}

        mem_total = subprocess.check_output(
            ["grep", "MemTotal", "/proc/meminfo"]).decode()
        mem_total = int(mem_total.split()[1])
        mem = mem_total / 1024

        # If geometry gives us at least 7.5GB (MIN_ROOT_SIZE + 1GB) we'll create ROOT and SWAP
        no_swap = False
        if res.getLength('MB') < MIN_ROOT_SIZE + 1:
            if mem < 2048:
                # Less than 2GB RAM and no swap? No way.
                txt = _(
                    "Cannot create new swap partition. Not enough free space")
                logging.error(txt)
                show.error(txt)
                return
            else:
                no_swap = True

        if no_swap:
            npart = pm.create_partition(device_path, 0, res)
            if npart is None:
                txt = _("Cannot create new partition.")
                logging.error(txt)
                show.error(txt)
                return
            pm.finalize_changes(disk)
            mount_devices["/"] = npart.path
            fs_devices[npart.path] = "ext4"
            fs.create_fs(npart.path, 'ext4', label='ROOT')
        else:
            # We know for a fact we have at least MIN_ROOT_SIZE + 1GB of space,
            # and at least MIN_ROOT_SIZE of those must go to ROOT.

            # 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 = res.getLength('MB') * 0.1
            if swap_part_size > max_swap:
                swap_part_size = max_swap

            # Create swap partition
            units = 1000000
            sec_size = disk.device.sectorSize
            new_length = int(swap_part_size * units / sec_size)
            new_end_sector = res.start + new_length
            my_geometry = pm.geom_builder(disk, res.start, new_end_sector,
                                          swap_part_size)
            logging.debug("create_partition %s", my_geometry)
            swappart = pm.create_partition(disk, 0, my_geometry)
            if swappart is None:
                txt = _("Cannot create new swap partition.")
                logging.error(txt)
                show.error(txt)
                return

            # Create new partition for /
            new_size_in_mb = res.getLength('MB') - swap_part_size
            start_sector = new_end_sector + 1
            my_geometry = pm.geom_builder(disk, start_sector, res.end,
                                          new_size_in_mb)
            logging.debug("create_partition %s", my_geometry)
            npart = pm.create_partition(disk, 0, my_geometry)
            if npart is None:
                txt = _("Cannot create new partition.")
                logging.error(txt)
                show.error(txt)
                return

            pm.finalize_changes(disk)

            # Mount points
            mount_devices["swap"] = swappart.path
            fs_devices[swappart.path] = "swap"
            fs.create_fs(swappart.path, 'swap', 'SWAP')

            mount_devices["/"] = npart.path
            fs_devices[npart.path] = "ext4"
            fs.create_fs(npart.path, 'ext4', 'ROOT')

        self.settings.set('install_bootloader', True)

        if self.settings.get('install_bootloader'):
            if self.settings.get('efi'):
                self.settings.set('bootloader_type', "UEFI_x86_64")
                self.settings.set('bootloader_location', '/boot')
            else:
                self.settings.set('bootloader_type', "GRUB2")
                self.settings.set('bootloader_location', device_path)

            logging.info(
                _("Thus will install the bootloader of type %s in %s") %
                (self.settings.get('bootloader_type'),
                 self.settings.get('bootloader_location')))
        else:
            logging.warning("Cnchi will not install any boot loader")

        if not self.testing:
            self.process = installation_process.InstallationProcess( \
                            self.settings, \
                            self.callback_queue, \
                            mount_devices, \
                            fs_devices, \
                            None, \
                            self.alternate_package_list)

            self.process.start()