def get_rootfs_size(self, actual_rootfs_size=0): """ Calculate the required size of rootfs taking into consideration --size/--fixed-size flags as well as overhead and extra space, as specified in kickstart file. Raises an error if the `actual_rootfs_size` is larger than fixed-size rootfs. """ if self.fixed_size: rootfs_size = self.fixed_size if actual_rootfs_size > rootfs_size: msger.error("Actual rootfs size (%d kB) is larger than allowed size %d kB" \ %(actual_rootfs_size, rootfs_size)) else: extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) return rootfs_size
def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a btrfs rootfs partition. Currently handles ext2/3/4 and btrfs. """ du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0]) extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ (rootfs, rootfs_size) exec_cmd(dd_cmd) label_str = "" if self.label: label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \ (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def prepare_rootfs_btrfs(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a btrfs rootfs partition. Currently handles ext2/3/4 and btrfs. """ du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0]) extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) label_str = "" if self.label: label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -b %d -r %s %s %s" % \ (self.fstype, rootfs_size * 1024, rootfs_dir, label_str, rootfs) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a vfat rootfs partition. """ du_cmd = "du -bks %s" % rootfs_dir out = exec_cmd(du_cmd) blocks = int(out.split()[0]) extra_blocks = self.get_extra_block_count(blocks) if extra_blocks < self.extra_space: extra_blocks = self.extra_space blocks += extra_blocks msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, blocks)) label_str = "-n boot" if self.label: label_str = "-n %s" % self.label dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks) exec_native_cmd(dosfs_cmd, native_sysroot) mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) exec_native_cmd(mcopy_cmd, native_sysroot) chmod_cmd = "chmod 644 %s" % rootfs exec_cmd(chmod_cmd)
def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for an ext2/3/4 rootfs partition. """ du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0]) extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) exec_cmd("truncate %s -s %d" % (rootfs, rootfs_size * 1024)) extra_imagecmd = "-i 8192" label_str = "" if self.label: label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \ (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo) mkfs_cmd = "fsck.%s -pvfD %s || [ $? -le 3 ]" % (self.fstype, rootfs) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for an ext2/3/4 rootfs partition. """ du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0]) extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) dd_cmd = "dd if=/dev/zero of=%s bs=1024 seek=%d count=0 bs=1k" % \ (rootfs, rootfs_size) exec_cmd(dd_cmd) extra_imagecmd = "-i 8192" label_str = "" if self.label: label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \ (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def prepare_rootfs_ext(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for an ext2/3/4 rootfs partition. """ du_cmd = "du -ks %s" % rootfs_dir out = exec_cmd(du_cmd) actual_rootfs_size = int(out.split()[0]) extra_blocks = self.get_extra_block_count(actual_rootfs_size) if extra_blocks < self.extra_space: extra_blocks = self.extra_space rootfs_size = actual_rootfs_size + extra_blocks rootfs_size *= self.overhead_factor msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, rootfs_size)) with open(rootfs, 'w') as sparse: os.ftruncate(sparse.fileno(), rootfs_size * 1024) extra_imagecmd = "-i 8192" label_str = "" if self.label: label_str = "-L %s" % self.label mkfs_cmd = "mkfs.%s -F %s %s %s -d %s" % \ (self.fstype, extra_imagecmd, rootfs, label_str, rootfs_dir) exec_native_cmd(mkfs_cmd, native_sysroot, pseudo=pseudo)
def get_extra_block_count(self, current_blocks): """ The --size param is reflected in self.size (in kB), and we already have current_blocks (1k) blocks, calculate and return the number of (1k) blocks we need to add to get to --size, 0 if we're already there or beyond. """ msger.debug("Requested partition size for %s: %d" % (self.mountpoint, self.size)) if not self.size: return 0 requested_blocks = self.size msger.debug("Requested blocks %d, current_blocks %d" % (requested_blocks, current_blocks)) if requested_blocks > current_blocks: return requested_blocks - current_blocks else: return 0
def get_extra_block_count(self, current_blocks): """ The --size param is reflected in self.size (in kB), and we already have current_blocks (1k) blocks, calculate and return the number of (1k) blocks we need to add to get to --size, 0 if we're already there or beyond. """ msger.debug("Requested partition size for %s: %d" % \ (self.mountpoint, self.size)) if not self.size: return 0 requested_blocks = self.size msger.debug("Requested blocks %d, current_blocks %d" % \ (requested_blocks, current_blocks)) if requested_blocks > current_blocks: return requested_blocks - current_blocks else: return 0
def prepare_rootfs_vfat(self, rootfs, oe_builddir, rootfs_dir, native_sysroot, pseudo): """ Prepare content for a vfat rootfs partition. """ du_cmd = "du -bks %s" % rootfs_dir out = exec_cmd(du_cmd) blocks = int(out.split()[0]) extra_blocks = self.get_extra_block_count(blocks) if extra_blocks < self.extra_space: extra_blocks = self.extra_space blocks += extra_blocks msger.debug("Added %d extra blocks to %s to get to %d total blocks" % \ (extra_blocks, self.mountpoint, blocks)) # Ensure total sectors is an integral number of sectors per # track or mcopy will complain. Sectors are 512 bytes, and we # generate images with 32 sectors per track. This calculation # is done in blocks, thus the mod by 16 instead of 32. Apply # sector count fix only when needed. if blocks % 16 != 0: blocks += (16 - (blocks % 16)) label_str = "-n boot" if self.label: label_str = "-n %s" % self.label dosfs_cmd = "mkdosfs %s -S 512 -C %s %d" % (label_str, rootfs, blocks) exec_native_cmd(dosfs_cmd, native_sysroot) mcopy_cmd = "mcopy -i %s -s %s/* ::/" % (rootfs, rootfs_dir) exec_native_cmd(mcopy_cmd, native_sysroot) chmod_cmd = "chmod 644 %s" % rootfs exec_cmd(chmod_cmd)