aboutsummaryrefslogtreecommitdiffstats
path: root/deploy/adapters/cobbler/snippets/preseed_pre_partition_disks
blob: 7575b2aa5800c00febbba90bf05e3ade45a3d205 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
#set hostname=$getVar('hostname',None)
#set partition = $getVar('partition', None)
#set partition_size = $getVar('partition_size', None)
#set partition_maxsize = $getVar('partition_maxsize', None)
#set disk_reserve_size = $getVar('disk_reserve_size', None)
#set disk_max_size = $getVar('disk_max_size', None)
#set default_disk_reserve_size = $getVar('default_disk_reserve_size', '0')
#set default_disk_max_size = $getVar('default_disk_max_size', '0')

#if $hostname == None
#set $vgname = "VolGroup00"
#else
#set $vgname = $hostname.split('.')[0]
#end if

echo "partman early script" >> /tmp/preseed.log
if [ -e /dev/disk/by-path ]; then
    set \$(ls -s -l /dev/disk/by-path | tr -s '\t' ' ' | cut -d' ' -f11,13)
    disk_mapping_nums=\$((\$#/2))
    disk_mapping_offset=0
    echo "disk_mapping_nums: \$disk_mapping_nums" >> /tmp/preseed.log
    echo "disk_mapping: \$@" >> /tmp/preseed.log
    disk_mapping=""
    disk_path_mapping=""
    while [ \$disk_mapping_offset -lt \$disk_mapping_nums ]; do
        found_disk_type=0
#if $getVar('disk_type_only','') != ""
        if expr match "\$1" ".*-${disk_type_only}-.*"; then
            found_disk_type=1
        fi
#else
        found_disk_type=1
#end if
        path_name=\$(basename \$1)
        disk_path_name=\$(echo \${path_name} | tr '-' '_' | tr ':' '_' | tr '.' '_')
        disk_name=\$(basename \$2)
        disk_mapping_offset=\$((\${disk_mapping_offset}+1))
        shift 2

        if [ \$found_disk_type -gt 0 ]; then
            if [ -z "\${disk_mapping}" ]; then
                disk_mapping="\${disk_name}"
            else
                disk_mapping="\${disk_mapping} \${disk_name}"
            fi
	    if [ -z "\${disk_path_mapping}" ]; then
                disk_path_mapping="\${disk_path_name}"
	    else
	        disk_path_mapping="\${disk_path_mapping} \${disk_path_name}"
            fi
            eval "disk_\${disk_name}=/dev/disk/by-path/\${path_name}"
	    eval "disk_\${disk_path_name}=/dev/disk/by-path/\${path_name}"
            eval "disk_path_\${disk_path_name}=/dev/\${disk_name}"
            eval "disk_path_\${disk_name}=/dev/\${disk_name}"
        else
            eval "ignore_disk_\${disk_name}=/dev/disk/by-path/\${path_name}"
            eval "ignore_disk_\${disk_path_name}=/dev/disk/by-path/\${path_name}"
            eval "ignore_disk_path_\${disk_path_name}=/dev/\${disk_name}"
            eval "ignore_disk_path_\${disk_name}=/dev/\${disk_name}"
        fi
    done

    for key in \${disk_mapping}; do
        eval "disk_path=\\${disk_\$key}"
        echo "disk_mapping \$key => \${disk_path}" >> /tmp/preseed.log
    done

    for key in \${disk_path_mapping}; do
        eval "disk=\\${disk_path_\$key}"
        echo "disk path mapping \$key => \${disk}" >> /tmp/preseed.log
    done
else
    echo "/dev/disk/by-path does not exist" >> /tmp/preseed.log
fi

partition_disks=""
disks=""
for disk in \$(list-devices disk); do
    disk_name=\$(basename \$disk)
    eval "disk_path=\\${disk_\${disk_name}}" 
    if [ -z "\${disk_path}" ]; then
        eval "ignore_disk_path=\\${ignore_disk_\${disk_name}}"
        if [ ! -z "\${ignore_disk_path}" ]; then
            echo "ignore disk \${disk_name} since it is not in disk_mapping" >> /tmp/preseed.log
            continue
        else
            echo "did not found disk path for \$disk but it is not ignored" >> /tmp/preseed.log
            eval "disk_\${disk_name}=/dev/\${disk_name}"
            eval "disk_path_\${disk_name}=/dev/\${disk_name}"
        fi
    fi
    found_disk=0

#if $getVar('partitions_only','') != ""
    #for $partition_only in $partitions_only.split(',')
        #if not $partition_only
            #continue
        #end if
    if expr match "\${disk_name}" "$partition_only"; then
        found_disk=1
    else
        echo "disk \${disk_name} does not match $partition_only" >> /tmp/preseed.log
    fi
    #end for
#else
    found_disk=1
#end if

#if $getVar('partition_by_path', '0') != "0"
    eval "disk=\\${disk_\${disk_name}}"
#end if

    if [ \$found_disk -gt 0 ]; then
        echo "add disk \${disk} in partitioning list" >> /tmp/preseed.log
        if [ -z "\${partition_disks}" ]; then
            partition_disks="\${disk}"
        else
            partition_disks="\${partition_disks} \${disk}"
        fi
    fi
    if [ -z "\$disks" ]; then
        disks="\${disk}"
    else
        disks="\${disks} \${disk}"
    fi
done
echo "partition disks: \${partition_disks}" >> /tmp/preseed.log
echo "disks \${disks}" >> /tmp/preseed.log

#if $getVar('sort_disks', '0') != "0"
sorted_disks=\$(printf '%s\n' \${partition_disks} | sort)
#else
sorted_disks=\${partition_disks}
#end if
echo "sorted disks \${sorted_disks}" >> /tmp/preseed.log

#if $getVar('start_from_disk', '') != ""
    #set $start_from_disk = $int($start_from_disk)
    #if $start_from_disk > 0
        #set $disk_start_offset = $start_from_disk - 1
    #else
        #set $disk_start_offset = 0
    #end if
set \${sorted_disks}
shift $disk_start_offset
sorted_disks=\$@
echo "sorted disks begin from the $start_from_disk: \${sorted_disks}" >> /tmp/preseed.log
#end if

#if $getVar('disk_num', '') != ""
set \${sorted_disks}
sorted_disks=\$(printf '%s\n' \$@ | head -n${disk_num})
echo "sorted disks for $disk_num disks: \${sorted_disks}" >> /tmp/preseed.log
#end if

first_disk=""
for disk in \${sorted_disks}; do
    if [ -z "\${first_disk}" ]; then
        first_disk=\${disk}
        break
    fi
done
echo "first disk \${first_disk}" >> /tmp/preseed.log

#if $getVar('keep_old_partitions', '0') != "0"
for disk in \${sorted_disks}; do
    dd if=/dev/zero of=\${disk} bs=512 count=1
done
remove_disks=\${sorted_disks}
#else
for disk in \$disks; do
    dd if=/dev/zero of=\$disk bs=512 count=1
done
remove_disks=\${disks}
#end if
echo "remove disks \${remove_disks}" >> /tmp/preseed.log

disk_partitions=\$(pvs --noheadings --separator :| cut -d: -f1)
remove_partitions=""
remove_vgs=""
for disk_partition in \${disk_partitions}; do
    vg=\$(pvs --noheadings --separator : \${disk_partition} | cut -d: -f2)
    remove_vg=""
    remove_partition=""
    for remove_disk in \${remove_disks}; do
#if $getVar('partition_by_path', '0') != "0"
        path_name=\$(basename \${remove_disk})
        disk_path_name=\$(echo \${path_name} | tr '-' '_' | tr ':' '_' | tr '.' '_')
	remove_disk_path=\${remove_disk}
        eval "remove_disk=\\${disk_path_\${disk_path_name}}"
#else
        disk_name=\$(basename \${remove_disk})
        eval "remove_disk_path=\\${disk_\${disk_name}}"
#end if
        if [ -z "\${remove_disk}" ]; then
	    continue
	fi
	if [ -z "\${remove_disk_path}" ]; then
            continue
        fi
        if expr match "\${disk_partition}" "\${remove_disk_path}.*"; then
            remove_vg="\$vg"
            remove_partition="\${disk_partition}"
        else
            echo "partition \${disk_partition} does not match \${remove_disk_path}.*" >> /tmp/preseed.log
        fi
        if expr match "\${disk_partition}" "\${remove_disk}.*"; then
            remove_vg="\$vg"
            remove_partition="\${disk_partition}"
        else
            echo "partition \${disk_partition} does not match \${remove_disk}.*" >> /tmp/preseed.log
        fi
	if [[ "\$vg" == "$vgname" ]]; then
            remove_vg="\$vg"
	    remove_partition="\${disk_partition}"
        fi
    done
    if [ ! -z "\${remove_vg}" ]; then
        if [ -z "\${remove_vgs}" ]; then
            remove_vgs="\${remove_vg}"
        else
            vg_removed=0
            for vg in \${remove_vgs}; do
                if [[ "\$vg" == "\${remove_vg}" ]]; then
                    vg_removed=1
                fi
            done
            if [ \${vg_removed} -eq 0 ]; then
                remove_vgs="\${remove_vgs} \${remove_vg}"
            fi
        fi
    fi
    if [ ! -z "\${remove_partition}" ]; then
        if [ -z "\${remove_partitions}" ]; then
            remove_partitions="\${remove_partition}"
        else
	    pv_removed=0
	    for pv in ${remove_partitions}; do
	        if [[ "\$pv" == "\${remove_partition}" ]]; then
		    pv_removed=1
		fi
	    done
	    if [ \${pv_removed} -eq 0 ]; then
                remove_partitions="\${remove_partitions} \${remove_partition}"
	    fi
        fi
    fi
done

echo "remove vgs \${remove_vgs}" >> /tmp/preseed.log
for remove_vg in \${remove_vgs}; do
    vgremove -f \${remove_vg}
done

echo "remove partitions \${remove_partitions} from \${remove_vgs}" >> /tmp/preseed.log
for remove_partition in \${remove_partitions}; do
    pvremove -ff -y \${remove_partition}
done

echo "remove disks \${remove_disks}" >> /tmp/preseed.log

partition_disks=""
#if $getVar('keep_old_partitions', '0') != "0"
for disk in \${sorted_disks}; do
#else
for disk in \${disks}; do
#end if
    if [ -z "\${partition_disks}" ]; then
        partition_disks="\${disk}"
    else
        partition_disks="\${partition_disks} \${disk}"
    fi
done

partition_disks_str=\$(echo \${partition_disks} | tr ' ' ',')
echo "d-i partman-auto/select_disks multiselect \${partition_disks_str}" >> /tmp/part-include
echo "d-i partman-auto/disk string \${partition_disks}" >> /tmp/part-include
echo "disks \${partition_disks}" >> /tmp/preseed.log

default_partition=$getVar('default_partition', '/')
partition_fstype=$getVar('partition_fstype', 'ext3')

echo "default partition \${default_partition}" >> /tmp/preseed.log
echo "partition fstype \${partition_fstype}" >> /tmp/preseed.log

#if $disk_reserve_size != None
    #set disk_sizes = [disk_size.strip() for disk_size in $disk_reserve_size.split(';') if disk_size.strip()]
    #for disk_and_size in $disk_sizes
        #set disk_name, size = $disk_and_size.split(' ', 1)
        #set disk_name = $disk_name.strip()
	#if $size.endswith('K')
	    #set disk_size = $int($size[:-1]) / 1000
	#elif $size.endswith('M')
	    #set disk_size = $int($size[:-1])
	#elif $size.endswith('G')
	    #set disk_size = $int($size[:-1]) * 1000
	#elif $size.endswith('T')
	    #set disk_size = $int($size[:-1]) * 1000000
	#else
	    #set disk_size = $int($size)
	#end if
reserve_disk_size_${disk_name}=${disk_size}
    #end for
#end if

#if $default_disk_reserve_size.endswith('K')
    #set disk_size = $int($default_disk_reserve_size[:-1]) / 1000
#elif $default_disk_reserve_size.endswith('M')
    #set disk_size = $int($default_disk_reserve_size[:-1])
#elif $default_disk_reserve_size.endswith('G')
    #set disk_size = $int($default_disk_reserve_size[:-1]) * 1000
#elif $default_disk_reserve_size.endswith('T')
    #set disk_size = $int($default_disk_reserve_size[:-1]) * 1000000
#else
    #set disk_size = $int($default_disk_reserve_size)
#end if
default_reserve_disk_size=${disk_size}

#if $disk_max_size != None
    #set disk_sizes = [disk_size.strip() for disk_size in $disk_max_size.split(';') if disk_size.strip()]
    #for disk_and_size in $disk_sizes
        #set disk_name, size = $disk_and_size.split(' ', 1)
        #set disk_name = $disk_name.strip()
	#if $size.endswith('K')
	    #set disk_size = $int($size[:-1]) / 1000
	#elif $size.endswith('M')
	    #set disk_size = $int($size[:-1])
	#elif $size.endswith('G')
	    #set disk_size = $int($size[:-1]) * 1000
	#elif $size.endswith('T')
	    #set disk_size = $int($size[:-1]) * 1000000
	#else
	    #set disk_size = $int($size)
	#end if
max_disk_size_${disk_name}=${disk_size}
    #end for
#end if

#if $default_disk_max_size.endswith('K')
    #set disk_size = $int($default_disk_max_size[:-1]) / 1000
#elif $default_disk_max_size.endswith('M')
    #set disk_size = $int($default_disk_max_size[:-1])
#elif $default_disk_max_size.endswith('G')
    #set disk_size = $int($default_disk_max_size[:-1]) * 1000
#elif $default_disk_max_size.endswith('T')
    #set disk_size = $int($default_disk_max_size[:-1]) * 1000000
#else
    #set disk_size = $int($default_disk_max_size)
#end if
default_max_disk_size=${disk_size}

partition_names=""
default_partition_name=""
#if $partition != None
    #set vol_sizes = [part.strip() for part in $partition.split(';') if part.strip()]
    #for vol_and_size in vol_sizes
        #set vol, vol_size = $vol_and_size.split(' ', 1)
        #set vol = $vol.strip()
	#if $vol == '/'
	    #set volname = 'root'
	#elif $vol == 'swap'
	    #set volname = 'swap'
	#elif $vol.startswith('/')
            #set volname = $vol[1:].replace('/', '_')
	#else
# $vol is not starts with /
            #continue
        #end if
if [ -z "\${partition_names}" ]; then
    partition_names="$volname"
else
    partition_names="\$partition_names $volname"
fi
if [[ "$vol" == "\$default_partition" ]]; then
    default_partition_name=$volname
fi
partition_point_$volname=$vol
        #set vol_size = $vol_size.strip()
	#if $vol_size.endswith('%')
	    #set vol_percent = $vol_size[:-1]
partition_percentage_$volname=$vol_percent
        #else
	    #if $vol_size.endswith('K')
                #set vol_min_size = $int($vol_size[:-1]) / 1000
            #elif $vol_size.endswith('M')
	        #set vol_min_size = $int($vol_size[:-1])
            #elif $vol_size.endswith('G')
	        #set vol_min_size = $int($vol_size[:-1]) * 1000
	    #elif $vol_size.endswith('T')
	        #set vol_min_size = $int($vol_size[:-1]) * 1000000
	    #else
	        #set vol_min_size = $int($vol_size)
	    #end if
partition_size_$volname=$vol_min_size
        #end if
    #end for
#end if

#if $partition_size != None
    #set vol_sizes = [part.strip() for part in $partition_size.split(';') if part.strip()]
    #for vol_and_size in $vol_sizes
        #set vol, vol_size = $vol_and_size.split(' ', 1)
        #set vol = $vol.strip()
	#if $vol == '/'
	    #set volname = 'root'
	#elif $vol == 'swap'
	    #set volname = 'swap'
	#elif $vol.startswith('/')
            #set volname = $vol[1:].replace('/', '_')
	#else
# $vol is not starts with /
            #continue
        #end if
	#if $vol_size.endswith('K')
	    #set vol_min_size = $int($vol_size[:-1]) / 1000
	#elif $vol_size.endswith('M')
	    #set vol_min_size = $int($vol_size[:-1])
	#elif $vol_size.endswith('G')
	    #set vol_min_size = $int($vol_size[:-1]) * 1000
	#elif $vol_size.endswith('T')
	    #set vol_min_size = $int($vol_size[:-1]) * 1000000
	#else
	    #set vol_min_size = $int($vol_size)
	#end if
partitions_size_$volname=${vol_min_size}
    #end for
#end if

#if $partition_maxsize != None
    #set vol_sizes = [part.strip() for part in $partition_maxsize.split(';') if part.strip()]
    #for vol_and_size in $vol_sizes
        #set vol, vol_size = $vol_and_size.split(' ', 1)
        #set vol = $vol.strip()
	#if $vol == '/'
	    #set volname = 'root'
	#elif $vol == 'swap'
	    #set volname = 'swap'
	#elif $vol.startswith('/')
            #set volname = $vol[1:].replace('/', '_')
	#else
# $vol is not starts with /
            #continue
        #end if
	#if $vol_size.endswith('K')
	    #set vol_max_size = $int($vol_size[:-1]) / 1000
	#elif $vol_size.endswith('M')
	    #set vol_max_size = $int($vol_size[:-1])
	#elif $vol_size.endswith('G')
	    #set vol_max_size = $int($vol_size[:-1]) * 1000
	#elif $vol_size.endswith('T')
	    #set vol_max_size = $int($vol_size[:-1]) * 1000000
	#else
	    #set vol_max_size = $int($vol_size)
	#end if
partition_maxsize_$volname=${vol_max_size}
    #end for
#end if

echo "finish partition mapping" >> /tmp/preseed.log
for key in \${partition_names}; do
    eval "mountpoint=\\${partition_point_\$key}"
    echo "partition names \$key => \${mountpoint}" >> /tmp/preseed.log
    eval "partition_percentage=\\${partition_percentage_\$key}"
    echo "partition percentage \$key => \${partition_percentage}" >> /tmp/preseed.log
    eval "partition_size=\\${partition_size_\$key}"
    echo "partition size \$key => \${partition_size}" >> /tmp/preseed.log
    eval "partition_max_size=\\${partition_max_size_\$key}"
    echo "partition max size \$key => \${partition_max_size}" >> /tmp/preseed.log
done


if [ -z "\${default_partition_name}" ]; then
    default_partition_name=root
fi

default_partition_percentage=100
for key in \${partition_names}; do
    if [[ "\$key" == "\${default_partition_name}" ]]; then
        continue
    fi
    if [[ "\$key" == "swap" ]]; then
        continue
    fi
    eval "partition_percentage=\\${partition_percentage_\$key}"
    if [ ! -z "\${partition_percentage}" ]; then
        if [ \${default_partition_percentage} -gt \${partition_percentage} ]; then
            default_partition_percentage=\$((\${default_partition_percentage}-\${partition_percentage}))
        else
            default_partition_percentage=0
        fi
    fi
done
eval "partition_percentage_\${default_partition_name}=\${default_partition_percentage}"

if [ -z "\${partition_point_boot}" ]; then
    partition_point_boot="/boot"
    if [ -z "\${partition_names}" ]; then
        partition_names="boot"
    else
        partition_names="\${partition_names} boot"
    fi
fi

if [ -z "\${partition_size_boot}" ]; then
    partition_size_boot=500
fi

if [ -z "\${partition_maxsize_boot}" ]; then
    partition_maxsize_boot=\$partition_size_boot
fi

if [ -z "\${first_disk}" ]; then
    first_disk=/dev/sda
fi

#if $getVar('keep_old_partitions', '0') != "0"
echo "d-i grub-installer/with_other_os boolean true" >> /tmp/part-include
#else
echo "d-i grub-installer/only_debian boolean true" >> /tmp/part-include
#end if

echo "d-i grub-installer/bootdev string \${first_disk}" >> /tmp/part-include
echo "setup bootloader on disk \${first_disk}" >> /tmp/preseed.log

partition_param_boot="\${partition_fstype} \
\\$primary{ } \\$bootable{ } method{ format } \
format{ } use_filesystem{ } filesystem{ \${partition_fstype} } \
mountpoint{ /boot } device{ \${first_disk} } \
"

if [ -z "\${partition_point_swap}" ]; then
    partition_point_swap="swap"
    if [ -z "\${partition_names}" ]; then
        partition_names="swap"
    else
        partition_names="\${partition_names} swap"
    fi
fi

if [ -z "\${partition_size_swap}" ]; then
    partition_size_swap=256
fi

if [ -z "\${partition_percentage_swap}" ]; then
    partition_percentage_swap=10
fi

if [ -z "\${partition_maxsize_swap}" ]; then
    partition_maxsize_swap=200%
fi

partition_param_swap="linux-swap \
\\$primary{ } method{ swap } format{ } \
device{ \${first_disk} } \
"

if [ -z "\${partition_point_root}" ]; then
    partition_point_root="/"
    if [ -z "\${partition_names}" ]; then
        partition_names="root"
    else
        partition_names="\$partition_names root"
    fi
fi

recipe="boot-root ::"
bios_partition_param="free method{ biosgrub } \
\\$primary{ } device{ \${first_disk} } \
"
recipe="\$recipe 1 1 1 \${bios_partition_param} ."

for key in \${partition_names}; do
    eval "partition=\\${partition_point_\$key}"
    echo "partition \$partition => \$key" >> /tmp/preseed.log
    eval "partition_percentage=\\${partition_percentage_\$key}"
    if [ -z "\${partition_percentage}" ]; then
        partition_percentage=0
    fi
    echo "partition percentage \$partition => \${partition_percentage}" >> /tmp/preseed.log
    eval "partition_size=\\${partition_size_\$key}"
    if [ -z "\${partition_size}" ]; then
        partition_size=1
    fi
    echo "partition size \$partition => \${partition_size}" >> /tmp/preseed.log
    if [ \${partition_percentage} -ne 0 ]; then
        partition_factor="\${partition_size}+\${partition_percentage}%"
    else
        partition_factor="\${partition_size}"
    fi
    echo "partition factor \$partition => \${partition_factor}" >> /tmp/preseed.log
    eval "partition_maxsize=\\${partition_maxsize_\$key}"
    if [ -z \${partition_maxsize} ]; then
        partition_maxsize=-1
    fi
    echo "partition maxsize \$partition => \${partition_maxsize}" >> /tmp/preseed.log
    eval "partition_param=\\${partition_param_\$key}"
    if [ -z "\${partition_param}" ]; then
        partition_param="\${partition_fstype} \
\\$lvmok{ } method{ format } format{ } \
use_filesystem{ } filesystem{ \${partition_fstype} } \
in_vg{ $vgname } lv_name{ \${key}vol } \
mountpoint{ \$partition }"
    fi
    echo "partition param \$partition => \${partition_param}" >> /tmp/preseed.log
    recipe="\$recipe \${partition_size} \${partition_factor} \${partition_maxsize} \${partition_param} ." 
done

for disk in \${sorted_disks}; do
#if $getVar('partition_by_path', '0') != "0"
    path_name=\$(basename \${disk})
    disk_path_name=\$(echo \${path_name} | tr '-' '_' | tr ':' '_' | tr '.' '_')
    eval "path_disk=\\${disk_path_\${disk_path_name}}"
    disk_name=\$(basename \${path_disk})
#else
    disk_name=\$(basename \$disk)
#end if
    eval "used_disk_\${disk_name}=\$disk"
    echo "add disk \$disk into disks" >> /tmp/preseed.log
    eval "max_disk_size=\\${max_disk_size_\${disk_name}}"
    if [ -z "\${max_disk_size}" ]; then
        max_disk_size=\${default_max_disk_size}
    fi
    echo "disk \${disk} max disk size \${max_disk_size}" >> /tmp/preseed.log
    if [ \${max_disk_size} -gt 0 ]; then
         maxsize_param=\${max_disk_size}
    else
        maxsize_param=-1
    fi
    disk_param="\${partition_fstype} \
\\$defaultignore{ } device{ \${disk} } \
method{ lvm } vg_name{ $vgname }"
    recipe="\$recipe 512 512+100% \${maxsize_param} \${disk_param} ."
    echo "partition param \${disk_name} => \${disk_param}" >> /tmp/preseed.log
    eval "reserve_disk_size=\\${reserve_disk_size_\${disk_name}}"
    if [ -z "\${reserve_disk_size}" ]; then
        reserve_disk_size=\${default_reserve_disk_size}
    fi
    echo "disk \${disk} reserve disk size \${reserve_disk_size}" >> /tmp/preseed.log
    if [ \${reserve_disk_size} -gt 0 ]; then
        reserve_disk_param="\${partition_fstype} \
\\$defaultignore{ } device{ \${disk} } \
method{ lvm } vg_name{ reserved }"
        recipe="\$recipe \${reserve_disk_size} \${reserve_disk_size} \${reserve_disk_size} \${reserve_disk_param} ."
	echo "reserve partition param \${disk_name} => \${reserve_disk_param}" >> /tmp/preseed.log
    fi
done


#if $getVar('keep_old_partitions', '0') == "0"
for disk in \$disks; do
#if $getVar('partition_by_path', '0') != "0"
    path_name=\$(basename \${disk})
    disk_path_name=\$(echo \${path_name} | tr '-' '_' | tr ':' '_' | tr '.' '_')
    eval "path_disk=\\${disk_path_\${disk_path_name}}"
    disk_name=\$(basename \${path_disk})
#else
    disk_name=\$(basename \$disk)
#end if
    eval "used_disk=\\${used_disk_\${disk_name}}"
    if [ -z "\${used_disk}" ]; then
        reserve_disk_param="\${partition_fstype} \
\\$defaultignore{ } device{ \${disk} } \
method{ lvm } vg_name{ reserved }"
        recipe="\$recipe 512 512+100% -1 \${reserve_disk_param} ."
	echo "reserve partition param \${disk_name} => \${reserve_disk_param}" >> /tmp/preseed.log
    fi
done
#end if

echo "d-i partman-auto/expert_recipe string \$recipe" >> /tmp/part-include
echo "d-i partman-auto/choose_recipe select boot-root" >> /tmp/part-include
## echo "d-i partman-lvm/vgcreate string $vgname" >> /tmp/part-include
## echo "d-i partman-auto-lvm/new_vg_name string $vgname" >> /tmp/part-include