Merge ~smoser/cirros:smaller-disks into cirros:master

Proposed by Scott Moser
Status: Merged
Merged at revision: 142e811126b52590ecff1956cff7f6d8f124e3f1
Proposed branch: ~smoser/cirros:smaller-disks
Merge into: cirros:master
Diff against target: 312 lines (+181/-62)
3 files modified
bin/bundle (+3/-2)
src/init (+37/-39)
src/lib/cirros/shlib (+141/-21)
Reviewer Review Type Date Requested Status
cirros developers Pending
Review via email: mp+307961@code.launchpad.net

Description of the change

still some things to clean up here.

To post a comment you must log in.
Revision history for this message
Rafael Folco (rafaelfolco) wrote :

+1 This build worked for me.

$ git log --pretty=oneline -n2
38227329f3685058e7b2b574d258a320f07a8a9c make disk image (disk.img) contain only /boot.
ba0412d1b6c7c658ff3f8265c1af4fd4e3e08867 Add support for Grub2 on Power architectures.

cirros-d161007-ppc64le-rootfs.img.gz: 25174847 --> 16426283 (34%)
cirros-d161007-ppc64le-disk.img: 27143680 --> 17507328 (35%)

I quickly tested it with qemu directly. It boots just fine.

The images were built with: export ARCHES="i386 ppc64le ppc64 powerpc"; ./bin/build-release daily
Fri, 07 Oct 2016 23:06:12 +0000 finished Took 2h 36m 2s. [9362s]

