Debian Codegraph @

doc/source/example_use_cases/clone_partitions.rst

raw
1 .. _clone_partitions:
2
3 Partition Clones
4 ================
5
6 .. sidebar:: Abstract
7
8 This page provides details about the partition clone feature
9 and its use cases.
10
11 {kiwi} allows you to create block-level clones of certain partitions
12 used in the image. Clones can be created from the `root`, `boot`,
13 and any other partition listed in the `<partitions>` element.
14
15 A partition clone is a simple byte dump from one
16 block storage device to another. However, this would cause conflicts
17 during boot of the system because all unique identifiers, like
18 the UUID of a filesystem, will no longer be unique. The clone
19 feature of {kiwi} takes care of this part and re-creates the
20 relevant unique identifiers per cloned partition. {kiwi} allows
21 this also for complex partitions like LVM, LUKS, or RAID.
22
23 The partition clone(s) will always appear first in the partition table,
24 followed by the origin partition. The origin partition is the one
25 whose identifier will be referenced and used by the system. By default,
26 no cloned partition will be mounted or used by the system at boot time.
27
28 Let's take a look at the following example:
29
30 .. code:: xml
31
32 <type image="oem" root_clone="1" boot_clone="1" firmware="uefi" filesystem="xfs" bootpartition="true" bootfilesystem="ext4">
33 <partitions>
34 <partition name="home" size="10" mountpoint="/home" filesystem="ext3" clone="2"/>
35 </partitions>
36 <oemconfig>
37 <oem-systemsize>2048</oem-systemsize>
38 <oem-resize>false</oem-resize>
39 </oemconfig>
40 <size unit="G">100</size>
41 </type>
42
43 With the above setup, {kiwi} will create a disk image that
44 contains the following partition table:
45
46 .. code::
47
48 Number Start (sector) End (sector) Size Code Name
49 1 2048 6143 2.0 MiB EF02 p.legacy
50 2 6144 47103 20.0 MiB EF00 p.UEFI
51 3 47104 661503 300.0 MiB 8300 p.lxbootclone1
52 4 661504 1275903 300.0 MiB 8300 p.lxboot
53 5 1275904 1296383 10.0 MiB 8300 p.lxhomeclone1
54 6 1296384 1316863 10.0 MiB 8300 p.lxhomeclone2
55 7 1316864 1337343 10.0 MiB 8300 p.lxhome
56 8 1337344 3864575 2 GiB 8300 p.lxrootclone1
57 9 3864576 6287326 2 GiB 8300 p.lxroot
58
59 When booting the system, only the origin partitions `p.lxboot`, `p.lxroot`,
60 and `p.lxhome` will be mounted and visible in, e.g., :file:`/etc/fstab`,
61 the bootloader, or the initrd. Thus, partition clones are present as a data
62 source but are not relevant for the operating system from a functional
63 perspective.
64
65 As shown in the above example, there is one clone request for root and boot
66 and two clone requests for the home partition. {kiwi} does not sanity-
67 check the provided number of clones (e.g., whether your partition table
68 can hold that many partitions).
69
70 .. warning::
71
72 There is a limit to how many partitions a partition table can hold.
73 This also limits how many clones can be created.
74
75 It's important when using the `root_clone` attribute to specify a size for
76 the part of the system that represents the root partition. As of today, {kiwi}
77 does not automatically divide the root partition into two identical pieces.
78 To create a clone of the partition, a size specification is required.
79 In the above example, the size for root is provided via the `oem-systemsize`
80 element. Using a root clone and fixed size values has the following consequences:
81
82 1. The resize capability must be disabled. This is done via the `oem-resize`
83 element. The reason is that only the last partition in the partition
84 table can be resized without destroying data. If there is a clone of
85 the root partition, it should never be resized because then the two
86 partitions will be different in size and no longer be clones of each other.
87
88 2. There can be unpartitioned space left. In the above example, the overall
89 disk size is set to 100G. The sum of all partition sizes will be smaller
90 than this value, and there is no resize available anymore. Depending
91 on the overall size setup for the disk, this will leave unpartitioned
92 space free on the disk.
93
94 Use Case
95 --------
96
97 Potential use cases for which a clone of one or more partitions
98 is useful include, among others:
99
100 Factory Resets:
101 Creating an image with the option to roll back to the
102 state of the system at deployment time can be very helpful
103 for disaster recovery.
104
105 System Updates with Rollbacks e.g A/B:
106 Creating an image that holds extra space allowing to roll back
107 modified data can make a system more robust. For example,
108 in a simple A/B update concept, partition A would be updated
109 but would flip to B if A is considered broken after applying the
110 update.
111
112 .. note::
113
114 Most probably, any use case based on partition clones requires
115 additional software to manage them. {kiwi} provides the
116 option to create the clone layout, but it does not provide
117 the software to implement the actual use case for which the
118 partition clones are needed.
119
120 Developers writing applications based on a clone layout created
121 with {kiwi} can leverage the metadata file :file:`/config.partids`.
122 This file is created at build time and contains the mapping between
123 the partition `name` and the actual partition number in the partition
124 table. For partition clones, the following naming convention applies:
125
126 .. code::
127
128 kiwi_(name)PartClone(id)="(partition_number)"
129
130 The `(name)` is either taken from the `name` attribute
131 of the `<partition>` element, or it is a fixed name assigned by {kiwi}.
132 There are the following reserved partition names for which cloning
133 is supported:
134
135 * root
136 * readonly
137 * boot
138
139 For the mentioned example, this will result in the
140 following :file:`/config.partids`:
141
142 .. code::
143
144 kiwi_BiosGrub="1"
145 kiwi_EfiPart="2"
146 kiwi_bootPartClone1="3"
147 kiwi_BootPart="4"
148 kiwi_homePartClone1="5"
149 kiwi_homePartClone2="6"
150 kiwi_HomePart="7"
151 kiwi_rootPartClone1="8"
152 kiwi_RootPart="9"