This file is indexed.

/lib/partman/finish.d/25create_swapfile is in ubiquity 18.04.14.

This file is owned by root:root, with mode 0o755.

The actual contents of the file can be viewed below.

 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
#!/bin/sh

. /lib/partman/lib/base.sh

swap_partition () {
    local swaps dev num id size type fs path name method
    local startdir="$(pwd)"
    swaps=''
    for dev in $DEVICES/*; do
	[ -d $dev ] || continue
	cd $dev
	open_dialog PARTITIONS
	while { read_line num id size type fs path name; [ "$id" ]; }; do
	    [ $fs != free ] || continue
	    [ -f "$id/method" ] || continue
	    method=$(cat $id/method)
	    if [ "$method" = swap ]; then
		    swaps="$swaps $path"
	    fi
	done
	close_dialog
    done
    if [ -n "$swaps" ]; then
        return 0
    else
        return 1
    fi
}

enable_swap () {
    # do swapon only when we will be able to swapoff afterwards
    [ -f /proc/swaps ] || return 0
    if ! grep -q "^$(readlink -f /target/swapfile) " /proc/swaps; then
	    swapon /target/swapfile 2>/dev/null || true
    fi
}

# Check target filesystem, might not support swapfiles...
# Also check if fallocate can be used
rootfstype=$(cat /proc/self/mountinfo | grep '/target' | cut -d\  -f8)
fallocatesupport=false
case $rootfstype in
    ext4)
        fallocatesupport=true
        ;;
    btrfs|zfs)
        # No support for swapfiles
        return 0
        ;;
esac

# No need for swapfile, if a swap partition is created/available
if swap_partition; then
    return 0
fi

# No new swapfile... if there is one already, e.g. reuse/reinstall recipes
if [ -f /target/swapfile ]; then
    enable_swap
    return 0
fi


db_get partman-swapfile/size
max_size=$RET
db_get partman-swapfile/percentage
max_percent=$RET

# Get available space
available=$(busybox df -P /target/ | sed 1d | while read fs size used available usep mounted on; do
	echo $available
done)

# 5% or cap limit
size=$((available/100))
size=$((size*$max_percent))
limit=$((1024*$max_size))
if [ $size -gt $limit ]
then
    size=$limit
fi

# No swapfile if limits are 0MB or 0%
if [ $size = 0 ]
then
    return 0
fi

if type fallocate >/dev/null 2>&1 && $fallocatesupport; then
    log-output -t partman-swapfile --pass-stdout fallocate -l ${size}KiB /target/swapfile
else
    log-output -t partman-swapfile --pass-stdout dd if=/dev/zero of=/target/swapfile bs=1024 count=$size
fi
chmod 600 /target/swapfile
log-output -t partman-swapfile --pass-stdout mkswap /target/swapfile >/dev/null
sync
enable_swap

return 0