Esempio n. 1
0
    def mount_partition(self, location, offset_bytes, size_bytes):
        '''Mount a partition in a partitioned device or image'''

        with pyfdisk.create_loopback(location, offset=offset_bytes,
                                     size=size_bytes) as loop:
            with self.mount(loop) as mountpoint:
                yield mountpoint
Esempio n. 2
0
    def mount_partition(self, location, offset_bytes, size_bytes):
        '''Mount a partition in a partitioned device or image'''

        with pyfdisk.create_loopback(location,
                                     offset=offset_bytes,
                                     size=size_bytes) as loop:
            with self.mount(loop) as mountpoint:
                yield mountpoint
Esempio n. 3
0
    def create_partitioned_system(self, temp_root, location):
        '''Create a Baserock system in a partitioned disk image or device'''

        part_spec = os.environ.get('PARTITION_FILE', 'partitioning/default')

        disk_size = self.get_disk_size()
        if not disk_size:
            raise writeexts.ExtensionError('DISK_SIZE is not defined')

        dev = partitioning.do_partitioning(location, disk_size,
                                           temp_root, part_spec)

        for part in dev.partitionlist:
            if not hasattr(part, 'mountpoint'):
                continue
            if part.mountpoint == '/':
                # Re-format the rootfs, to include needed extra features
                with pyfdisk.create_loopback(location,
                                             part.extent.start *
                                             dev.sector_size, part.size) as l:
                    self.mkfs_btrfs(l)

            self.status(msg='Mounting partition %d' % part.number)
            offset = part.extent.start * dev.sector_size
            with self.mount_partition(location,
                                      offset, part.size) as part_mount_dir:
                if part.mountpoint == '/':
                    # Install root filesystem
                    rfs_uuid = self.get_uuid(location, part.extent.start *
                                                dev.sector_size)
                    self.create_btrfs_system_layout(temp_root, part_mount_dir,
                                                    'factory', rfs_uuid, dev)
                else:
                    # Copy files to partition from unpacked rootfs
                    src_dir = os.path.join(temp_root,
                                           re.sub('^/', '', part.mountpoint))
                    self.status(msg='Copying files to %s partition' %
                                     part.mountpoint)
                    self.copy_dir_contents(src_dir, part_mount_dir)

        # Write raw files to disk with dd
        partitioning.process_raw_files(dev, temp_root)
Esempio n. 4
0
    def create_partitioned_system(self, temp_root, location):
        '''Deploy a bootable Baserock system with a custom partition layout.

        Called if USE_PARTITIONING=yes is set in the deployment options.

        '''
        part_spec = os.environ.get('PARTITION_FILE', 'partitioning/default')

        disk_size = self.get_disk_size()
        if not disk_size:
            raise writeexts.ExtensionError('DISK_SIZE is not defined')

        dev = partitioning.do_partitioning(location, disk_size,
                                           temp_root, part_spec)
        boot_partition_available = dev.get_partition_by_mountpoint('/boot')

        for part in dev.partitionlist:
            if not hasattr(part, 'mountpoint'):
                continue
            if part.mountpoint == '/':
                # Re-format the rootfs, to include needed extra features
                with pyfdisk.create_loopback(location,
                                             part.extent.start *
                                             dev.sector_size, part.size) as l:
                    self.mkfs_btrfs(l)

            self.status(msg='Mounting partition %d' % part.number)
            offset = part.extent.start * dev.sector_size
            with self.mount_partition(location,
                                      offset, part.size) as part_mount_dir:
                if part.mountpoint == '/':
                    # Install root filesystem
                    rfs_uuid = self.get_uuid(location, part.extent.start *
                                                dev.sector_size)
                    self.create_versioned_layout(part_mount_dir, 'factory')
                    self.create_btrfs_system_rootfs(temp_root, part_mount_dir,
                                                   'factory', rfs_uuid, dev)

                    # If there's no /boot partition, but we do need to generate
                    # a bootloader configuration file, then it needs to go in
                    # the root partition.
                    if (boot_partition_available is False
                            and self.bootloader_config_is_wanted()):
                        self.create_bootloader_config(
                            temp_root, part_mount_dir, 'factory', rfs_uuid,
                            dev)

                    if self.get_bootloader_install() == 'extlinux':
                        # The extlinux/syslinux MBR blob always needs to be
                        # installed in the root partition.
                        self.install_syslinux_blob(dev, temp_root)
                else:
                    # Copy files to partition from unpacked rootfs
                    src_dir = os.path.join(temp_root,
                                           re.sub('^/', '', part.mountpoint))
                    self.status(msg='Copying files to %s partition' %
                                     part.mountpoint)
                    self.copy_dir_contents(src_dir, part_mount_dir)

                if (part.mountpoint == '/boot' and
                        self.bootloader_config_is_wanted()):
                    # We need to mirror the layout of the root partition in the
                    # /boot partition. Each kernel lives in its own
                    # systems/$version_label/ directory within the /boot
                    # partition.
                    self.create_versioned_layout(part_mount_dir, 'factory')
                    self.create_bootloader_config(temp_root, part_mount_dir,
                        'factory', None, dev)

        # Write raw files to disk with dd
        partitioning.process_raw_files(dev, temp_root)