Revision history for this message
Scott Moser (smoser) wrote :

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/bin/bundle b/bin/bundle
2index 6552796..7d801d6 100755
3--- a/bin/bundle
4+++ b/bin/bundle
5@@ -292,8 +292,9 @@ debug 1 "populating image"
6 mount -o loop "${out_partimg}" "${mp}" && UMOUNT=${mp} ||
7 fail "failed to mount ${out_partimg} loopback"
8
9-tar -C "$mp" -xpf - < "$filesys_tar" ||
10- fail "failed to populate mount point"
11+tar -C "$mp" -xpf - vmlinuz initrd.img boot/ < "$kernel_tar" ||
12+ fail "failed to extract kernel_tar"
13+cp "$initramfs" "$mp/boot/initrd.img-${kver}"
14
15 umount "${mp}" && UMOUNT="" ||
16 fail "failed to unmount ${out_partimg}"
17diff --git a/src/init b/src/init
18index 884b0f0..e826f8b 100755
19--- a/src/init
20+++ b/src/init
21@@ -30,17 +30,22 @@ idebug "loading modules"
22 /etc/init.d/load-modules start
23
24 ROOT=""
25-MOUNTED=""
26+NEWROOT_MP=/newroot
27
28-if [ "$KC_RAMDISK_ROOT" != "1" ]; then
29- while read maj min blk name other; do
30- [ -n "${maj}" -a "${maj}" != "major" ] || continue
31- umount=0
32- mount -o ro "/dev/${name}" "/newroot" >/dev/null 2>&1 &&
33- MOUNTED="$MOUNTED ${name}" && umount=1 &&
34- [ -x /newroot/sbin/init ] && ROOT="/dev/$name" && break
35- [ ${umount} -eq 0 ] || umount /newroot
36- done < /proc/partitions
37+rootspec="$KC_ROOT"
38+if [ -z "$rootspec" ]; then
39+ rootspec="LABEL=$ROOTFS_LABEL"
40+ debug 2 "using default root=$rootspec"
41+fi
42+
43+ROOT=""
44+if [ "$KC_RAMDISK_ROOT" = "1" ]; then
45+ ROOT="ramdisk"
46+elif search_for_root "$rootspec" ro "$NEWROOT_MP"; then
47+ debug 2 "mounted root '$rootspec' from dev '${_RET_MCB_DEV}'"
48+ ROOT="${_RET_MCB_DEV}"
49+else
50+ debug 1 "did not find a device matching $rootspec"
51 fi
52
53 if [ "$KC_DEBUG" = "1" ]; then
54@@ -48,44 +53,37 @@ if [ "$KC_DEBUG" = "1" ]; then
55 /bin/sh
56 fi
57
58-if [ -z "$ROOT" -a "$KC_RAMDISK_ROOT" != "1" ] &&
59- blank=$(blkid -l -o device -t LABEL=$ROOTFS_LABEL) &&
60- [ -e "$blank" ]; then
61- iinfo "copying initramfs to $blank"
62- items=""
63- set +f
64- for x in /*; do
65- case "$x" in
66- /dev|/proc|/newroot) : ;;
67- *) items="$items $x";;
68- esac
69- done
70- set -f
71- mount "$blank" /newroot
72- mkdir -p /newroot/dev /newroot/proc
73- cp -a $items /newroot/
74- cp -a /dev/console /newroot/dev
75- mount -o remount,ro /newroot
76- ROOT="$blank"
77+if [ -z "$ROOT" ]; then
78+ if search_for_blank "$rootspec" rw "$NEWROOT_MP"; then
79+ blank="${_RET_MCB_DEV}"
80+ # copy initramfs to new mount.
81+ iinfo "copying initramfs to $blank"
82+ items=""
83+ set +f
84+ for x in /*; do
85+ case "$x" in
86+ /dev|/proc|/newroot) : ;;
87+ *) items="$items $x";;
88+ esac
89+ done
90+ set -f
91+ mkdir -p "${NEWROOT_MP}/dev" "${NEWROOT_MP}/proc"
92+ cp -a $items "${NEWROOT_MP}/"
93+ cp -a "/dev/console" "$NEWROOT_MP/dev/"
94+ mount -o remount,ro "$NEWROOT_MP"
95+ ROOT="$blank"
96+ fi
97 fi
98
99-if [ -n "$ROOT" ]; then
100+if [ -n "$ROOT" -a "$ROOT" != "ramdisk" ]; then
101 cd /newroot
102 mount -o move /dev ./dev
103 umount /proc
104 iinfo "initramfs loading root from $ROOT"
105 exec switch_root /newroot "$KC_INIT" "$@"
106 else
107- while read maj min blk name other; do
108- [ -n "${maj}" -a "${maj}" != "major" ] || continue
109- umount=0
110- mount -o ro "/dev/${name}" "/newroot" >/dev/null 2>&1 &&
111- umount=1 &&
112- [ -x /newroot/sbin/init ] && ROOT="/dev/$name" && break
113- [ ${umount} -eq 0 ] || umount /newroot
114- done < /proc/partitions
115 umount /proc
116- [ "$KC_RAMDISK_ROOT" = "0" ] &&
117+ [ "$ROOT" != "ramdisk" ] &&
118 iinfo "initramfs did not find root, running as ramdisk" ||
119 iinfo "running in ramdisk mode as requested"
120 exec "$KC_INIT" "$@"
121diff --git a/src/lib/cirros/shlib b/src/lib/cirros/shlib
122index 677b903..339254e 100644
123--- a/src/lib/cirros/shlib
124+++ b/src/lib/cirros/shlib
125@@ -101,34 +101,151 @@ debug_connection() {
126 echo "############ debug end ##############"
127 }
128
129-mount_callback_umount() {
130- # dev, opts, callback, args
131- local dev="$1" opts="$2" callback="$3" ret=""
132- local tmpd=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.mp.XXXXXX")
133- mount "$dev" $opts "$tmpd" || {
134+dev_with_info() {
135+ local info="$1" dev=""
136+ dev=$(blkid -l -o device -t "$info") &&
137+ [ -b "$dev" ] && _RET="$dev"
138+ return
139+}
140+
141+check_sbin_init() {
142+ # used as mount_callback callback
143+ debug 1 "check_sbin_init: $*"
144+ local dev="$1" mp="$2"
145+ shift 2
146+ [ -x "$mp/sbin/init" ]
147+}
148+
149+search_for_blank() {
150+ # search_for_root(info, mountpoint)
151+ local info="$1" opts="$2" mp="$3"
152+ mount_callback "$info" "$opts" "$mp" false
153+}
154+
155+search_for_root() {
156+ # search_for_root(info, mountpoint)
157+ local info="$1" opts="$2" mp="$3"
158+ shift 2;
159+ mount_callback "$info" "$opts" "$mp" cbfail check_sbin_init
160+}
161+
162+mount_callback() {
163+ # mount_fs_callback(info, mount_opts, target, umount, callback [args])
164+ # attempt to mount a device with info 'info' with mount_opts
165+ # at target. if target is 'tmp', then create a temp dir.
166+ # on success call callback
167+ # unmount:
168+ # true: unmount
169+ # cbfail: unmount callback returns non-zero
170+ # false: do not unmount
171+ # callback is called like:
172+ # callback <device> <mountpoint> [args]
173+ #
174+ # info can be:
175+ # /* : block device path
176+ # LABEL=* : filesystem with provided label
177+ # UUID=* : filesystem with provided uuid
178+ #
179+ # return value:
180+ # 2: unknown failure
181+ # 3: mount failed
182+ # 4: device not found
183+ # otherwise, return the callback's return code.
184+ local info="$1" mount_opts="$2" target="$3" unmount="${4-true}"
185+ local fail_unknown=2 fail_mount=3 fail_not_found=4
186+ local tmpd="" msg="" mp=""
187+ _RET_MCB_MP=""
188+ _RET_MCB_DEV=""
189+ shift 4;
190+ if [ $# -eq 0 ]; then
191+ set -- :
192+ fi
193+ local callback="$1"
194+ shift
195+ case "$unmount" in
196+ true|false|cbfail) :;;
197+ *)
198+ error "unexpected input for unmount: '$unmount'"
199+ return $fail_unknown
200+ esac
201+ case "$info" in
202+ /*) dev="$info"
203+ [ -b "$dev" ] || return $fail_not_found;;
204+ LABEL=*|UUID=*)
205+ dev_with_info "$info" && dev="$_RET" ||
206+ return $fail_not_found;;
207+ *)
208+ error "unexpected mount info: $info";
209+ return $fail_unknown;;
210+ esac
211+ if [ "$target" = "tmp" ]; then
212+ tmpd=$(mktemp -d "${TMPDIR:-/tmp}/${0##*/}.mp.XXXXXX") ||
213+ return $fail_unknown
214+ debug 2 "mktemp failed"
215+ mp="$tmpd"
216+ else
217+ mp="$target"
218+ fi
219+ case "$mount_opts" in
220+ ro|rw) mount_opts="-o $mount_opts";;
221+ esac
222+ msg="mcb [info=$info dev=$dev target=$target unmount=$unmount callback=$callback]"
223+ debug 1 "$msg: mount '$dev' '$mount_opts' '$mp'"
224+ mount "$dev" $mount_opts "$mp" || {
225 ret=$?;
226- debug 2 "failed mount $dev";
227- rmdir "$tmpd"
228- return $ret;
229+ debug 2 "$msg: failed mount $dev";
230+ if [ -n "$tmpd" ]; then
231+ rmdir "$tmpd"
232+ return $fail_mount;
233+ fi
234 }
235- shift 3;
236- "$callback" "$tmpd" "$@"
237+ "$callback" "$dev" "$mp" "$@"
238 ret=$?
239- umount "$tmpd" || {
240- ret=$?;
241- debug 1 "failed umount $dev";
242- return $ret;
243- }
244- rmdir "$tmpd"
245- return 0
246+ msg="${msg%]} ret=$ret"
247+ if [ "$unmount" = "true" ] ||
248+ [ "$unmount" = "cbfail" -a "$ret" -ne 0 ]; then
249+ umount "$dev" || {
250+ error "$msg: failed to unmount"
251+ return $fail_unknown
252+ }
253+ if [ "$target" = "tmp" ]; then
254+ rmdir "$tmpd" || {
255+ error "$msg: failed rmdir $tmpd"
256+ return $fail_unknown
257+ }
258+ fi
259+ else
260+ [ "$unmount" = "cbfail" ] &&
261+ debug 2 "$msg: not unmounting cbfail=0"
262+ _RET_MCB_MP="$mp"
263+ fi
264+ _RET_MCB_DEV="$dev"
265+ return $ret
266+}
267+
268+mcu_drop_dev_arg() {
269+ # mount_callback_umount called the callbacks with only
270+ # mountpoint, while mount_callback calls dev and mountpoint
271+ # this is used to provide legacy interface.
272+ local dev="$1" mp="$2" fn="$3"
273+ shift 3
274+ debug 1 "mcudda: fn=$fn dev=$dev mp=$mp : $*"
275+ "$fn" "$mp" "$@"
276+}
277+
278+mount_callback_umount() {
279+ # this is legacy-ish wrapper around mount_callback
280+ local dev="$1" opts="$2"
281+ shift 2
282+ mount_callback "$dev" "$opts" tmp true mcu_drop_dev_arg "$@"
283 }
284
285 find_devs_with() {
286 # return a list of devices that match filter
287 # where filter is like:
288- # TYPE=<filesystem>
289- # LABEL=<label>
290- # UUID=<uuid>
291+ # TYPE=<filesystem>
292+ # LABEL=<label>
293+ # UUID=<uuid>
294 local filter="$1"
295 local out rc ret=""
296 out=$(blkid "-t$filter" "-odevice" 2>/dev/null)
297@@ -229,11 +346,14 @@ parse_cmdline() {
298 init) KC_INIT="$val";;
299 debug-initramfs) KC_DEBUG_INITRAMFS=1;;
300 verbose) KC_VERBOSE=1;;
301+ verbose=*) KC_VERBOSE=${tok#verbose=};;
302 esac
303 done
304
305 case "$KC_ROOT" in
306- [Nn][Oo][Nn][Ee]|ramdisk) KC_RAMDISK_ROOT=1;;
307+ [Nn][Oo][Nn][Ee]|ramdisk)
308+ KC_RAMDISK_ROOT=1;
309+ KC_ROOT="ramdisk";;
310 esac
311
312 # set KC_PREF_CONSOLE to the last writable console

Subscribers

People subscribed via source and target branches