Status: | Needs review |
---|---|
Proposed branch: | lp:~rafaelfolco/cirros/cirros |
Merge into: | lp:cirros |
Diff against target: |
1072 lines (+1046/-0) (has conflicts) 5 files modified
bin/build-release.OTHER (+265/-0) bin/bundle.OTHER (+348/-0) bin/grab-grub-ieee (+100/-0) bin/part2disk.OTHER (+284/-0) doc/README-powerpc.txt.OTHER (+49/-0) Conflict adding files to bin. Created directory. Conflict because bin is not versioned, but has versioned children. Versioned directory. Contents conflict in bin/build-release Contents conflict in bin/bundle Contents conflict in bin/part2disk Conflict adding files to doc. Created directory. Conflict because doc is not versioned, but has versioned children. Versioned directory. Contents conflict in doc/README-powerpc.txt |
To merge this branch: | bzr merge lp:~rafaelfolco/cirros/cirros |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Scott Moser | Pending | ||
Review via email: mp+306211@code.launchpad.net |
Commit message
Description of the change
Add support for Grub2 on Power architectures.
Power bootable qcow2 images require Grub to be installed on a PreP Boot partition. This patch enables CirrOS to boot from Grub2/PreP.
To post a comment you must log in.
Unmerged revisions
- 381. By Rafael Folco
-
Code polishing and Minor fixes
- 380. By Rafael Folco
-
Download first, build br-source first arch
- 379. By Rafael Folco
-
Add Grub2 support to Power
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === added directory 'bin' | |||
2 | === added file 'bin/build-release.OTHER' | |||
3 | --- bin/build-release.OTHER 1970-01-01 00:00:00 +0000 | |||
4 | +++ bin/build-release.OTHER 2016-09-20 12:52:40 +0000 | |||
5 | @@ -0,0 +1,265 @@ | |||
6 | 1 | #!/bin/bash | ||
7 | 2 | # | ||
8 | 3 | # Authors: Scott Moser <smoser@canonical.com> | ||
9 | 4 | # Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> | ||
10 | 5 | # Rafael Folco <rfolco@br.ibm.com> | ||
11 | 6 | # | ||
12 | 7 | # This program is free software: you can redistribute it and/or modify | ||
13 | 8 | # it under the terms of the GNU General Public License as published by | ||
14 | 9 | # the Free Software Foundation, version 3 of the License. | ||
15 | 10 | # | ||
16 | 11 | # This program is distributed in the hope that it will be useful, | ||
17 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
19 | 14 | # GNU General Public License for more details. | ||
20 | 15 | # | ||
21 | 16 | # You should have received a copy of the GNU General Public License | ||
22 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
23 | 18 | |||
24 | 19 | [ $# -ge 1 ] || { echo "must give version"; exit 1; } | ||
25 | 20 | |||
26 | 21 | source "${0%/*}/common-functions.sh" | ||
27 | 22 | |||
28 | 23 | VER=$1 | ||
29 | 24 | daily=false | ||
30 | 25 | if [ "$1" = "daily" ]; then | ||
31 | 26 | VER="d$(date +%y%m%d)" | ||
32 | 27 | daily=true | ||
33 | 28 | fi | ||
34 | 29 | shift | ||
35 | 30 | pre=cirros-$VER | ||
36 | 31 | BR_VER="2015.05" | ||
37 | 32 | ARCHES="${ARCHES:-i386 x86_64 arm powerpc aarch64 ppc64 ppc64le}" | ||
38 | 33 | KVER="4.4.0-28.47" # Ubuntu 16.04 | ||
39 | 34 | GVER="2.02~beta2-36ubuntu8" | ||
40 | 35 | ME=$(readlink -f "$0") | ||
41 | 36 | MY_D=${ME%/*} | ||
42 | 37 | PATH=${MY_D}:$PATH | ||
43 | 38 | |||
44 | 39 | set -e | ||
45 | 40 | set -o pipefail | ||
46 | 41 | |||
47 | 42 | OUT="$PWD/../build-$VER" | ||
48 | 43 | LOGFILE="$OUT/date.txt" | ||
49 | 44 | export TMPDIR="$OUT/tmp" | ||
50 | 45 | mkdir -p "$OUT" "$TMPDIR" | ||
51 | 46 | |||
52 | 47 | msg() { | ||
53 | 48 | echo "$@" >> "$LOGFILE" | ||
54 | 49 | echo "$@" | ||
55 | 50 | } | ||
56 | 51 | logevent() { | ||
57 | 52 | # logevent(msg, [from]) | ||
58 | 53 | # log the message in $1 and time since $2, defaulting to last call. | ||
59 | 54 | local up delta msg="$1" ref="$2" human="" | ||
60 | 55 | up=${SECONDS} | ||
61 | 56 | if [ "$ref" = "-" ]; then | ||
62 | 57 | ref="" | ||
63 | 58 | elif [ "$ref" = "" ]; then | ||
64 | 59 | ref="${_LAST_UP}" | ||
65 | 60 | fi | ||
66 | 61 | if [ -n "$ref" ]; then | ||
67 | 62 | delta="$(($up-$ref))" | ||
68 | 63 | sec2human "$delta" tshort && human=${_RET} | ||
69 | 64 | fi | ||
70 | 65 | msg "$(date -R)" "$msg" "${delta:+Took ${human}. [${delta}s]}" | ||
71 | 66 | _LAST_UP=$up | ||
72 | 67 | _RET=${_LAST_UP} | ||
73 | 68 | } | ||
74 | 69 | |||
75 | 70 | build_arch() { | ||
76 | 71 | local arch="" quiet=false cmd="" log="" | ||
77 | 72 | if [ "$1" = "quiet" ]; then | ||
78 | 73 | quiet=true | ||
79 | 74 | shift | ||
80 | 75 | fi | ||
81 | 76 | arch="$1" | ||
82 | 77 | log="${OUT}/build-$arch.log" | ||
83 | 78 | cmd=( make ARCH=$arch "OUT_D=$OUT/build/$arch" | ||
84 | 79 | ${CCACHE_D:+"BR2_CCACHE_DIR=${CCACHE_D}/$arch"} ) | ||
85 | 80 | |||
86 | 81 | logevent "start $arch" - | ||
87 | 82 | if $quiet; then | ||
88 | 83 | error "building $arch into $log" | ||
89 | 84 | time "${cmd[@]}" > "$log" 2>&1 | ||
90 | 85 | else | ||
91 | 86 | time "${cmd[@]}" 2>&1 | tee "$log" | ||
92 | 87 | fi | ||
93 | 88 | ret=$? | ||
94 | 89 | logevent "finish $arch [ret=$ret]" | ||
95 | 90 | return $ret | ||
96 | 91 | } | ||
97 | 92 | |||
98 | 93 | get_grub_format() { | ||
99 | 94 | local arch=$1 | ||
100 | 95 | case "$arch" in | ||
101 | 96 | powerpc|ppc*) format=ieee;; | ||
102 | 97 | *) format=efi;; | ||
103 | 98 | esac | ||
104 | 99 | echo $format | ||
105 | 100 | } | ||
106 | 101 | |||
107 | 102 | get_img_size() { | ||
108 | 103 | local arch=$1 | ||
109 | 104 | case "$arch" in | ||
110 | 105 | powerpc|ppc*|aarch64) size=96M;; | ||
111 | 106 | *) size="";; | ||
112 | 107 | esac | ||
113 | 108 | echo $size | ||
114 | 109 | } | ||
115 | 110 | |||
116 | 111 | if [ "$1" = "build_arch" ]; then | ||
117 | 112 | shift | ||
118 | 113 | build_arch "$@" | ||
119 | 114 | exit | ||
120 | 115 | elif [ $# -gt 1 ]; then | ||
121 | 116 | fail "confused by $# arguments: $*" | ||
122 | 117 | fi | ||
123 | 118 | |||
124 | 119 | # really just here to check that VER is a tag | ||
125 | 120 | # or source code checkout would fail | ||
126 | 121 | if ! $daily; then | ||
127 | 122 | revno=$(bzr tags -r "tag:$VER") || fail "$VER: not a tag in $PWD." | ||
128 | 123 | revno=$(echo "$revno" | awk '{print $2}') | ||
129 | 124 | fi | ||
130 | 125 | |||
131 | 126 | logevent "begin" - | ||
132 | 127 | tstart=${_RET} | ||
133 | 128 | |||
134 | 129 | logevent "start download" - | ||
135 | 130 | rm -f download | ||
136 | 131 | mkdir -p ../download | ||
137 | 132 | ln -snf ../download download | ||
138 | 133 | brtgz="buildroot-${BR_VER}.tar.gz" | ||
139 | 134 | dl "http://buildroot.uclibc.org/downloads/$brtgz" "download/$brtgz" | ||
140 | 135 | logevent "end download" | ||
141 | 136 | |||
142 | 137 | logevent "start unpack" - | ||
143 | 138 | rm -Rf "buildroot-${BR_VER}" | ||
144 | 139 | rm -f buildroot | ||
145 | 140 | tar -xvf download/buildroot-${BR_VER}.tar.gz | ||
146 | 141 | ln -snf buildroot-${BR_VER} buildroot | ||
147 | 142 | |||
148 | 143 | # we do not do this here, so that we're not dependent on the | ||
149 | 144 | # cvs working (which wont work through http_proxy) and also | ||
150 | 145 | # to have revision controlled information in that file. | ||
151 | 146 | #./bin/mkcabundle > src/etc/ssl/certs/ca-certificates.crt | ||
152 | 147 | |||
153 | 148 | ( cd buildroot && QUILT_PATCHES="$PWD/../patches-buildroot" quilt push -a ) | ||
154 | 149 | |||
155 | 150 | echo "$VER" > "src/etc/cirros/version" | ||
156 | 151 | logevent "end unpack" | ||
157 | 152 | |||
158 | 153 | # Stage 1: DOWNLOAD | ||
159 | 154 | logevent "start br-source" - | ||
160 | 155 | make ARCH=${ARCHES%% *} br-source | ||
161 | 156 | logevent "end br-source" | ||
162 | 157 | |||
163 | 158 | for arch in ${ARCHES}; do | ||
164 | 159 | format=$(get_grub_format "$arch") | ||
165 | 160 | mkdir -p "$OUT/stage/$arch" | ||
166 | 161 | |||
167 | 162 | # grab kernel | ||
168 | 163 | logevent "start kernel download" - | ||
169 | 164 | grab-kernels "$KVER" $arch | ||
170 | 165 | logevent "end kernel download" | ||
171 | 166 | |||
172 | 167 | # grab grub | ||
173 | 168 | logevent "start grub $arch-$format download" - | ||
174 | 169 | grab-grub-${format} "$GVER" $arch | ||
175 | 170 | logevent "end grub $arch-$format download" | ||
176 | 171 | done | ||
177 | 172 | |||
178 | 173 | # STAGE 2: BUILD | ||
179 | 174 | jobs_flag="" | ||
180 | 175 | parallel=true | ||
181 | 176 | case "${CIRROS_PARALLEL:-none}" in | ||
182 | 177 | none) parallel=false;; | ||
183 | 178 | 0|true) :;; | ||
184 | 179 | [0-9]|[0-9][0-9]) jobs_flag="--jobs=${CIRROS_PARALLEL}";; | ||
185 | 180 | auto) command -v parallel >/dev/null || parallel=false;; | ||
186 | 181 | *) fail "unknown value for CIRROS_PARALLEL=$CIRROS_PARALLEL";; | ||
187 | 182 | esac | ||
188 | 183 | |||
189 | 184 | if $parallel; then | ||
190 | 185 | parallel --ungroup ${jobs_flag} \ | ||
191 | 186 | "$0" "$VER" build_arch quiet {} ::: ${ARCHES} | ||
192 | 187 | else | ||
193 | 188 | for arch in ${ARCHES}; do | ||
194 | 189 | build_arch "$arch" | ||
195 | 190 | done; | ||
196 | 191 | fi | ||
197 | 192 | |||
198 | 193 | # STAGE 3: BUNDLE | ||
199 | 194 | for arch in ${ARCHES}; do | ||
200 | 195 | # bundle rootfs, kernel & grub | ||
201 | 196 | format=$(get_grub_format "$arch") | ||
202 | 197 | size=$(get_img_size "$arch") | ||
203 | 198 | logevent "start bundling $arch" - | ||
204 | 199 | sudo ./bin/bundle -v ${size:+--size=$size} --arch="$arch" \ | ||
205 | 200 | "$OUT/build/$arch/rootfs.tar" \ | ||
206 | 201 | ./download/kernel-$arch.tar.gz ./download/grub-${format}-$arch.tar.gz \ | ||
207 | 202 | "$OUT/stage/$arch"; | ||
208 | 203 | logevent "finish bundling $arch" | ||
209 | 204 | done | ||
210 | 205 | |||
211 | 206 | sudo chown -R $USER:$USER "$OUT/stage" | ||
212 | 207 | |||
213 | 208 | mkdir -p "$OUT/release" | ||
214 | 209 | |||
215 | 210 | #srctgz="$OUT/release/cirros-$VER-source.tar.gz" | ||
216 | 211 | #bzr export -r "tag:$VER" --format=tgz --root="cirros-$VER" "$srctgz" | ||
217 | 212 | #echo "wrote source tgz: $srctgz" | ||
218 | 213 | if ! $daily; then | ||
219 | 214 | ( srcd="$PWD" && tmpd=$(mktemp -d) && cd "$tmpd" && | ||
220 | 215 | bzr branch "$srcd" -r tag:$VER cirros-$VER && | ||
221 | 216 | rm -Rf cirros-$VER/.bzr && | ||
222 | 217 | echo "$VER" > "cirros-$VER/src/etc/cirros/version" && | ||
223 | 218 | tar cvzf - cirros-$VER ) > "$OUT/release/cirros-$VER-source.tar.gz" | ||
224 | 219 | fi | ||
225 | 220 | |||
226 | 221 | rm -f "$OUT/stage"/*/"$pre"* | ||
227 | 222 | for arch in ${ARCHES}; do | ||
228 | 223 | p=$pre-$arch | ||
229 | 224 | ( cd "$OUT/stage/$arch" && | ||
230 | 225 | ln kernel $p-vmlinuz && ln kernel $p-kernel && | ||
231 | 226 | ln initramfs $p-initrd && ln initramfs $p-initramfs && | ||
232 | 227 | ln part.img $p-rootfs.img && | ||
233 | 228 | ln blank.img $p-blank.img && | ||
234 | 229 | ln disk.img $p-disk.img && | ||
235 | 230 | ln filesys.tar.gz $p-lxc.tar.gz && | ||
236 | 231 | true | ||
237 | 232 | ); | ||
238 | 233 | done | ||
239 | 234 | |||
240 | 235 | logevent "start populating release" - | ||
241 | 236 | for arch in ${ARCHES}; do | ||
242 | 237 | p=$pre-$arch | ||
243 | 238 | ( cd "$OUT/stage/$arch" && | ||
244 | 239 | cp $p-kernel $p-initramfs $p-lxc.tar.gz "$OUT/release/" && | ||
245 | 240 | gzip -9 -c $p-rootfs.img > $OUT/release/$p-rootfs.img.gz ) && | ||
246 | 241 | ( cd "$OUT/stage/$arch" && | ||
247 | 242 | tar cvzf - $p-blank.img $p-vmlinuz $p-initrd | ||
248 | 243 | ) > "$OUT/release/$p-uec.tar.gz" | ||
249 | 244 | cp "$OUT/stage/$arch/$p-disk.img" "$OUT/release/$p-disk.img" | ||
250 | 245 | done | ||
251 | 246 | |||
252 | 247 | mkdir -p "$OUT/release/buildroot_rootfs" | ||
253 | 248 | for arch in ${ARCHES}; do | ||
254 | 249 | t="$OUT/release/buildroot_rootfs/buildroot-$VER-$arch.tar" | ||
255 | 250 | cp "$OUT/build/$arch/rootfs.tar" "$t" | ||
256 | 251 | gzip --force -9 "$t" | ||
257 | 252 | done | ||
258 | 253 | |||
259 | 254 | chmod u+rwX,go+rX -R "$OUT/release/"* | ||
260 | 255 | |||
261 | 256 | sumfiles=$(cd "$OUT/release" && for f in *; do | ||
262 | 257 | [ -f "$f" -a "$f" != MD5SUMS ] && echo "$f"; done) | ||
263 | 258 | ( cd "$OUT/release" && md5sum $sumfiles > MD5SUMS ) | ||
264 | 259 | |||
265 | 260 | logevent "finish populate release" - | ||
266 | 261 | msg "output in $OUT/release" | ||
267 | 262 | msg "entire process took $SECONDS seconds" | ||
268 | 263 | logevent "finished" "$tstart" | ||
269 | 264 | |||
270 | 265 | # vi: tabstop=4 expandtab | ||
271 | 0 | 266 | ||
272 | === added file 'bin/bundle.OTHER' | |||
273 | --- bin/bundle.OTHER 1970-01-01 00:00:00 +0000 | |||
274 | +++ bin/bundle.OTHER 2016-09-20 12:52:40 +0000 | |||
275 | @@ -0,0 +1,348 @@ | |||
276 | 1 | #!/bin/bash | ||
277 | 2 | # | ||
278 | 3 | # Authors: Scott Moser <smoser@canonical.com> | ||
279 | 4 | # Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> | ||
280 | 5 | # Rafael Folco <rfolco@br.ibm.com> | ||
281 | 6 | # | ||
282 | 7 | # This program is free software: you can redistribute it and/or modify | ||
283 | 8 | # it under the terms of the GNU General Public License as published by | ||
284 | 9 | # the Free Software Foundation, version 3 of the License. | ||
285 | 10 | # | ||
286 | 11 | # This program is distributed in the hope that it will be useful, | ||
287 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
288 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
289 | 14 | # GNU General Public License for more details. | ||
290 | 15 | # | ||
291 | 16 | # You should have received a copy of the GNU General Public License | ||
292 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
293 | 18 | # | ||
294 | 19 | |||
295 | 20 | source "${0%/*}/common-functions.sh" | ||
296 | 21 | |||
297 | 22 | TEMP_D="" | ||
298 | 23 | UMOUNT="" | ||
299 | 24 | DEF_SIZE=${DEF_SIZE:-32M} | ||
300 | 25 | DEF_MODULES="acpiphp e1000 ne2k-pci 8139cp pcnet32 ip_tables" | ||
301 | 26 | |||
302 | 27 | Usage() { | ||
303 | 28 | cat <<EOF | ||
304 | 29 | Usage: ${0##*/} rootfs.tar kpkg.deb output_dir | ||
305 | 30 | [re]Bundle a buildroot rootfs into a mini-cloud image | ||
306 | 31 | |||
307 | 32 | options: | ||
308 | 33 | -s | --size S resize image to size (default: ${DEF_SIZE}) | ||
309 | 34 | --arch A prepare for arch A | ||
310 | 35 | |||
311 | 36 | Example: | ||
312 | 37 | ${0##*/} rootfs.tar linux-image-*-virtuaal*.deb build-output/ | ||
313 | 38 | EOF | ||
314 | 39 | } | ||
315 | 40 | cleanup() { | ||
316 | 41 | [ -z "${UMOUNT}" ] || umount "${UMOUNT}" | ||
317 | 42 | [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}" | ||
318 | 43 | } | ||
319 | 44 | xrsync() { | ||
320 | 45 | rsync --archive --xattrs --hard-links --acls --sparse "$@" | ||
321 | 46 | } | ||
322 | 47 | |||
323 | 48 | short_opts="hs:v" | ||
324 | 49 | long_opts="arch:,initrd-busybox:,help,size:,verbose" | ||
325 | 50 | getopt_out=$(getopt --name "${0##*/}" \ | ||
326 | 51 | --options "${short_opts}" --long "${long_opts}" -- "$@") && | ||
327 | 52 | eval set -- "${getopt_out}" || | ||
328 | 53 | bad_Usage | ||
329 | 54 | |||
330 | 55 | topdir=$(cd "${0%/*}/.." && pwd) | ||
331 | 56 | size=${DEF_SIZE} | ||
332 | 57 | FS_LABEL="cirros-rootfs" | ||
333 | 58 | fs_type="ext3" | ||
334 | 59 | arch="" | ||
335 | 60 | |||
336 | 61 | while [ $# -ne 0 ]; do | ||
337 | 62 | cur=${1}; next=${2}; | ||
338 | 63 | case "$cur" in | ||
339 | 64 | -h|--help) Usage; exit 0;; | ||
340 | 65 | -s|--size) size=${next}; shift;; | ||
341 | 66 | --arch) arch=${next}; shift;; | ||
342 | 67 | -v|--verbose) DEBUG=$((${DEBUG}+1));; | ||
343 | 68 | --) shift; break;; | ||
344 | 69 | esac | ||
345 | 70 | shift; | ||
346 | 71 | done | ||
347 | 72 | |||
348 | 73 | [ $# -eq 4 ] || bad_Usage "must give rootfs.tar, kernel pkg, grub-{efi|ieee}.tar, out_dir" | ||
349 | 74 | rootfs_in=${1} | ||
350 | 75 | kpkg_in=${2} | ||
351 | 76 | grub_in=${3} | ||
352 | 77 | out_d_in=${4} | ||
353 | 78 | |||
354 | 79 | PATH="$topdir/bin:$PATH" | ||
355 | 80 | src_dir="${topdir}/src" | ||
356 | 81 | src_symlinks="${topdir}/symlinks.list" | ||
357 | 82 | makedevs_list="${topdir}/makedevs.list" | ||
358 | 83 | fixup_fs="${topdir}/fixup-fs" | ||
359 | 84 | xgrubd="$topdir/grubd" | ||
360 | 85 | |||
361 | 86 | [ "$(id -u)" = "0" ] || fail "sorry... must be root" | ||
362 | 87 | |||
363 | 88 | [ -d "${src_dir}" ] || fail "no source dir ${src_d}" | ||
364 | 89 | |||
365 | 90 | TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") || | ||
366 | 91 | fail "failed to make tempd" | ||
367 | 92 | trap cleanup EXIT | ||
368 | 93 | |||
369 | 94 | mkdir -p "${out_d_in}" && out_d=$(readlink -f "${out_d_in}") && | ||
370 | 95 | rootfs=$(readlink -f "${rootfs_in}") && | ||
371 | 96 | kpkg=$(readlink -f "${kpkg_in}") || | ||
372 | 97 | fail "failed to get full path for input" | ||
373 | 98 | |||
374 | 99 | out_partimg="${out_d}/part.img" | ||
375 | 100 | out_diskimg="${out_d}/disk.img" | ||
376 | 101 | out_kernel="${out_d}/kernel" | ||
377 | 102 | out_initramfs="${out_d}/initramfs" | ||
378 | 103 | out_diskimg="${out_d}/disk.img" | ||
379 | 104 | out_blankimg="${out_d}/blank.img" | ||
380 | 105 | out_filesys_lxc="${out_d}/filesys.tar.gz" | ||
381 | 106 | inter_d="$out_d/intermediate" | ||
382 | 107 | |||
383 | 108 | mp="${TEMP_D}/mnt" | ||
384 | 109 | kernel_d="${TEMP_D}/kernel" | ||
385 | 110 | kern_list_full="${TEMP_D}/kernel.files.full" | ||
386 | 111 | kern_files="${TEMP_D}/kernel.files" | ||
387 | 112 | kern_modules="${TEMP_D}/kernel.files.modules" | ||
388 | 113 | overlay_d="${TEMP_D}/overlay" | ||
389 | 114 | initramfs_d="${TEMP_D}/initramfs" | ||
390 | 115 | initramfs="${TEMP_D}/initramfs.img" | ||
391 | 116 | stage_d="$TEMP_D/staging" | ||
392 | 117 | |||
393 | 118 | kernel_tar="$inter_d/kernel.tar" | ||
394 | 119 | overlay_tar="$inter_d/overlay.tar" | ||
395 | 120 | filesys_tar="$inter_d/filesys.tar" | ||
396 | 121 | |||
397 | 122 | modfile="$src_dir/etc/modules" | ||
398 | 123 | if [ -f "$modfile" ]; then | ||
399 | 124 | MODULES=$("$src_dir/etc/init.d/load-modules" parse_modules \ | ||
400 | 125 | "$modfile" "$arch") || | ||
401 | 126 | fail "failed to read modules" | ||
402 | 127 | MODULES=$(echo "$MODULES" | sed 's, .*,,' | tr '\n' ' ') | ||
403 | 128 | else | ||
404 | 129 | MODULES=${DEF_MODULES} | ||
405 | 130 | fi | ||
406 | 131 | debug 1 "modules: $MODULES" | ||
407 | 132 | |||
408 | 133 | prepare-grub "$xgrubd" || | ||
409 | 134 | fail "failed to get grub binary" | ||
410 | 135 | |||
411 | 136 | mkdir -p "${mp}" "${kernel_d}" "${overlay_d}" \ | ||
412 | 137 | "${initramfs_d}" "$inter_d" "$stage_d" || | ||
413 | 138 | fail "failed to make temp dirs" | ||
414 | 139 | |||
415 | 140 | debug 1 "creating filesystem in ${out_partimg}" | ||
416 | 141 | rm -f "$out_partimg" | ||
417 | 142 | truncate "--size=${size}" "${out_partimg}" || | ||
418 | 143 | fail "failed to create ${out_partimg} of size ${size}" | ||
419 | 144 | |||
420 | 145 | out=$("mkfs.${fs_type}" -F "${out_partimg}" -L "${FS_LABEL}" 2>&1) || | ||
421 | 146 | fail "failed to make filesystem of type ${fs_type}: ${out}" | ||
422 | 147 | |||
423 | 148 | cp "$out_partimg" "$out_blankimg" || | ||
424 | 149 | fail "failed to to copy blank partition image" | ||
425 | 150 | |||
426 | 151 | debug 1 "preparing kernel overlay" | ||
427 | 152 | # creating kernel tarball | ||
428 | 153 | case "$kpkg_in" in | ||
429 | 154 | *.deb) | ||
430 | 155 | dpkg -x "${kpkg_in}" "${kernel_d}" || | ||
431 | 156 | fail "failed extracting kernel deb package in ${kpkg_in}" | ||
432 | 157 | ;; | ||
433 | 158 | *.tar*) | ||
434 | 159 | tar -C "$kernel_d" -xf "$kpkg_in" || | ||
435 | 160 | fail "failed extracting kernel tarball in ${kpkg_in}" | ||
436 | 161 | ;; | ||
437 | 162 | *) fail "unknown file format for $kpkg_in";; | ||
438 | 163 | esac | ||
439 | 164 | |||
440 | 165 | ( cd "${kernel_d}" && find * -type f ) > "${kern_list_full}" || | ||
441 | 166 | fail "failed to extract kernel to ${kernel_d}" | ||
442 | 167 | |||
443 | 168 | kver="" | ||
444 | 169 | for x in "$kernel_d/lib/modules"/*; do | ||
445 | 170 | [ -d "$x/kernel" ] || continue | ||
446 | 171 | [ -z "$kver" ] || | ||
447 | 172 | fail "2 or more things looked like kernels in lib/modules of $kpkg_in" | ||
448 | 173 | kver="${x##*/}" | ||
449 | 174 | done | ||
450 | 175 | [ -n "$kver" ] || | ||
451 | 176 | fail "failed to find kernel version. no lib/modules/* ?" | ||
452 | 177 | |||
453 | 178 | depmod -a --basedir "${kernel_d}" "${kver}" || | ||
454 | 179 | fail "failed to run depmod" | ||
455 | 180 | |||
456 | 181 | mdep="${kernel_d}/lib/modules/${kver}/modules.dep" | ||
457 | 182 | for x in ${MODULES}; do | ||
458 | 183 | grep -q "/${x}.ko" "${mdep}" || | ||
459 | 184 | { error "WARNING: no ${x} in kernel package!"; continue; } | ||
460 | 185 | awk -F: '$1 ~ mat { | ||
461 | 186 | sub(":","",$1) | ||
462 | 187 | printf("%s/%s\n",p,$1) | ||
463 | 188 | leng=split($0,deps," ") | ||
464 | 189 | x=2 # strange, but 0 contains nothing, 1 contains first field (with :) | ||
465 | 190 | while ( x<=leng ) { | ||
466 | 191 | printf("%s/%s\n", p, deps[x]); | ||
467 | 192 | x++ | ||
468 | 193 | } | ||
469 | 194 | }' mat="/${x}.ko$" p="lib/modules/${kver}" "${mdep}" | ||
470 | 195 | done > "${kern_modules}" | ||
471 | 196 | sort -u "${kern_modules}" > "${kern_files}" | ||
472 | 197 | vmlinuz=$( cd "${kernel_d}" && [ -f boot/vmlinu?-* ] && | ||
473 | 198 | echo boot/vmlinu?-* ) && echo "${vmlinuz}" >> "${kern_files}" && | ||
474 | 199 | ln -sf "$vmlinuz" "$kernel_d/vmlinuz" && echo "vmlinuz" >> "$kern_files" || | ||
475 | 200 | fail "no kernel (boot/vmlinuz-*) found in ${kpkg_in}" | ||
476 | 201 | echo "boot/config-$kver" >> "$kern_files" | ||
477 | 202 | |||
478 | 203 | tar -C "${kernel_d}" -cpf - \ | ||
479 | 204 | --files-from "${kern_files}" > "${kernel_tar}" || | ||
480 | 205 | fail "failed to collect kernel files" | ||
481 | 206 | |||
482 | 207 | debug 1 "preparing source overlay from ${src_dir}" | ||
483 | 208 | xrsync "${src_dir}/" "${overlay_d}" || | ||
484 | 209 | fail "failed to copy source dir" | ||
485 | 210 | |||
486 | 211 | chown -R 0:0 "${overlay_d}" || fail "failed to chown files in overlay" | ||
487 | 212 | |||
488 | 213 | if [ -f "${src_symlinks}" ]; then | ||
489 | 214 | ( cd "${overlay_d}" && | ||
490 | 215 | while read src target; do | ||
491 | 216 | { [ -d "${target%/*}" ] || mkdir -p "${target%/*}"; } || | ||
492 | 217 | { error "could not create ${target%/*}"; exit 1; } | ||
493 | 218 | ln -sf "${src}" "${target}" || exit 1 | ||
494 | 219 | done < "${src_symlinks}" | ||
495 | 220 | ) || fail "failed to create symlinks" | ||
496 | 221 | fi | ||
497 | 222 | if [ -f "${makedevs_list}" ]; then | ||
498 | 223 | xmakedevs "$makedevs_list" "$overlay_d" || | ||
499 | 224 | fail "failed to makedevs on overlay" | ||
500 | 225 | fi | ||
501 | 226 | |||
502 | 227 | ( cd "$overlay_d" && tar -cpf - * ) > "$overlay_tar" || | ||
503 | 228 | fail "failed to make overlay_tar" | ||
504 | 229 | |||
505 | 230 | debug 1 "populating staging directory" | ||
506 | 231 | tar -C "$stage_d" -xpf - < "$rootfs_in" || | ||
507 | 232 | fail "failed to extract rootfs_tar" | ||
508 | 233 | tar -C "$stage_d" -xpf - < "$overlay_tar" || | ||
509 | 234 | fail "failed to extract overlay_tar" | ||
510 | 235 | |||
511 | 236 | if [ -x "${fixup_fs}" ]; then | ||
512 | 237 | "${fixup_fs}" "${stage_d}" || | ||
513 | 238 | fail "failed to fixup filesystem" | ||
514 | 239 | fi | ||
515 | 240 | |||
516 | 241 | ( cd "$stage_d" && tar -Scpzf - -- * ) > "$out_filesys_lxc" || | ||
517 | 242 | fail "failed to create filesys tarball" | ||
518 | 243 | |||
519 | 244 | tar -C "$stage_d" -xpf - < "$kernel_tar" || | ||
520 | 245 | fail "failed to extract kernel_tar" | ||
521 | 246 | tar -C "$stage_d" -xpf - < "$xgrubd/bootgrub.tar" || | ||
522 | 247 | fail "failed to extract bootgrub" | ||
523 | 248 | |||
524 | 249 | depmod -a --basedir "$stage_d" "${kver}" || | ||
525 | 250 | fail "failed to run depmod for kver ${kver} in output" | ||
526 | 251 | |||
527 | 252 | debug 1 "creating initramfs" | ||
528 | 253 | xrsync "$stage_d/" "$initramfs_d" || | ||
529 | 254 | fail "failed to copy to initramfs_d" | ||
530 | 255 | rm -Rf "$initramfs_d/vmlinuz" "$initramfs_d/boot" || | ||
531 | 256 | fail "failed to remove files in initramfs staging dir" | ||
532 | 257 | |||
533 | 258 | ( cd "$initramfs_d" && find . | cpio --quiet -o -H newc | | ||
534 | 259 | gzip -9 ) > "$initramfs" | ||
535 | 260 | |||
536 | 261 | # Here we create /boot/initrd.img-${kver}. | ||
537 | 262 | # That is the initramfs that is put inside of disk images. | ||
538 | 263 | # Since the disk images have all the modules available in the | ||
539 | 264 | # filesystem, we put no modules in this initramfs. Having them | ||
540 | 265 | # in both places would just waste space. | ||
541 | 266 | # | ||
542 | 267 | # That means that the kernel must have builtin drivers for | ||
543 | 268 | # any block devices. Another path to accomplishing the same | ||
544 | 269 | # space savings is what cloud-initramfs-copymods does. | ||
545 | 270 | # The solution there is that if there is no /lib/modules/<kver> | ||
546 | 271 | # inside the target filesystem, then the initramfs mount binds | ||
547 | 272 | # its /lib/modules/<kver> into the target. | ||
548 | 273 | rm -Rf "$initramfs_d/lib/modules/$kver" || | ||
549 | 274 | fail "failed to remove lib/modules for mini initramfs" | ||
550 | 275 | |||
551 | 276 | ( cd "$initramfs_d" && find . | cpio --quiet -o -H newc | | ||
552 | 277 | gzip -9 ) > "${initramfs}.smaller" | ||
553 | 278 | |||
554 | 279 | cp "${initramfs}.smaller" "$stage_d/boot/initrd.img-${kver}" && | ||
555 | 280 | ln -s "boot/initrd.img-${kver}" "${stage_d}/initrd.img" || | ||
556 | 281 | fail "failed to copy initramfs to stage dir" | ||
557 | 282 | |||
558 | 283 | debug 1 "packing clean kernel_tar" | ||
559 | 284 | tar -C "$stage_d" -cpf - \ | ||
560 | 285 | vmlinuz initrd.img boot/ lib/modules/ > "$kernel_tar" || | ||
561 | 286 | fail "failed to create clean kerne_tar" | ||
562 | 287 | |||
563 | 288 | ( cd "$stage_d" && tar -cpf - * ) > "$filesys_tar" || | ||
564 | 289 | fail "failed to create filesys_tar" | ||
565 | 290 | |||
566 | 291 | debug 1 "populating image" | ||
567 | 292 | mount -o loop "${out_partimg}" "${mp}" && UMOUNT=${mp} || | ||
568 | 293 | fail "failed to mount ${out_partimg} loopback" | ||
569 | 294 | |||
570 | 295 | tar -C "$mp" -xpf - < "$filesys_tar" || | ||
571 | 296 | fail "failed to populate mount point" | ||
572 | 297 | |||
573 | 298 | umount "${mp}" && UMOUNT="" || | ||
574 | 299 | fail "failed to unmount ${out_partimg}" | ||
575 | 300 | |||
576 | 301 | cp "${kernel_d}/${vmlinuz}" "${out_kernel}" || | ||
577 | 302 | fail "failed to copy kernel to ${out_kernel}" | ||
578 | 303 | |||
579 | 304 | { [ -z "${out_initramfs}" ] || cp "${initramfs}" "${out_initramfs}"; } || | ||
580 | 305 | fail "failed to copy initramfs to ${out_initramfs}" | ||
581 | 306 | |||
582 | 307 | debug 1 "fixing grub entry in partimg" | ||
583 | 308 | tmp_part="$TEMP_D/part.img.disk" | ||
584 | 309 | cp "$out_partimg" "$tmp_part" && | ||
585 | 310 | mount -o loop "$tmp_part" "$mp" && UMOUNT="$mp" || | ||
586 | 311 | fail "failed to mount $tmp_part" | ||
587 | 312 | sed -i 's/(hd0)/(hd0,0)/' "$mp/boot/grub/menu.lst" || | ||
588 | 313 | fail "failed to edit /boot/grub/menu.lst in image" | ||
589 | 314 | umount "$mp" && UMOUNT="" || | ||
590 | 315 | fail "failed to unmount partimg" | ||
591 | 316 | |||
592 | 317 | case $arch in | ||
593 | 318 | i386|x86_64) grub_options="--grub1 --grub-efi";; | ||
594 | 319 | arm|aarch64) grub_options="--grub-efi";; | ||
595 | 320 | powerpc|ppc*) grub_options="--grub-ieee";; | ||
596 | 321 | *) grub_options=;; | ||
597 | 322 | esac | ||
598 | 323 | |||
599 | 324 | debug 1 "creating disk image" | ||
600 | 325 | out=$(PATH=$xgrubd:$PATH part2disk $grub_options "$tmp_part" \ | ||
601 | 326 | "$grub_in" "$arch" "$out_diskimg.raw" 2>&1) || | ||
602 | 327 | fail "failed to create disk image: $out" | ||
603 | 328 | qemu-img convert -O qcow2 -c "$out_diskimg.raw" "$out_diskimg" || | ||
604 | 329 | fail "failed to convert disk image" | ||
605 | 330 | rm -f "$out_diskimg.raw" "$tmp_part" | ||
606 | 331 | |||
607 | 332 | if [ -n "${SUDO_USER}" ]; then | ||
608 | 333 | u=${SUDO_USER} | ||
609 | 334 | g=$(id -g "${u}") || g=${u} | ||
610 | 335 | chown "${u}:${g}" -R "$out_d" || | ||
611 | 336 | fail "failed to grant ownership of ${u}:${g} to ${u}:${g}" | ||
612 | 337 | fi | ||
613 | 338 | |||
614 | 339 | echo "wrote ${out_partimg}" | ||
615 | 340 | echo "wrote ${out_diskimg}" | ||
616 | 341 | echo "wrote ${out_kernel}" | ||
617 | 342 | echo "wrote ${out_initramfs}" | ||
618 | 343 | echo "wrote ${out_blankimg}" | ||
619 | 344 | echo "wrote ${out_filesys_lxc}" | ||
620 | 345 | |||
621 | 346 | exit 0 | ||
622 | 347 | |||
623 | 348 | # vi: tabstop=4 expandtab | ||
624 | 0 | 349 | ||
625 | === added file 'bin/grab-grub-ieee' | |||
626 | --- bin/grab-grub-ieee 1970-01-01 00:00:00 +0000 | |||
627 | +++ bin/grab-grub-ieee 2016-09-20 12:52:40 +0000 | |||
628 | @@ -0,0 +1,100 @@ | |||
629 | 1 | #!/bin/bash | ||
630 | 2 | # | ||
631 | 3 | # Copyright (C) 2016 IBM Corp. | ||
632 | 4 | # | ||
633 | 5 | # Author: Rafael Folco <rfolco@br.ibm.com> | ||
634 | 6 | # | ||
635 | 7 | # This program is free software: you can redistribute it and/or modify | ||
636 | 8 | # it under the terms of the GNU General Public License as published by | ||
637 | 9 | # the Free Software Foundation, version 3 of the License. | ||
638 | 10 | # | ||
639 | 11 | # This program is distributed in the hope that it will be useful, | ||
640 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
641 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
642 | 14 | # GNU General Public License for more details. | ||
643 | 15 | # | ||
644 | 16 | # You should have received a copy of the GNU General Public License | ||
645 | 17 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
646 | 18 | # | ||
647 | 19 | |||
648 | 20 | source "${0%/*}/common-functions.sh" | ||
649 | 21 | |||
650 | 22 | burl="https://launchpad.net/ubuntu/+archive/primary/+files/" | ||
651 | 23 | outdir="./download" | ||
652 | 24 | def_arches="ppc64le powerpc ppc64" | ||
653 | 25 | |||
654 | 26 | [ "$1" = "--outdir" ] && { outdir="$1" && shift; } | ||
655 | 27 | gver="$1" | ||
656 | 28 | shift | ||
657 | 29 | |||
658 | 30 | if [ $# -eq 0 ]; then | ||
659 | 31 | set -- ${def_arches} | ||
660 | 32 | fi | ||
661 | 33 | |||
662 | 34 | [ -d "$outdir" ] || mkdir -p "$outdir" || | ||
663 | 35 | fail "failed mkdir $outdir" | ||
664 | 36 | |||
665 | 37 | [ -n "$gver" ] || fail "must give grub version" | ||
666 | 38 | |||
667 | 39 | deb2tar() { | ||
668 | 40 | |||
669 | 41 | local deb="$1" tar="$2" | ||
670 | 42 | |||
671 | 43 | t=$(dirname "$deb") | ||
672 | 44 | tdir=$(mktemp -d "$t/.XXXXXX") || return | ||
673 | 45 | |||
674 | 46 | debug 1 "creating $out in tempdir at $tdir" | ||
675 | 47 | |||
676 | 48 | mkdir -p "$tdir/deb" | ||
677 | 49 | dpkg -x "$deb" "$tdir/deb" || fail "failed to unpack $deb" | ||
678 | 50 | |||
679 | 51 | gbin="grub" | ||
680 | 52 | gmod="boot cat configfile echo ext2 halt loadenv minicmd normal part_gpt | ||
681 | 53 | reboot search search_fs_uuid search_fs_file search_label serial sleep | ||
682 | 54 | test linux" | ||
683 | 55 | |||
684 | 56 | debug 2 "grub-mkimage: creating grub powerpc-ieee1275 image" | ||
685 | 57 | grub-mkimage --directory "${tdir}/deb/usr/lib/grub/powerpc-ieee1275" \ | ||
686 | 58 | --prefix "(ieee1275/disk,gpt1)/boot/grub" \ | ||
687 | 59 | --output "$tdir/${gbin}" \ | ||
688 | 60 | --format "powerpc-ieee1275" \ | ||
689 | 61 | --compression "none" $gmod | ||
690 | 62 | |||
691 | 63 | rm -rf "$tdir/deb" | ||
692 | 64 | debug 2 "creating grub.tar.gz" | ||
693 | 65 | tar -C "$tdir/" -czf "$tdir/grub.tar.gz" $gbin && | ||
694 | 66 | mv "$tdir/grub.tar.gz" "$tar" || { | ||
695 | 67 | error "failed creating tarball"; | ||
696 | 68 | rm -Rf "$tdir" | ||
697 | 69 | return 1; | ||
698 | 70 | } | ||
699 | 71 | rm -Rf "$tdir" | ||
700 | 72 | return 0 | ||
701 | 73 | |||
702 | 74 | } | ||
703 | 75 | |||
704 | 76 | for arch in "$@"; do | ||
705 | 77 | case "$arch" in | ||
706 | 78 | ppc64le) | ||
707 | 79 | debarch='ppc64el' | ||
708 | 80 | ;; | ||
709 | 81 | powerpc|ppc64) | ||
710 | 82 | debarch='powerpc' | ||
711 | 83 | ;; | ||
712 | 84 | *) debug 1 "no grub-ieee1275 for $arch";; | ||
713 | 85 | esac | ||
714 | 86 | |||
715 | 87 | # e.g. https://launchpad.net/ubuntu/+archive/primary/+files/grub-ieee1275-bin_2.02~beta2-36ubuntu8_ppc64el.deb | ||
716 | 88 | deb="grub-ieee1275-bin_${gver}_${debarch}.deb" | ||
717 | 89 | if [ ! -f "${outdir}/${deb}" ]; then | ||
718 | 90 | dl $burl/$deb "$outdir/$deb" || fail "failed dl $burl/$deb" | ||
719 | 91 | fi | ||
720 | 92 | tar="grub-ieee-${gver}-${arch}.tar.gz" | ||
721 | 93 | deb2tar "$outdir/$deb" "$outdir/$tar" || | ||
722 | 94 | fail "failed deb2tar from $deb to $tar" | ||
723 | 95 | |||
724 | 96 | error "wrote $outdir/${tar}" | ||
725 | 97 | ln -sf "${tar}" "$outdir/grub-ieee-${arch}.tar.gz" || | ||
726 | 98 | fail "failed symlink for $outdir/grub-ieee-${arch}.tar.gz" | ||
727 | 99 | done | ||
728 | 100 | # vi: ts=4 expandtab | ||
729 | 0 | 101 | ||
730 | === added file 'bin/part2disk.OTHER' | |||
731 | --- bin/part2disk.OTHER 1970-01-01 00:00:00 +0000 | |||
732 | +++ bin/part2disk.OTHER 2016-09-20 12:52:40 +0000 | |||
733 | @@ -0,0 +1,284 @@ | |||
734 | 1 | #!/bin/bash | ||
735 | 2 | # part2disk - wrap a partition image in a disk image | ||
736 | 3 | # | ||
737 | 4 | # Copyright (C) 2010 Canonical Ltd. | ||
738 | 5 | # | ||
739 | 6 | # Authors: Scott Moser <smoser@canonical.com> | ||
740 | 7 | # Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org> | ||
741 | 8 | # Rafael Folco <rfolco@br.ibm.com> | ||
742 | 9 | # | ||
743 | 10 | # This program is free software: you can redistribute it and/or modify | ||
744 | 11 | # it under the terms of the GNU General Public License as published by | ||
745 | 12 | # the Free Software Foundation, version 3 of the License. | ||
746 | 13 | # | ||
747 | 14 | # This program is distributed in the hope that it will be useful, | ||
748 | 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
749 | 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
750 | 17 | # GNU General Public License for more details. | ||
751 | 18 | # | ||
752 | 19 | # You should have received a copy of the GNU General Public License | ||
753 | 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
754 | 21 | |||
755 | 22 | source "${0%/*}/common-functions.sh" | ||
756 | 23 | |||
757 | 24 | DEF_SECTOR_SIZE=512 | ||
758 | 25 | base_d=$(dirname $(readlink -f "${0}")) | ||
759 | 26 | PATH="${PATH}:${base_d}" | ||
760 | 27 | |||
761 | 28 | getsize() { | ||
762 | 29 | local fname="$1" kname="" size="" | ||
763 | 30 | if [ -b "${fname}" ]; then | ||
764 | 31 | kname=$(readlink -f "${fname}") && | ||
765 | 32 | size=$(awk '$4 == kn { print $3 * 1024 }' \ | ||
766 | 33 | "kn=${kname##*/}" /proc/partitions) && | ||
767 | 34 | [ -n "${size}" ] || { | ||
768 | 35 | error "failed to read size of ${fname} from /proc/partitions"; | ||
769 | 36 | return 1; | ||
770 | 37 | } | ||
771 | 38 | else | ||
772 | 39 | size=$(stat --format "%s" "${fname}") || { | ||
773 | 40 | error "failed to get size of ${fname}" | ||
774 | 41 | return 1; | ||
775 | 42 | } | ||
776 | 43 | fi | ||
777 | 44 | _RET="$size" | ||
778 | 45 | } | ||
779 | 46 | |||
780 | 47 | Usage() { | ||
781 | 48 | cat <<EOF | ||
782 | 49 | Usage: ${0##*/} [options] partition-image grub-{efi|ieee}-tarball architecture disk-image | ||
783 | 50 | |||
784 | 51 | Create disk image 'disk-image' with 'partition-image' in a partition | ||
785 | 52 | inside it. Add grub if requested. | ||
786 | 53 | |||
787 | 54 | options: | ||
788 | 55 | -G | --grub install grub to disk image mbr | ||
789 | 56 | | --grub1 install grub1 to disk image mbr | ||
790 | 57 | | --grub-efi install EFI grub to disk image | ||
791 | 58 | | --grub-ieee install ieee1275 grub to disk image prep partition | ||
792 | 59 | -s | --size S create the disk image of size 'S'. | ||
793 | 60 | default is large enough to fit partition-image | ||
794 | 61 | -v | --verbose increase verbosity | ||
795 | 62 | EOF | ||
796 | 63 | } | ||
797 | 64 | human2bytes() { | ||
798 | 65 | # converts size suitable for input to resize2fs to bytes | ||
799 | 66 | # s:512 byte sectors, K:kilobytes, M:megabytes, G:gigabytes | ||
800 | 67 | # none: block size of the image | ||
801 | 68 | local input=${1} defunit=${2:-1024} | ||
802 | 69 | local unit count; | ||
803 | 70 | case "$input" in | ||
804 | 71 | *s) count=${input%s}; unit=512;; | ||
805 | 72 | *K) count=${input%K}; unit=1024;; | ||
806 | 73 | *M) count=${input%M}; unit=$((1024*1024));; | ||
807 | 74 | *G) count=${input%G}; unit=$((1024*1024*1024));; | ||
808 | 75 | *) count=${input} ; unit=${2:-1024};; | ||
809 | 76 | esac | ||
810 | 77 | _RET=$((${count}*${unit})) | ||
811 | 78 | } | ||
812 | 79 | |||
813 | 80 | cleanup() { | ||
814 | 81 | umount "$TMP/efi" | ||
815 | 82 | umount "$TMP/rootfs" | ||
816 | 83 | kpartx -d "$dimg" | ||
817 | 84 | } | ||
818 | 85 | |||
819 | 86 | trap cleanup EXIT | ||
820 | 87 | |||
821 | 88 | short_opts="b:c:Ghs:v" | ||
822 | 89 | long_opts="grub-ieee,grub-efi,grub1,grub,help,size:,verbose" | ||
823 | 90 | getopt_out=$(getopt --name "${0##*/}" \ | ||
824 | 91 | --options "${short_opts}" --long "${long_opts}" -- "$@") && | ||
825 | 92 | eval set -- "${getopt_out}" || | ||
826 | 93 | bad_Usage | ||
827 | 94 | |||
828 | 95 | ssize=${DEF_SECTOR_SIZE} | ||
829 | 96 | size_in="" | ||
830 | 97 | grub_ptnum=1 | ||
831 | 98 | grub=0 | ||
832 | 99 | grub1=0 | ||
833 | 100 | grub_efi=0 | ||
834 | 101 | grub_ieee=0 | ||
835 | 102 | while [ $# -ne 0 ]; do | ||
836 | 103 | cur=${1}; next=${2}; | ||
837 | 104 | case "$cur" in | ||
838 | 105 | -G|--grub) | ||
839 | 106 | grub=1 | ||
840 | 107 | ;; | ||
841 | 108 | -G|--grub1) | ||
842 | 109 | grub1=1 | ||
843 | 110 | ;; | ||
844 | 111 | --grub-efi) | ||
845 | 112 | grub_efi=1 | ||
846 | 113 | ptype="ef00" # EFI System | ||
847 | 114 | ;; | ||
848 | 115 | --grub-ieee) | ||
849 | 116 | grub_ieee=1 | ||
850 | 117 | ptype="4100" # PowerPC PreP Boot | ||
851 | 118 | ;; | ||
852 | 119 | -h|--help) Usage; exit 0;; | ||
853 | 120 | -s|--size) size_in=$2; shift;; | ||
854 | 121 | -v|--verbose) DEBUG=$((${DEBUG}+1));; | ||
855 | 122 | --) shift; break;; | ||
856 | 123 | esac | ||
857 | 124 | shift; | ||
858 | 125 | done | ||
859 | 126 | |||
860 | 127 | [ $# -eq 4 ] || bad_Usage "must supply partition image, grub-{efi|ieee} tarball, architecture and output file" | ||
861 | 128 | |||
862 | 129 | pimg=${1} | ||
863 | 130 | grub_in=${2} | ||
864 | 131 | arch=${3} | ||
865 | 132 | dimg=${4} | ||
866 | 133 | |||
867 | 134 | { [ ${grub} -eq 0 ] || phelper=$(command -v part2disk-grubhelper); } || | ||
868 | 135 | fail "no part2disk-grubhelper in PATH" | ||
869 | 136 | [ $grub1 -eq 0 ] || command -v grub >/dev/null || fail "no 'grub' in path"; | ||
870 | 137 | |||
871 | 138 | [ -f "${pimg}" -o -b "${pimg}" ] || fail "${pimg}: not a file or block device" | ||
872 | 139 | |||
873 | 140 | getsize "$pimg" || | ||
874 | 141 | fail "failed to get size of $pimg" | ||
875 | 142 | pimg_s="$_RET" | ||
876 | 143 | |||
877 | 144 | front_pad=$((12*1024*1024)) | ||
878 | 145 | tot_size=$(($front_pad+$pimg_s)) | ||
879 | 146 | tot_size_sectors=$(($tot_size/$ssize)) | ||
880 | 147 | |||
881 | 148 | if [ -n "${size_in}" ]; then | ||
882 | 149 | human2bytes "${size_in}" 1 || fail "failed to convert ${size_in} to bytes" | ||
883 | 150 | size=${_RET} | ||
884 | 151 | else | ||
885 | 152 | size=$tot_size_sectors | ||
886 | 153 | fi | ||
887 | 154 | |||
888 | 155 | if [ -e "$dimg" ]; then | ||
889 | 156 | getsize "$dimg" || | ||
890 | 157 | fail "failed to get size of $dimg" | ||
891 | 158 | dimg_s="$_RET" | ||
892 | 159 | else | ||
893 | 160 | dimg_s="$size" | ||
894 | 161 | fi | ||
895 | 162 | |||
896 | 163 | if [ "${dimg_s}" -lt "$size" ]; then | ||
897 | 164 | fail "size of $dimg ($dimg_s) not large enough to fit $size" | ||
898 | 165 | fi | ||
899 | 166 | |||
900 | 167 | debug 1 "input is ${pimg_s} bytes." | ||
901 | 168 | debug 1 "target is ${tot_size} bytes." | ||
902 | 169 | |||
903 | 170 | debug 2 "create target image" | ||
904 | 171 | dd if=/dev/zero of="${dimg}" bs=$ssize count=$tot_size_sectors \ | ||
905 | 172 | 2>/dev/null || | ||
906 | 173 | fail "failed to write to ${dimg}" | ||
907 | 174 | |||
908 | 175 | debug 2 "create partitions" | ||
909 | 176 | sgdisk -n 15:2048:+8M -t 15:${ptype} -N 1 $dimg | ||
910 | 177 | loop_nr=`kpartx -av $dimg | head -n1 | cut -d" " -f3 | cut -d"p" -f2` | ||
911 | 178 | |||
912 | 179 | debug 2 "parted $dimg print" | ||
913 | 180 | parted $dimg print | ||
914 | 181 | |||
915 | 182 | # copy partition image. this writes $pimg bytes even if that is | ||
916 | 183 | # not divivisble by $ssize | ||
917 | 184 | debug 2 "copying ${pimg} to partition in ${dimg}" | ||
918 | 185 | dd if="$pimg" of=/dev/mapper/loop${loop_nr}p1 conv=notrunc \ | ||
919 | 186 | 2>/dev/null || | ||
920 | 187 | fail "failed to write ${pimg} into ${dimg}" | ||
921 | 188 | |||
922 | 189 | if [ ${grub} -ne 0 ]; then | ||
923 | 190 | debug 2 "invoking part2disk-grubhelper ${dimg}" | ||
924 | 191 | sudo "${phelper}" "${dimg}" || | ||
925 | 192 | fail "part2disk-grubhelper ${dimg} failed" | ||
926 | 193 | fi | ||
927 | 194 | |||
928 | 195 | if [ $grub1 -ne 0 ]; then | ||
929 | 196 | debug 2 "installing grub" | ||
930 | 197 | grub --no-floppy --batch <<EOF | ||
931 | 198 | device (hd0) $dimg | ||
932 | 199 | root (hd0,0) | ||
933 | 200 | setup (hd0) | ||
934 | 201 | quit | ||
935 | 202 | EOF | ||
936 | 203 | fi | ||
937 | 204 | |||
938 | 205 | if [ $grub_efi -ne 0 ]; then | ||
939 | 206 | case $arch in | ||
940 | 207 | x86_64) efiarch=x64;; | ||
941 | 208 | aarch64) efiarch=aa64;; | ||
942 | 209 | i386) efiarch=ia32;; | ||
943 | 210 | arm) efiarch=arm;; | ||
944 | 211 | *) fail "arch $arch without EFI grub" | ||
945 | 212 | esac | ||
946 | 213 | TMP=$(mktemp -d) | ||
947 | 214 | install -d $TMP/tar $TMP/efi $TMP/rootfs | ||
948 | 215 | |||
949 | 216 | mkfs.vfat /dev/mapper/loop${loop_nr}p15 | ||
950 | 217 | mount /dev/mapper/loop${loop_nr}p15 $TMP/efi | ||
951 | 218 | install -d $TMP/efi/EFI/BOOT $TMP/efi/EFI/ubuntu | ||
952 | 219 | tar -xf $grub_in -C $TMP/efi/EFI/BOOT | ||
953 | 220 | |||
954 | 221 | mount /dev/mapper/loop${loop_nr}p1 $TMP/rootfs | ||
955 | 222 | kernelfile=$(cd $TMP/rootfs/boot; ls vmlinu* | head -n1) | ||
956 | 223 | initrdfile=$(cd $TMP/rootfs/boot; ls initrd.img-* | head -n1) | ||
957 | 224 | |||
958 | 225 | |||
959 | 226 | cat >$TMP/efi/EFI/ubuntu/grub.cfg <<EOF | ||
960 | 227 | set default=0 | ||
961 | 228 | set timeout=1 | ||
962 | 229 | menuentry 'CirrOS' { | ||
963 | 230 | set root='hd0,gpt1' | ||
964 | 231 | if [ x$feature_platform_search_hint = xy ]; then | ||
965 | 232 | search --no-floppy --label --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci1,gpt1 cirros-rootfs | ||
966 | 233 | else | ||
967 | 234 | search --no-floppy --label --set=root cirros-rootfs | ||
968 | 235 | fi | ||
969 | 236 | |||
970 | 237 | linux /boot/${kernelfile} LABEL=cirros-rootfs ro | ||
971 | 238 | initrd /boot/${initrdfile} | ||
972 | 239 | } | ||
973 | 240 | EOF | ||
974 | 241 | |||
975 | 242 | umount "$TMP/efi" | ||
976 | 243 | umount "$TMP/rootfs" | ||
977 | 244 | fi | ||
978 | 245 | |||
979 | 246 | set -x | ||
980 | 247 | |||
981 | 248 | # grub-ieee1275 (powerpc) | ||
982 | 249 | if [ $grub_ieee -ne 0 ]; then | ||
983 | 250 | TMP=$(mktemp -d) | ||
984 | 251 | install -d $TMP/rootfs $TMP/tar | ||
985 | 252 | |||
986 | 253 | mkfs.vfat /dev/mapper/loop${loop_nr}p15 | ||
987 | 254 | tar -xf $grub_in -C $TMP/tar | ||
988 | 255 | dd if=$TMP/tar/grub of=/dev/mapper/loop${loop_nr}p15 | ||
989 | 256 | |||
990 | 257 | mount /dev/mapper/loop${loop_nr}p1 $TMP/rootfs | ||
991 | 258 | kernelfile=$(cd $TMP/rootfs/boot; ls vmlinu* | head -n1) | ||
992 | 259 | initrdfile=$(cd $TMP/rootfs/boot; ls initrd.img-* | head -n1) | ||
993 | 260 | |||
994 | 261 | cat >$TMP/rootfs/boot/grub/grub.cfg <<EOF | ||
995 | 262 | set default=0 | ||
996 | 263 | set timeout=1 | ||
997 | 264 | menuentry 'CirrOS' { | ||
998 | 265 | set root='ieee1275/disk,gpt1' | ||
999 | 266 | |||
1000 | 267 | if [ x$feature_platform_search_hint = xy ]; then | ||
1001 | 268 | search --no-floppy --label --set=root --hint-ieee1275=ieee1275/disk,gpt1 cirros-rootfs | ||
1002 | 269 | else | ||
1003 | 270 | search --no-floppy --label --set=root cirros-rootfs | ||
1004 | 271 | fi | ||
1005 | 272 | |||
1006 | 273 | linux /boot/${kernelfile} LABEL=cirros-rootfs ro | ||
1007 | 274 | initrd /boot/${initrdfile} | ||
1008 | 275 | } | ||
1009 | 276 | EOF | ||
1010 | 277 | |||
1011 | 278 | umount "$TMP/rootfs" | ||
1012 | 279 | fi | ||
1013 | 280 | |||
1014 | 281 | |||
1015 | 282 | kpartx -d "$dimg" | ||
1016 | 283 | error "wrote to ${dimg}" | ||
1017 | 284 | # vi: ts=4 noexpandtab | ||
1018 | 0 | 285 | ||
1019 | === added directory 'doc' | |||
1020 | === added file 'doc/README-powerpc.txt.OTHER' | |||
1021 | --- doc/README-powerpc.txt.OTHER 1970-01-01 00:00:00 +0000 | |||
1022 | +++ doc/README-powerpc.txt.OTHER 2016-09-20 12:52:40 +0000 | |||
1023 | @@ -0,0 +1,49 @@ | |||
1024 | 1 | |||
1025 | 2 | CirrOS PowerPC images | ||
1026 | 3 | ===================== | ||
1027 | 4 | |||
1028 | 5 | * Use the build-release script w/ daily option | ||
1029 | 6 | $ export ARCHES="ppc64le powerpc ppc64"; ./bin/build-release daily | ||
1030 | 7 | |||
1031 | 8 | This will build rootfs, grab kernels and grub, install grub w/ modules on | ||
1032 | 9 | prep partition, and bundle image. The *-disk.img is a qcow2 bootable image | ||
1033 | 10 | and contains a grub2 installed on a PreP Boot partition. | ||
1034 | 11 | |||
1035 | 12 | * Quick test | ||
1036 | 13 | $ img=cirros-{YYMMDD}-ppc64le-disk.img; qemu-system-ppc64le -echr 0x05 \ | ||
1037 | 14 | -machine pseries-2.5,accel=kvm,usb=off -cpu host -m 512 -nographic \ | ||
1038 | 15 | $img | ||
1039 | 16 | |||
1040 | 17 | * Add the image to OpenStack | ||
1041 | 18 | $ openstack image create --disk-format qcow2 --container-format bare \ | ||
1042 | 19 | --public --property os_command_line="console=hvc0 console=tty0" \ | ||
1043 | 20 | --property arch=ppc64le --property hypervisor_type=kvm \ | ||
1044 | 21 | --property hw_disk_bus=scsi --property hw_scsi_model=virtio-scsi \ | ||
1045 | 22 | --property hw_cdrom_bus=scsi cirros_qcow2 \ | ||
1046 | 23 | < cirros-{YYMMDD}-ppc64le-disk.img | ||
1047 | 24 | |||
1048 | 25 | NOTE: ppc64le/ppc64 images have been tested extensively on the OpenStack CI | ||
1049 | 26 | using the daily builds - http://download.cirros-cloud.net/daily/ - and works | ||
1050 | 27 | well with virtio drivers (network and disk). | ||
1051 | 28 | |||
1052 | 29 | Currently known working on PowerKVM: | ||
1053 | 30 | |||
1054 | 31 | $ { echo '#!/bin/sh'; echo 'echo HELLO WORLD'; } > user-data | ||
1055 | 32 | $ cloud-localds seed.img user-data | ||
1056 | 33 | |||
1057 | 34 | ## usb=off is required | ||
1058 | 35 | ## -net nic and -drive get default (ibmveth and ibmvscsi) drivers | ||
1059 | 36 | $ qemu-system-ppc64 -machine pseries,accel=kvm,usb=off -m 1G \ | ||
1060 | 37 | -name foo -M pseries \ | ||
1061 | 38 | -device spapr-vscsi \ | ||
1062 | 39 | -net nic -net user \ | ||
1063 | 40 | -display none -nographic \ | ||
1064 | 41 | -drive file=disk1.img \ | ||
1065 | 42 | -kernel "$1" ${2:+-initrd "$2"} \ | ||
1066 | 43 | -append "root=/dev/sda console=hvc0" | ||
1067 | 44 | |||
1068 | 45 | Also known working is adding 'blank.img' as a '-drive'. | ||
1069 | 46 | |||
1070 | 47 | Historical NOTE(smoser) about virtio: | ||
1071 | 48 | What is not working is virtio. I have not successfully gotten virtio network | ||
1072 | 49 | or virtio disk working. |