Esempio n. 5
0
    def create_partitioned_system(self, temp_root, location):
        '''Deploy a bootable Baserock system with a custom partition layout.

        Called if USE_PARTITIONING=yes is set in the deployment options.

        '''
        part_spec = os.environ.get('PARTITION_FILE', 'partitioning/default')

        disk_size = self.get_disk_size()
        if not disk_size:
            raise writeexts.ExtensionError('DISK_SIZE is not defined')

        dev = partitioning.do_partitioning(location, disk_size, temp_root,
                                           part_spec)
        boot_partition_available = dev.get_partition_by_mountpoint('/boot')

        for part in dev.partitionlist:
            if not hasattr(part, 'mountpoint'):
                continue
            if part.mountpoint == '/':
                # Re-format the rootfs, to include needed extra features
                with pyfdisk.create_loopback(
                        location, part.extent.start * dev.sector_size,
                        part.size) as l:
                    self.mkfs_btrfs(l)

            self.status(msg='Mounting partition %d' % part.number)
            offset = part.extent.start * dev.sector_size
            with self.mount_partition(location, offset,
                                      part.size) as part_mount_dir:
                if part.mountpoint == '/':
                    # Install root filesystem
                    rfs_uuid = self.get_uuid(
                        location, part.extent.start * dev.sector_size)
                    self.create_versioned_layout(part_mount_dir, 'factory')
                    self.create_btrfs_system_rootfs(temp_root, part_mount_dir,
                                                    'factory', rfs_uuid, dev)

                    # If there's no /boot partition, but we do need to generate
                    # a bootloader configuration file, then it needs to go in
                    # the root partition.
                    if (boot_partition_available is False
                            and self.bootloader_config_is_wanted()):
                        self.create_bootloader_config(temp_root,
                                                      part_mount_dir,
                                                      'factory', rfs_uuid, dev)

                    if self.get_bootloader_install() == 'extlinux':
                        # The extlinux/syslinux MBR blob always needs to be
                        # installed in the root partition.
                        self.install_syslinux_blob(dev, temp_root)
                else:
                    # Copy files to partition from unpacked rootfs
                    src_dir = os.path.join(temp_root,
                                           re.sub('^/', '', part.mountpoint))
                    self.status(msg='Copying files to %s partition' %
                                part.mountpoint)
                    self.copy_dir_contents(src_dir, part_mount_dir)

                if (part.mountpoint == '/boot'
                        and self.bootloader_config_is_wanted()):
                    # We need to mirror the layout of the root partition in the
                    # /boot partition. Each kernel lives in its own
                    # systems/$version_label/ directory within the /boot
                    # partition.
                    self.create_versioned_layout(part_mount_dir, 'factory')
                    self.create_bootloader_config(temp_root, part_mount_dir,
                                                  'factory', None, dev)

        # Write raw files to disk with dd
        partitioning.process_raw_files(dev, temp_root)