Custom Disk Partitions¶
By design, KIWI does not support a customized partition table. Alternatively, KIWI supports the definition of user-defined volumes which covers most of common use cases. See Custom Disk Volumes for further details about that.
KIWI has its own partitioning schema which is defined according to several different user configurations: boot firmware, boot partition, expandable layouts, etc. Those supported features have an impact on the partitioning schema. MBR or GUID partition tables are not flexible, carry limitations and are tied to some specific disk geometry. Because of that the preferred alternative to disk layouts based on traditional partition tables is using flexible approaches like logic volumes.
As an example, expandable OEM images is a relevant KIWI feature that is incompatible with the idea of adding user defined partitions on the system area.
Despite no full customization is supported, some aspects of the partition schema can be customized. KIWI supports:
Adding a spare partition before the root (
It can be achieved by using the
spare_parttype attribute, see Schema Documentation.
Leaving some unpartitioned area at the end of the disk.
Setting some unpartitioned free space on the disk can be done using the
sizeelement in type’s section. [LINK]
Expand built disks to a new size adding unpartitioned free space at the end of the disk.
A built image can be resized by using the
kiwi-ng image resizecommand and set a new extended size for the disk. See KIWI commands docs here.
Custom Partitioning at Boot Time¶
Adding additional partitions at boot time of KIWI images is also possible, however, setting the tools and scripts for doing so needs to be handled by the user. A possible strategy to add partitions on system area are described below.
The main idea consists on running a first boot service that creates the partitions that are needed. Adding custom services is simple, use the following steps:
Create a unit file for a systemd service:
[Unit] Description=Add a data partition After=basic.target Wants=basic.target [Service] Type=oneshot ExecStart=/bin/bash /usr/local/bin/create_part
This systemd unit file will run at boot time once systemd reaches the basic target. At this stage all basic services are up an running (devices mounted, network interfaces up, etc.). In case the service is required to run on earlier stages for some reason, default dependencies need to be disabled, see systemd man pages.
Create partitioner shell script matching your specific needs
Consider the following steps for a partitioner shell script that creates a new partition. Following the above unit file example the
/usr/local/bin/create_partscript should cover the following steps:
Verify partition exists
Verify the required partition is not mounted neither exists. Exit zero (0) if is already there.
Use tools such
findmntto find the root device and
lsblkto find a partition with certain label or similar criteria.
Create a new partition
Create a new partition. On error, exit with non zero.
Use partitioner tools such as
sgdiskthat can be easily used in non interactive scripts. Using
partprobeto reload partition table to make OS aware of the changes is handy.
Add the desired filesystem to the new partitions. On error, exit with non zero.
Regular filesystem formatting tools (
mkfs.ext4just to mention one) can be used to apply the desired filesystem to the just created new partition. At this stage it is handy to add a label to the filesystem for easy recognition on later stages or script reruns.
Update fstab file
Just echo and append the desired entry in /etc/fstab.
mount --allwill try to mount all fstab volumes, it just omits any already mounted device.
Add additional files into the root overlay tree.
The above described unit files and partition creation shell script need to be included into the overlay tree of the image, thus they should be placed into the expected paths in root folder (or in
Activate the service in
The service needs to be enabled during image built time to be run during the very first boot. In can be done by adding the following snipped inside the