@@ -154,6 +154,7 @@ class KickStart():
part.add_argument('--include-path', nargs='+', action='append')
part.add_argument('--change-directory')
part.add_argument("--extra-space", type=sizetype("M"))
+ part.add_argument('--keep-free', type=sizetype("M"))
part.add_argument('--fsoptions', dest='fsopts')
part.add_argument('--fspassno', dest='fspassno')
part.add_argument('--fstype', default='vfat',
@@ -259,6 +260,8 @@ class KickStart():
err = "%s:%d: Must set the label with --label" \
% (confpath, lineno)
raise KickStartError(err)
+ if not parsed.keep_free:
+ parsed.keep_free = 0
# using ArgumentParser one cannot easily tell if option
# was passed as argument, if said option has a default
# value; --overhead-factor/--extra-space cannot be used
@@ -32,6 +32,7 @@ class Partition():
self.exclude_path = args.exclude_path
self.include_path = args.include_path
self.change_directory = args.change_directory
+ self.keep_free = args.keep_free
self.fsopts = args.fsopts
self.fspassno = args.fspassno
self.fstype = args.fstype
@@ -91,17 +92,16 @@ class Partition():
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.
-
+ --size/--fixed-size and --keep-free 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
+ rootfs_size = self.fixed_size - self.keep_free
if actual_rootfs_size > rootfs_size:
raise WicError("Actual rootfs size (%d kB) is larger than "
- "allowed size %d kB" %
- (actual_rootfs_size, rootfs_size))
+ "allowed size %d kB (including %d kB keep free)" %
+ (actual_rootfs_size, rootfs_size, self.keep_free))
else:
extra_blocks = self.get_extra_block_count(actual_rootfs_size)
if extra_blocks < self.extra_space:
@@ -119,10 +119,18 @@ class Partition():
def disk_size(self):
"""
Obtain on-disk size of partition taking into consideration
- --size/--fixed-size options.
+ --size/--fixed-size and --keep-free options.
+
+ """
+ return self.fixed_size if self.fixed_size else self.size + self.keep_free
+ @property
+ def fs_size(self):
+ """
+ Obtain on-disk size of filesystem inside the partition taking into
+ consideration --size/--fixed-size and --keep-free options.
"""
- return self.fixed_size if self.fixed_size else self.size
+ return self.fixed_size - self.keep_free if self.fixed_size else self.size
def prepare(self, creator, cr_workdir, oe_builddir, rootfs_dir,
bootimg_dir, kernel_dir, native_sysroot, updated_fstab_path):
@@ -202,10 +210,10 @@ class Partition():
"This a bug in source plugin %s and needs to be fixed." %
(self.mountpoint, self.source))
- if self.fixed_size and self.size > self.fixed_size:
+ if self.fixed_size and self.size + self.keep_free > self.fixed_size:
raise WicError("File system image of partition %s is "
- "larger (%d kB) than its allowed size %d kB" %
- (self.mountpoint, self.size, self.fixed_size))
+ "larger (%d kB + %d kB keep free) than its allowed size %d kB" %
+ (self.mountpoint, self.size, self.keep_free, self.fixed_size))
def prepare_rootfs(self, cr_workdir, oe_builddir, rootfs_dir,
native_sysroot, real_rootfs = True, pseudo_dir = None):
@@ -440,7 +448,7 @@ class Partition():
"""
Prepare an empty ext2/3/4 partition.
"""
- size = self.disk_size
+ size = self.fs_size
with open(rootfs, 'w') as sparse:
os.ftruncate(sparse.fileno(), size * 1024)
@@ -464,7 +472,7 @@ class Partition():
"""
Prepare an empty btrfs partition.
"""
- size = self.disk_size
+ size = self.fs_size
with open(rootfs, 'w') as sparse:
os.ftruncate(sparse.fileno(), size * 1024)
@@ -482,7 +490,7 @@ class Partition():
"""
Prepare an empty vfat partition.
"""
- blocks = self.disk_size
+ blocks = self.fs_size
label_str = "-n boot"
if self.label: