@@ -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+
6486function deactivate_device_mappings {
6587 if lvm_system; then
6688 deactivate_volume_group
@@ -74,10 +96,11 @@ function deactivate_device_mappings {
7496}
7597
7698function 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
83106function 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
284315fi
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
292323fi
293324
@@ -297,7 +328,7 @@ if [ "$(get_partition_table_type "${disk}")" = 'gpt' ];then
297328fi
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
303334if lvm_system; then
328359fi
329360
330361# wait for the root device to appear
331- wait_for_storage_device " ${root_device } "
362+ wait_for_storage_device " ${last_device } "
0 commit comments