3
. /lib/partman/lib/base.sh
4
. /lib/partman/lib/resize.sh
5
. /lib/partman/lib/recipes.sh
7
# busybox wants mount -o move; util-linux wants mount --move. Sigh.
8
if [ -d /lib/debian-installer ]; then
14
modprobe loop >/dev/null 2>&1 || true
16
# Set up working directory.
18
if type mktemp >/dev/null 2>&1; then
19
recipe_dir="$(mktemp -d /tmp/partman-auto-loop.XXXXXX)"
20
trap "rm -rf $recipe_dir" EXIT HUP INT QUIT TERM
31
if ! db_get partman-auto-loop/partition || [ -z "$RET" ]; then
32
logger -t partman-auto-loop "Error: No partition number specified in partman-auto-loop/partition"
37
if ! db_get partman-auto-loop/recipe || [ -z "$RET" ]; then
38
logger -t partman-auto-loop "Error: No recipe specified in partman-auto-loop/recipe"
42
echo "$recipe" >"$recipe_dir/loop_recipe"
44
# Find the requested partition.
46
db_progress START 0 5 partman-auto/text/automatically_partition
47
db_progress INFO partman-auto/progress/info
51
open_dialog PARTITIONS
52
while { read_line num id size type fs path name; [ "$id" ]; }; do
53
if [ "$num" = "$partition" ]; then
56
# go ahead and read all remaining input
60
if [ -z "$partition_id" ]; then
61
logger -t partman-auto-loop "Error: Partition number $partition not found in $disk"
65
# Set up the requested partition in partman.
69
for i in /lib/partman/valid_filesystems/*; do
71
$i $disk $partition_id existing
74
if [ "$j" = "$partition_fs" ]; then
79
if [ "$existing" = no ]; then
80
logger -t partman-auto-loop "Error: No filesystem on $disk/$partition_id"
84
echo keep >$partition_id/method
85
rm -f $partition_id/format
86
>$partition_id/use_filesystem
87
echo $partition_fs >$partition_id/filesystem
88
mkdir -p $partition_id/options
89
echo / >$partition_id/mountpoint
90
update_partition $disk $partition_id
92
# Is there enough space to perform the recipe?
100
for word in $(cat "$recipe_dir/loop_recipe"); do
103
recipe_new="${recipe_new:+$recipe_new }\$imagepath{ $firstword } $word"
107
if [ "$firstword" ]; then
108
recipe_new="${recipe_new:+$recipe_new }$word"
111
imagepaths="${imagepaths:+$imagepaths }$word"
116
echo "$recipe_new" >"$recipe_dir/loop_recipe_new"
117
decode_recipe "$recipe_dir/loop_recipe_new" loop
122
for i in /lib/partman/fstab.d/*; do
123
[ -x "$i" ] || continue
126
while read fs mp type options dump pass; do
129
echo $fs $mp $type $options $dump $pass
135
if [ -z "$fstab" ]; then
136
logger -t partman-auto-loop "Error: No fstab output for $disk/$partition_id"
142
mountpoint="$(grep "^${fstab%% *} [^ ]* [^ ]* [^ ]*rw" /proc/mounts | cut -d ' ' -f2 | head -n1)" || mountpoint=
143
if [ "$mountpoint" = /target ]; then
146
elif [ "$mountpoint" ]; then
147
if ! mount $mount_move "$mountpoint" /target; then
148
logger -t partman-auto-loop "Error: Failed to move $mountpoint to /target"
151
unmount_cmd='umount /target'
153
for m in /lib/partman/mount.d/*; do
154
[ -x "$m" ] || continue
156
unmount_cmd="$($m "$fstab")"
157
if [ "$?" = 0 ]; then
163
mkdir -p /run/sendsigs.omit.d
164
pidof mount.ntfs >> /run/sendsigs.omit.d/ntfs-3g
165
pidof mount.ntfs-3g >> /run/sendsigs.omit.d/ntfs-3g
168
# TODO: handle errors if no mount succeeded
170
mount $mount_move /target /host # TODO error handling
172
# Don't try to mount this again later.
173
rm -f $partition_id/mountpoint
175
# Ensure there is enough free space.
176
check_free_space=false
177
requires_disk_space(){
178
[ "$1" != 0 ] || return
179
path="$(echo "$*" | sed 's/.*\$imagepath{ *\([^ }]*\) *}.*/\1/')"
180
[ "$path" != "$*" ] || return
185
[ -f "/host$path" ] && return
186
check_free_space=true
188
foreach_partition 'requires_disk_space $*'
190
# Skip resize_range check if images are already created.
191
if [ $check_free_space = true ]; then
192
case $partition_fs in
193
linux-swap|fat16|fat32|hfs|hfs+|hfsx)
197
if ! search-path tune2fs; then
198
logger -t partman-auto-loop "Error: tune2fs not found"
201
if ! search-path resize2fs; then
202
logger -t partman-auto-loop "Error: resize2fs not found"
205
if ! get_ext2_resize_range; then
206
logger -t partman-auto-loop "Error: Failed to get ext2 resize range for $disk/$partition_id"
211
if ! search-path ntfsresize; then
212
logger -t partman-auto-loop "Error: ntfsresize not found"
215
if ! get_ntfs_resize_range; then
216
db_input critical partman-auto-loop/unclean_ntfs || true
218
logger -t partman-auto-loop "Error: Failed to get NTFS resize range for $disk/$partition_id"
224
logger -t partman-auto-loop "Cannot calculate free space on filesystems of type $partition_fs"
228
free_size="$(expr \( "$cursize" - "$minsize" \) \* 9 / 10)"
229
# convert to megabytes
230
free_size="$(expr 0000000"$free_size" : '0*\(..*\)......$')"
231
if [ $(min_size) -gt $free_size ]; then
232
logger -t partman-auto-loop "Error: partman-auto-loop/recipe too large ($(min_size) > $free_size)"
237
# Ensure that no old loop images are present and mountable.
239
mkdir -p /tmpmountpoint
240
for path in $imagepaths; do
245
if [ -e "/host$path" ]; then
246
if mount -t auto -o loop,ro /host$path /tmpmountpoint 2>/dev/null 3>&-; then
247
found_images="${found_images:+$found_images }$path"
248
umount /tmpmountpoint || true
249
rmdir /tmpmountpoint || true
253
if [ "$found_images" ]; then
255
db_subst partman-auto-loop/unclean_host PARTITION "$partition"
256
db_subst partman-auto-loop/unclean_host DISK "$disk"
257
db_subst partman-auto-loop/unclean_host IMAGES "$found_images"
258
db_input critical partman-auto-loop/unclean_host || true
277
[ "$1" != 0 ] || return
278
path="$(echo "$*" | sed 's/.*\$imagepath{ *\([^ }]*\) *}.*/\1/')"
279
[ "$path" != "$*" ] || return
285
if [ ! -f "/host$path" ]; then
286
mkdir -p "/host${path%/*}"
287
if [ "$4" = "linux-swap" ]; then
288
# swap requires a file with no holes
289
dd if=/dev/zero of="/host$path" bs="1000000" count="$1"
291
dd if=/dev/zero of="/host$path" bs="1000000" seek="$1" count=0
294
if ! losetup -f "/host$path"; then
298
if [ "$4" = linux-swap ]; then
301
loops="$(echo /dev/loop* /dev/loop/*)"
303
for loop in $loops; do
304
[ -e "$loop" ] || continue
307
loopfile="$(losetup "$loop")" || continue
308
# The following works with both busybox's
309
# losetup and util-linux's losetup. Yes,
311
loopfile="$(echo "$loopfile" | sed 's,.*\(/host/[^)]*\).*,\1,')"
317
[ "$loopfile" = "/host$path" ] || continue
319
dirname="$(echo "$loop" | sed 's:/:=:g')"
320
dev="$DEVICES/$dirname"
323
mkdir "$dev" || autopartitioning_failed
324
printf "%s" "$loop" >"$dev/device"
325
printf "%s" "$1" >"$dev/size"
326
echo "Loopback on $loopfile" >"$dev/model"
327
echo "$loopfile" >"$dev/loop"
330
open_dialog OPEN "$(cat "$dev/device")"
333
if [ "$response" = failed ]; then
336
autopartitioning_failed
339
open_dialog NEW_LABEL loop
342
# find the free space
343
open_dialog PARTITIONS
345
while { read_line num id size type fs path name; [ "$id" ]; }; do
346
if [ "$fs" = free ]; then
353
# create partition in the free space
354
[ "$free_space" ] || autopartitioning_failed
355
open_dialog NEW_PARTITION primary $4 $free_space full ${1}000001
356
read_line num id size type fs path name
359
shift; shift; shift; shift
360
setup_partition $id $*
365
foreach_partition 'setup_loop $*'
371
apt-install lupin-support