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 | diff -Nru initramfs-tools-ubuntu-core-0.7.7/debian/changelog initramfs-tools-ubuntu-core-0.7.8/debian/changelog
--- initramfs-tools-ubuntu-core-0.7.7/debian/changelog 2015-07-08 00:38:27.000000000 +0200
+++ initramfs-tools-ubuntu-core-0.7.8/debian/changelog 2015-08-20 17:32:04.000000000 +0200
@@ -1,3 +1,17 @@
+initramfs-tools-ubuntu-core (0.7.8) wily; urgency=medium
+
+ * add hook to copy sfdisk and resize2fs in place
+ * add "resize" local-premount script to resize the writable
+ partition to full disk size if the free space on the writable media
+ is more than 10%. keeps a log in /run/initramfs/resize-writable.log
+ * drop creation of already existing /run/initramfs dir in ubuntu-core-rootfs
+ else all former logs get wiped in that dir, /init creates it as one of
+ the very first steps.
+ * add dependency on realpath and coreutils, since we use binaries from both
+ in the resize script
+
+ -- Oliver Grawert <ogra@ubuntu.com> Thu, 20 Aug 2015 11:05:56 +0200
+
initramfs-tools-ubuntu-core (0.7.7) wily; urgency=medium
* Also use wait-for-root when mounting other critical partitions
diff -Nru initramfs-tools-ubuntu-core-0.7.7/debian/control initramfs-tools-ubuntu-core-0.7.8/debian/control
--- initramfs-tools-ubuntu-core-0.7.7/debian/control 2015-04-13 22:29:49.000000000 +0200
+++ initramfs-tools-ubuntu-core-0.7.8/debian/control 2015-08-20 14:30:50.000000000 +0200
@@ -9,7 +9,7 @@
Package: initramfs-tools-ubuntu-core
Architecture: all
Depends: initramfs-tools, ubuntu-core-config, ${misc:Depends},
- gnupg, xz-utils
+ gnupg, xz-utils, realpath, coreutils
Description: Tools for making a read-only Ubuntu Core image selectively writeable
This package contains the scripts to make a read-only Ubuntu Core image
selectively writeable. These scripts are run within the initramfs.
diff -Nru initramfs-tools-ubuntu-core-0.7.7/hooks/resize initramfs-tools-ubuntu-core-0.7.8/hooks/resize
--- initramfs-tools-ubuntu-core-0.7.7/hooks/resize 1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-ubuntu-core-0.7.8/hooks/resize 2015-08-20 15:04:52.000000000 +0200
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+set -e
+
+PREREQ=""
+
+# Output pre-requisites
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case "$1" in
+ prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+. /usr/share/initramfs-tools/hook-functions
+
+copy_exec /sbin/sfdisk /sbin
+copy_exec /sbin/resize2fs /sbin
+copy_exec /sbin/blockdev /sbin
+copy_exec /usr/bin/realpath
+copy_exec /usr/bin/dirname
diff -Nru initramfs-tools-ubuntu-core-0.7.7/scripts/local-premount/resize initramfs-tools-ubuntu-core-0.7.8/scripts/local-premount/resize
--- initramfs-tools-ubuntu-core-0.7.7/scripts/local-premount/resize 1970-01-01 01:00:00.000000000 +0100
+++ initramfs-tools-ubuntu-core-0.7.8/scripts/local-premount/resize 2015-08-20 17:30:34.000000000 +0200
@@ -0,0 +1,48 @@
+#!/bin/sh -e
+# initramfs local-premount script for resizing writable
+
+PREREQ=""
+
+# Output pre-requisites
+prereqs()
+{
+ echo "$PREREQ"
+}
+
+case "$1" in
+ prereqs)
+ prereqs
+ exit 0
+ ;;
+esac
+
+wait-for-root "LABEL=writable" "${ROOTDELAY:-180}" >/dev/null || true
+
+writable_part="$(findfs LABEL=writable)"
+
+logfile="/run/initramfs/resize-writable.log"
+
+syspath="$(dirname $(realpath /sys/class/block/$(basename $writable_part)))"
+device="$(realpath /dev/block/$(cat $syspath/dev))"
+partition=$(cat $syspath/$(basename $writable_part)/partition)
+
+device_size="$(($(cat $syspath/size)/2))"
+sum_size="$(($(grep $(basename $device)[a-z0-9] /proc/partitions|\
+ tr -s ' '|cut -d' ' -f4|tr '\n' '+'|sed 's/+$//')))"
+
+free_space=$(($device_size-$sum_size))
+min_free_space=$(($device_size/10))
+
+if [ "$min_free_space" -lt "$free_space" ]; then
+ echo "initrd: found more than 10% free space on disk, resizing ${writable_part}" >/dev/kmsg || true
+ echo "initrd: partition to full disk size, see ${logfile} for details" >/dev/kmsg || true
+ # grow our selected partition to max space available
+ echo ", +"|/sbin/sfdisk -N $partition $device >>$logfile 2>&1
+ # make sure we re read the partition table in any case
+ /sbin/blockdev --rereadpt $device >>$logfile 2>&1
+ # check the filesystem before attempting re-size
+ /sbin/e2fsck -fy $writable_part >>$logfile 2>&1
+ # resize the filesystem to full size of the partition
+ /sbin/resize2fs -f $writable_part >>$logfile 2>&1
+fi
+
diff -Nru initramfs-tools-ubuntu-core-0.7.7/scripts/ubuntu-core-rootfs initramfs-tools-ubuntu-core-0.7.8/scripts/ubuntu-core-rootfs
--- initramfs-tools-ubuntu-core-0.7.7/scripts/ubuntu-core-rootfs 2015-07-08 00:38:12.000000000 +0200
+++ initramfs-tools-ubuntu-core-0.7.8/scripts/ubuntu-core-rootfs 2015-08-20 17:25:46.000000000 +0200
@@ -208,7 +208,6 @@
# Mount the writable partition to a temporary mount point
# (to allow it to be move-mounted on top of the read-only root).
- mkdir -p "/run/initramfs" || true
logfile="/run/initramfs/fsck-${writable_label}"
echo "initrd: checking filesystem for ${writable_label} partition" >/dev/kmsg || true
|