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 | diff -Nru casper-1.340.1/debian/changelog casper-1.340.2/debian/changelog
--- casper-1.340.1/debian/changelog 2015-07-08 15:42:41.000000000 +0100
+++ casper-1.340.2/debian/changelog 2015-08-04 21:05:35.000000000 +0100
@@ -1,3 +1,12 @@
+casper (1.340.2) wily; urgency=low
+
+ * scripts/casper: migrate existing persistent disk images to the
+ updated upper/work form. Record the actual format used and
+ ensure we use the existing format and abort if not possible.
+ (LP: #1481117)
+
+ -- Andy Whitcroft <apw@canonical.com> Tue, 04 Aug 2015 21:05:34 +0100
+
casper (1.340.1) trusty; urgency=low
* scripts/casper: move union content into a subdirectory of the /cow
diff -Nru casper-1.340.1/scripts/casper casper-1.340.2/scripts/casper
--- casper-1.340.1/scripts/casper 2015-07-08 14:54:12.000000000 +0100
+++ casper-1.340.2/scripts/casper 2015-08-04 20:44:15.000000000 +0100
@@ -375,10 +375,65 @@
return 0
}
+cow_write_format() {
+ {
+ echo "# This records the union filesystem format used for this cow medium; do not delete or alter."
+ echo "UNIONFS=$1"
+ } >"$2"
+}
+
setup_unionfs() {
image_directory="$1"
rootmnt="$2"
+ # Mount up the writable layer, if it is persistent then it may well
+ # tell us what format we should be using.
+ mkdir -p /cow
+ cowdevice="tmpfs"
+ cow_fstype="tmpfs"
+ cow_mountopt="rw,noatime,mode=755"
+
+ # Looking for "${root_persistence}" device or file
+ if [ -n "${PERSISTENT}" ]; then
+ cowprobe=$(find_cow_device "${root_persistence}")
+ if [ -b "${cowprobe}" ]; then
+ cowdevice=${cowprobe}
+ cow_fstype=$(get_fstype "${cowprobe}")
+ cow_mountopt="rw,noatime"
+ else
+ [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
+ fi
+ fi
+
+ mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
+
+ # Work out if this is an existing persistance partition and if so
+ # move its existing "upper" into a new upper directory.
+ if [ ! -d /cow/upper ]; then
+ mkdir -p /cow/upper
+ for cow_content in /cow/*
+ do
+ case "$cow_content" in
+ /cow/lost+found|/cow/upper) continue ;;
+ esac
+
+ mv "$cow_content" /cow/upper
+
+ # We have no format information, so fake some up. If they
+ # have not specified any then we simply assume it was
+ # overlayfs (V1 format).
+ cow_write_format "overlayfs" /cow/format
+ done
+ mkdir -p /cow/work
+ fi
+
+ # Look and see if we have a current format, it is essential we use
+ # a compatible format. Relies on the recovery above having cleaned
+ # out the top level.
+ [ -f /cow/format ] && . /cow/format
+
+ # See if we have the appropriate format, pick the first one if
+ # unspecified.
if [ "${UNIONFS}" = 'DEFAULT' ]; then
for union in 'overlay' 'overlayfs' 'aufs' 'unionfs'
do
@@ -396,6 +451,15 @@
if [ "${UNIONFS}" = 'DEFAULT' ]; then
UNIONFS='aufs'
fi
+ # Confirm the final format was valid.
+ if [ "${UNIONFS}" != "unionfs-fuse" ]; then
+ modprobe "${MP_QUIET}" -b "${UNIONFS}" || true
+ if cut -f2 /proc/filesystems | grep -q "^${UNIONFS}\$"; then
+ :
+ else
+ panic "/cow format specified as ${UNIONFS} and no support found"
+ fi
+ fi
# run-init can't deal with images in a subdir, but we're going to
# move all of these away before it runs anyway. No, we're not,
@@ -443,26 +507,8 @@
done
rofsstring=${rofsstring%:}
- mkdir -p /cow
- cowdevice="tmpfs"
- cow_fstype="tmpfs"
- cow_mountopt="rw,noatime,mode=755"
-
- # Looking for "${root_persistence}" device or file
- if [ -n "${PERSISTENT}" ]; then
- cowprobe=$(find_cow_device "${root_persistence}")
- if [ -b "${cowprobe}" ]; then
- cowdevice=${cowprobe}
- cow_fstype=$(get_fstype "${cowprobe}")
- cow_mountopt="rw,noatime"
- else
- [ "$quiet" != "y" ] && log_warning_msg "Unable to find the persistent medium"
- fi
- fi
-
- mount -t ${cow_fstype} -o ${cow_mountopt} ${cowdevice} /cow || panic "Can not mount $cowdevice on /cow"
- mkdir -p /cow/upper /cow/work
-
+ # Record the format we are using for this mount.
+ [ ! -f /cow/format ] && cow_write_format "${UNIONFS}" /cow/format
case ${UNIONFS} in
unionfs-fuse)
(ulimit -n 16384; unionfs-fuse -o cow -o noinitgroups -o default_permissions -o allow_other -o use_ino -o suid /cow/upper=RW:$rofsstring "$rootmnt" || panic "${UNIONFS} mount failed")
|