Skip to content

Commit 213518b

Browse files
committed
Drop root only resize restriction
The current kiwi-resize code was restricted to the root partition for historical reasons. As in a partition table only the last partition can resize, this should be the only limitation for the resize code to perform its job. In connection with the rd.kiwi.install.retain_last feature it is also very likely that the last partition is not the root partition but it should be properly restored by the resize code after deployment
1 parent 912dd0f commit 213518b

File tree

6 files changed

+88
-93
lines changed

6 files changed

+88
-93
lines changed

dracut/modules.d/55kiwi-dump/kiwi-dump-image.sh

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -409,9 +409,6 @@ function dump_image {
409409
report_and_quit "Failed to install image"
410410
fi
411411
fi
412-
if [ "${count}" -gt 0 ]; then
413-
recreate_last_partition "${image_target}"
414-
fi
415412
}
416413

417414
function fetch_local_partition_table {
@@ -490,28 +487,6 @@ function optimize_count_for_32k_blocksize {
490487
echo "${count}"
491488
}
492489

493-
function recreate_last_partition {
494-
local image_target=$1
495-
local table_type
496-
table_type=$(get_partition_table_type "${image_target}")
497-
if [ "${table_type}" = "gpt" ];then
498-
relocate_gpt_at_end_of_disk "${image_target}"
499-
fi
500-
sfdisk -d "${image_target}" > /tmp/parttable 2>/dev/null
501-
head -n -1 /tmp/parttable > /tmp/parttable_1
502-
tail -n 1 /tmp/parttable > /tmp/parttable_2
503-
if [ "${table_type}" = "gpt" ];then
504-
sed -ie "s@\(/dev/.* : start=.*\), size=.*, \(type=.*, uuid=.*, name=\".*\"\)@\1, \2@" \
505-
/tmp/parttable_2
506-
else
507-
sed -ie "s@\(/dev/.* : start=.*\), size=.*, \(type=.*\)@\1, \2@" \
508-
/tmp/parttable_2
509-
fi
510-
cat /tmp/parttable_1 /tmp/parttable_2 > /tmp/parttable
511-
set_device_lock "${image_target}" \
512-
sfdisk -f "${image_target}" < /tmp/parttable
513-
}
514-
515490
function dump_local_image {
516491
local image_source=$1
517492
local image_target=$2

dracut/modules.d/55kiwi-repart/kiwi-repart-disk.sh

Lines changed: 54 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -47,20 +47,42 @@ function initialize {
4747
export disk
4848
fi
4949

50-
root_device=${root#block:}
51-
export root_device
50+
last_device=$(get_last_partition_device "${disk}")
51+
export last_device
5252

5353
disk_free_mbytes=$((
5454
$(get_free_disk_bytes "${disk}") / 1048576
5555
))
5656
export disk_free_mbytes
5757

5858
disk_root_mbytes=$((
59-
$(get_block_device_kbsize "${root_device}") / 1024
59+
$(get_block_device_kbsize "${last_device}") / 1024
6060
))
6161
export disk_root_mbytes
6262
}
6363

64+
function get_last_partition_id_from_config_file {
65+
# """
66+
# Read the partition id with the biggest value from
67+
# config.partids. This method will be replaced by
68+
# get_last_partition_id() in the future. As of today
69+
# there is still code in 59kiwi-lib which reads
70+
# the imported variables from config.partids. This
71+
# code needs to be refactored first before we can
72+
# get rid of config.partids
73+
# """
74+
local partition_ids=/config.partids
75+
local partid=1
76+
local partid_cur
77+
while read -r partname; do
78+
partid_cur=$(echo "${partname}" | cut -f2 -d= | tr -d \")
79+
if [ "${partid_cur}" -gt "${partid}" ];then
80+
partid="${partid_cur}"
81+
fi
82+
done < "${partition_ids}"
83+
echo "${partid}"
84+
}
85+
6486
function deactivate_device_mappings {
6587
if lvm_system;then
6688
deactivate_volume_group
@@ -74,10 +96,11 @@ function deactivate_device_mappings {
7496
}
7597

7698
function finalize_disk_repart {
77-
declare kiwi_RootPart=${kiwi_RootPart}
99+
local kiwi_ResizePart
100+
kiwi_ResizePart=$(get_last_partition_id_from_config_file)
78101
finalize_partition_table "${disk}"
79102
set_root_map \
80-
"$(get_partition_node_name "${disk}" "${kiwi_RootPart}")"
103+
"$(get_partition_node_name "${disk}" "${kiwi_ResizePart}")"
81104
}
82105

83106
function get_target_rootpart_size {
@@ -103,9 +126,14 @@ function repart_standard_disk {
103126
# pX+1: ( root ) [+luks +raid]
104127
# -------------------------------------
105128
# """
106-
declare kiwi_RootPart=${kiwi_RootPart}
107129
local kiwi_oemrootMB
130+
local kiwi_ResizePart
131+
local command_query
132+
local root_part_size
133+
local part_name
108134
kiwi_oemrootMB=$(get_target_rootpart_size)
135+
kiwi_ResizePart=$(get_last_partition_id_from_config_file)
136+
part_name=$(sfdisk --part-label "${disk}" "${kiwi_ResizePart}")
109137
if [ -z "${kiwi_oemrootMB}" ];then
110138
local disk_have_root_system_mbytes=$((
111139
disk_root_mbytes + disk_free_mbytes
@@ -129,21 +157,20 @@ function repart_standard_disk {
129157
# deactivate all active device mappings
130158
deactivate_device_mappings
131159
# repart root partition
132-
local command_query
133-
local root_part_size=+${disk_have_root_system_mbytes}M
160+
root_part_size=+${disk_have_root_system_mbytes}M
134161
if [ -z "${kiwi_oemrootMB}" ];then
135162
# no new parts and no rootsize limit, use rest disk space
136163
root_part_size=.
137164
fi
138165
command_query="
139-
d ${kiwi_RootPart}
140-
n p:lxroot ${kiwi_RootPart} . ${root_part_size}
166+
d ${kiwi_ResizePart}
167+
n ${part_name} ${kiwi_ResizePart} . ${root_part_size}
141168
"
142169
if mdraid_system; then
143170
command_query="
144-
d ${kiwi_RootPart}
145-
n p:lxraid ${kiwi_RootPart} . ${root_part_size}
146-
t ${kiwi_RootPart} fd
171+
d ${kiwi_ResizePart}
172+
n ${part_name} ${kiwi_ResizePart} . ${root_part_size}
173+
t ${kiwi_ResizePart} fd
147174
"
148175
fi
149176
if ! create_partitions "${disk}" "${command_query}";then
@@ -165,9 +192,14 @@ function repart_lvm_disk {
165192
# pX+1: ( LVM ) [+luks +raid]
166193
# -------------------------------------
167194
# """
168-
declare kiwi_RootPart=${kiwi_RootPart}
169195
local kiwi_oemrootMB
196+
local kiwi_ResizePart
197+
local command_query
198+
local lvm_part_size
199+
local part_name
170200
kiwi_oemrootMB=$(get_target_rootpart_size)
201+
kiwi_ResizePart=$(get_last_partition_id_from_config_file)
202+
part_name=$(sfdisk --part-label "${disk}" "${kiwi_ResizePart}")
171203
if [ -z "${kiwi_oemrootMB}" ];then
172204
local disk_have_root_system_mbytes=$((
173205
disk_root_mbytes + disk_free_mbytes
@@ -195,16 +227,15 @@ function repart_lvm_disk {
195227
# create lvm.conf appropriate for resize
196228
setup_lvm_config
197229
# repart lvm partition
198-
local command_query
199-
local lvm_part_size=+${disk_have_root_system_mbytes}M
230+
lvm_part_size=+${disk_have_root_system_mbytes}M
200231
if [ -z "${kiwi_oemrootMB}" ];then
201232
# no rootsize limit, use rest disk space
202233
lvm_part_size=.
203234
fi
204235
command_query="
205-
d ${kiwi_RootPart}
206-
n p:lxlvm ${kiwi_RootPart} . ${lvm_part_size}
207-
t ${kiwi_RootPart} 8e
236+
d ${kiwi_ResizePart}
237+
n ${part_name} ${kiwi_ResizePart} . ${lvm_part_size}
238+
t ${kiwi_ResizePart} 8e
208239
"
209240
if ! create_partitions "${disk}" "${command_query}";then
210241
die "Failed to create partition table"
@@ -284,10 +315,10 @@ if luks_system "${disk}";then
284315
fi
285316

286317
# wait for the root device to appear
287-
wait_for_storage_device "${root_device}"
318+
wait_for_storage_device "${last_device}"
288319

289320
# check if repart/resize is wanted
290-
if ! resize_wanted "${root_device}" "${disk}"; then
321+
if ! resize_wanted "${last_device}" "${disk}"; then
291322
return
292323
fi
293324

@@ -297,7 +328,7 @@ if [ "$(get_partition_table_type "${disk}")" = 'gpt' ];then
297328
fi
298329

299330
# wait for the root device to appear
300-
wait_for_storage_device "${root_device}"
331+
wait_for_storage_device "${last_device}"
301332

302333
# resize disk partition table
303334
if lvm_system;then
@@ -328,4 +359,4 @@ else
328359
fi
329360

330361
# wait for the root device to appear
331-
wait_for_storage_device "${root_device}"
362+
wait_for_storage_device "${last_device}"

dracut/modules.d/59kiwi-lib/kiwi-partitions-lib.sh

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,37 @@ function get_partition_node_name {
213213
return 1
214214
}
215215

216+
function recreate_last_partition {
217+
local image_target=$1
218+
local table_type
219+
table_type=$(get_partition_table_type "${image_target}")
220+
if [ "${table_type}" = "gpt" ];then
221+
relocate_gpt_at_end_of_disk "${image_target}"
222+
fi
223+
sfdisk -d "${image_target}" > /tmp/parttable 2>/dev/null
224+
head -n -1 /tmp/parttable > /tmp/parttable_1
225+
tail -n 1 /tmp/parttable > /tmp/parttable_2
226+
if [ "${table_type}" = "gpt" ];then
227+
sed -ie "s@\(/dev/.* : start=.*\), size=.*, \(type=.*, uuid=.*, name=\".*\"\)@\1, \2@" \
228+
/tmp/parttable_2
229+
else
230+
sed -ie "s@\(/dev/.* : start=.*\), size=.*, \(type=.*\)@\1, \2@" \
231+
/tmp/parttable_2
232+
fi
233+
cat /tmp/parttable_1 /tmp/parttable_2 > /tmp/parttable
234+
set_device_lock "${image_target}" \
235+
sfdisk -f "${image_target}" < /tmp/parttable
236+
}
237+
238+
function get_last_partition_device {
239+
# """
240+
# Get unix node of last partition in table
241+
# """
242+
local disk=$1
243+
lsblk -p -n -r -o NAME,TYPE "${disk}" |\
244+
grep -E "part|md$" | tail -n 1 | cut -f1 -d ' '
245+
}
246+
216247
function get_last_partition_id {
217248
# """
218249
# Get index of last partition from the current table

kiwi/builder/disk.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ def _build_and_map_disk_partitions(
12101210
if root_clone_count:
12111211
rootfs_mbsize = int(rootfs_mbsize / (root_clone_count + 1))
12121212
else:
1213-
if self.oem_systemsize and not self.oem_resize:
1213+
if self.oem_systemsize:
12141214
rootfs_mbsize = self.oem_systemsize
12151215
else:
12161216
rootfs_mbsize = 'all_free'

kiwi/schema/kiwi.rnc

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1452,19 +1452,6 @@ div {
14521452
]
14531453
]
14541454
]
1455-
sch:pattern [
1456-
abstract = "true"
1457-
id = "image_expandable"
1458-
sch:rule [
1459-
context = "type[@$attr='true']"
1460-
sch:assert [
1461-
test = "oemconfig/oem-resize[contains(text(), 'false')]"
1462-
"$attr attribute also needs the setting: "
1463-
"<oem-resize>false</oem-resize> in the "
1464-
"<oemconfig> section of the selected <type>"
1465-
]
1466-
]
1467-
]
14681455
sch:pattern [
14691456
abstract = "true"
14701457
id = "image_verity_requirement"
@@ -1632,24 +1619,12 @@ div {
16321619
]
16331620
k.type.spare_part_is_last.attribute =
16341621
## Specify if the spare partition should be the last one in
1635-
## the partition table. Can only be configured for the oem
1636-
## type with oem-resize switched off. By default the root
1637-
## partition is the last one and the spare partition lives
1638-
## before it. With this attribute that setup can be toggled.
1639-
## However if the root partition is no longer the last one
1640-
## the oem repart/resize code can no longer work because
1641-
## the spare part would block it. Because of that moving
1642-
## the spare part at the end of the disk is only applied
1643-
## if oem-resize is switched off. There is a runtime
1644-
## check in the kiwi code to check this condition
1622+
## the partition table.
16451623
attribute spare_part_is_last { xsd:boolean }
16461624
>> sch:pattern [ id = "spare_part_is_last" is-a = "image_type"
16471625
sch:param [ name = "attr" value = "spare_part_is_last" ]
16481626
sch:param [ name = "types" value = "oem" ]
16491627
]
1650-
>> sch:pattern [ id = "spare_part_is_last_valid" is-a = "image_expandable"
1651-
sch:param [ name = "attr" value = "spare_part_is_last" ]
1652-
]
16531628
k.type.bootpartsize.attribute =
16541629
## For images with a separate boot partition this attribute
16551630
## specifies the size in MB. If not set the min bootpart

kiwi/schema/kiwi.rng

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,11 +2196,6 @@ volume management system</a:documentation>
21962196
<sch:assert test="vagrantconfig[@provider]">&lt;vagrantconfig&gt; section is required for the vagrant format</sch:assert>
21972197
</sch:rule>
21982198
</sch:pattern>
2199-
<sch:pattern abstract="true" id="image_expandable">
2200-
<sch:rule context="type[@$attr='true']">
2201-
<sch:assert test="oemconfig/oem-resize[contains(text(), 'false')]">$attr attribute also needs the setting: &lt;oem-resize&gt;false&lt;/oem-resize&gt; in the &lt;oemconfig&gt; section of the selected &lt;type&gt;</sch:assert>
2202-
</sch:rule>
2203-
</sch:pattern>
22042199
<sch:pattern abstract="true" id="image_verity_requirement">
22052200
<sch:rule context="type[@embed_verity_metadata]">
22062201
<sch:assert test="@$attr">$attr attribute must be set for embed_verity_metadata</sch:assert>
@@ -2405,25 +2400,13 @@ Can only be configured for the disk image type oem</a:documentation>
24052400
<define name="k.type.spare_part_is_last.attribute">
24062401
<attribute name="spare_part_is_last">
24072402
<a:documentation>Specify if the spare partition should be the last one in
2408-
the partition table. Can only be configured for the oem
2409-
type with oem-resize switched off. By default the root
2410-
partition is the last one and the spare partition lives
2411-
before it. With this attribute that setup can be toggled.
2412-
However if the root partition is no longer the last one
2413-
the oem repart/resize code can no longer work because
2414-
the spare part would block it. Because of that moving
2415-
the spare part at the end of the disk is only applied
2416-
if oem-resize is switched off. There is a runtime
2417-
check in the kiwi code to check this condition</a:documentation>
2403+
the partition table.</a:documentation>
24182404
<data type="boolean"/>
24192405
</attribute>
24202406
<sch:pattern id="spare_part_is_last" is-a="image_type">
24212407
<sch:param name="attr" value="spare_part_is_last"/>
24222408
<sch:param name="types" value="oem"/>
24232409
</sch:pattern>
2424-
<sch:pattern id="spare_part_is_last_valid" is-a="image_expandable">
2425-
<sch:param name="attr" value="spare_part_is_last"/>
2426-
</sch:pattern>
24272410
</define>
24282411
<define name="k.type.bootpartsize.attribute">
24292412
<attribute name="bootpartsize">

0 commit comments

Comments
 (0)