2
# If you are curious why partman-auto is so slow, it is because
5
local dev num id size type fs path name partitions
6
for dev in $DEVICES/*; do
7
[ -d "$dev" ] || continue
10
open_dialog PARTITIONS
11
while { read_line num id size type fs path name; [ "$id" ]; }; do
12
partitions="$partitions $id"
15
for id in $partitions; do
16
update_partition $dev $id
21
autopartitioning_failed () {
22
db_input critical partman-auto/autopartitioning_failed || true
31
local ignore ram line word min factor max fs -
32
ignore="${2:+${2}ignore}"
33
unnamed=$(($unnamed + 1))
34
ram=$(grep ^Mem: /proc/meminfo | { read x y z; echo $y; }) # in bytes
35
if [ -z "$ram" ]; then
36
ram=$(grep ^MemTotal: /proc/meminfo | { read x y z; echo $y; })000
38
ram=$(expr 0000000"$ram" : '0*\(..*\)......$') # convert to megabytes
39
name="Unnamed.${unnamed}"
42
for word in $(cat $1); do
49
db_metaget $line description
50
name="${RET:-Unnamed.$unnamed}"
54
# we correct errors in order not to crash parted_server
56
if expr "$1" : '[0-9][0-9]*$' >/dev/null; then
58
elif expr "$1" : '[0-9][0-9]*%$' >/dev/null; then
59
min=$(($ram * ${1%?} / 100))
61
min=2200000000 # there is no so big storage device jet
63
if expr "$2" : '[0-9][0-9]*%$' >/dev/null; then
64
factor=$(($ram * ${2%?} / 100))
65
elif expr "$2" : '[0-9][0-9]*$' >/dev/null; then
68
factor=$min # do not enlarge the partition
70
if [ "$factor" -lt "$min" ]; then
73
if expr "$3" : '[0-9][0-9]*$' >/dev/null; then
75
elif expr "$3" : '[0-9][0-9]*%$' >/dev/null; then
76
max=$(($ram * ${3%?} / 100))
78
max=$min # do not enlarge the partition
80
if [ "$max" -lt "$min" ]; then
83
case "$4" in # allow only valid file systems
84
ext2|ext3|xfs|reiserfs|jfs|linux-swap|fat16|fat32|hfs)
91
shift; shift; shift; shift
92
line="$min $factor $max $fs $*"
94
# Exclude partitions that have ...ignore set
95
if [ "$ignore" ] && [ "$(echo $line | grep "$ignore")" ]; then
98
scheme="${scheme:+$scheme$NL}$line"
103
line="${line:+$line }$word"
109
foreach_partition () {
110
local - doing IFS partition former last
114
for partition in $scheme; do
116
if [ "$former" ]; then
123
if [ "$former" ]; then
134
size=$(($size + $1))'
142
factor=$(($factor + $2))'
146
partition_before () {
147
local num id size type fs path name result found
150
open_dialog PARTITIONS
151
while { read_line num id size type fs path name; [ "$id" ]; }; do
152
if [ "$id" = "$1" ]; then
155
if [ $found = no ]; then
164
local num id size type fs path name result found
167
open_dialog PARTITIONS
168
while { read_line num id size type fs path name; [ "$id" ]; }; do
169
if [ $found = yes -a -z "$result" ]; then
172
if [ "$id" = "$1" ]; then
186
&& echo $* | grep '\''\$primary{'\'' >/dev/null
190
logical="${logical:+$logical$NL}$*"
195
local id flags file line
200
while [ "$1" != '}' -a "$1" ]; do
203
open_dialog GET_FLAGS $id
204
flags=$(read_paragraph)
206
open_dialog SET_FLAGS $id
213
while [ "$1" != '}' -a "$1" ]; do
222
mkdir -p $id/${file%/*}
228
while [ "$1" != '}' -a "$1" ]; do
229
if [ "$1" = ';' ]; then
230
echo "$line" >>$id/$file
232
line="${line:+$line }$1"
236
echo "$line" >>$id/$file
244
local archdetect arch sub recipedir
246
if type archdetect >/dev/null 2>&1; then
247
archdetect=$(archdetect)
249
archdetect=unknown/generic
251
arch=${archdetect%/*}
255
/lib/partman/recipes-$arch-$sub \
256
/lib/partman/recipes-$arch \
259
if [ -d $recipedir ]; then
267
local recipes recipedir free_size choices min_size type target
273
# Preseeding of recipes.
274
db_get partman-auto/expert_recipe
275
if [ -n "$RET" ]; then
276
echo "$RET" > /tmp/expert_recipe
277
db_set partman-auto/expert_recipe_file /tmp/expert_recipe
279
db_get partman-auto/expert_recipe_file
280
if [ ! -z "$RET" ] && [ -e "$RET" ]; then
282
decode_recipe $recipe $type
283
if [ $(min_size) -le $free_size ]; then
286
logger -t partman-auto \
287
"Expert recipe too large ($(min_size) > $free_size); skipping"
291
recipedir=$(get_recipedir)
295
db_get partman-auto/choose_recipe
296
old_default_recipe="$RET"
297
for recipe in $recipedir/*; do
298
[ -f "$recipe" ] || continue
299
decode_recipe $recipe $type
300
if [ $(min_size) -le $free_size ]; then
301
choices="${choices}${recipe}${TAB}${name}${NL}"
302
if [ no = "$default_recipe" ]; then
303
default_recipe="$recipe"
305
if [ "$old_default_recipe" = "$name" ]; then
306
default_recipe="$recipe"
311
if [ -z "$choices" ]; then
312
db_input critical partman-auto/no_recipe || true
313
db_go || true # TODO handle backup right
317
db_subst partman-auto/choose_recipe TARGET "$target"
318
debconf_select high partman-auto/choose_recipe "$choices" "$default_recipe"
319
if [ "$?" = 255 ]; then
326
# Make factors small numbers so we can multiply on them.
327
# Also ensure that fact, max and fs are valid
328
# (Ofcourse in valid recipes they must be valid.)
329
factsum=$(($(factor_sum) - $(min_size)))
330
if [ $factsum -eq 0 ]; then
335
local min fact max fs
337
fact=$((($2 - $min) * 100 / $factsum))
341
ext2|ext3|linux-swap|fat16|fat32|hfs)
348
shift; shift; shift; shift
349
echo $min $fact $max $fs $*'
353
while [ "$scheme" != "$oldscheme" ]; do
355
factsum=$(factor_sum)
356
unallocated=$(($free_size - $(min_size)))
357
if [ $unallocated -lt 0 ]; then
362
local min fact max newmin
367
if [ $factsum -eq 0 ]; then
369
if [ $fact -lt 0 ]; then
373
newmin=$(($min + $unallocated * $fact / $factsum))
375
if [ $newmin -gt $max ]; then
377
elif [ $newmin -lt $min ]; then
380
echo $newmin $fact $max $*
387
for device in $DEVICES/*; do
388
[ -d "$device" ] || continue
390
open_dialog PARTITIONS
391
while { read_line num id size type fs path name; [ "$id" ]; }; do