Merge lp:~rafaelfolco/cirros/cirros into lp:cirros

Proposed by Rafael Folco
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
Reviewer Review Type Date Requested Status
Scott Moser Pending
Review via email: mp+306211@code.launchpad.net

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
=== added directory 'bin'
=== added file 'bin/build-release.OTHER'
--- bin/build-release.OTHER 1970-01-01 00:00:00 +0000
+++ bin/build-release.OTHER 2016-09-20 12:52:40 +0000
@@ -0,0 +1,265 @@
1#!/bin/bash
2#
3# Authors: Scott Moser <smoser@canonical.com>
4# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
5# Rafael Folco <rfolco@br.ibm.com>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, version 3 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
19[ $# -ge 1 ] || { echo "must give version"; exit 1; }
20
21source "${0%/*}/common-functions.sh"
22
23VER=$1
24daily=false
25if [ "$1" = "daily" ]; then
26 VER="d$(date +%y%m%d)"
27 daily=true
28fi
29shift
30pre=cirros-$VER
31BR_VER="2015.05"
32ARCHES="${ARCHES:-i386 x86_64 arm powerpc aarch64 ppc64 ppc64le}"
33KVER="4.4.0-28.47" # Ubuntu 16.04
34GVER="2.02~beta2-36ubuntu8"
35ME=$(readlink -f "$0")
36MY_D=${ME%/*}
37PATH=${MY_D}:$PATH
38
39set -e
40set -o pipefail
41
42OUT="$PWD/../build-$VER"
43LOGFILE="$OUT/date.txt"
44export TMPDIR="$OUT/tmp"
45mkdir -p "$OUT" "$TMPDIR"
46
47msg() {
48 echo "$@" >> "$LOGFILE"
49 echo "$@"
50}
51logevent() {
52 # logevent(msg, [from])
53 # log the message in $1 and time since $2, defaulting to last call.
54 local up delta msg="$1" ref="$2" human=""
55 up=${SECONDS}
56 if [ "$ref" = "-" ]; then
57 ref=""
58 elif [ "$ref" = "" ]; then
59 ref="${_LAST_UP}"
60 fi
61 if [ -n "$ref" ]; then
62 delta="$(($up-$ref))"
63 sec2human "$delta" tshort && human=${_RET}
64 fi
65 msg "$(date -R)" "$msg" "${delta:+Took ${human}. [${delta}s]}"
66 _LAST_UP=$up
67 _RET=${_LAST_UP}
68}
69
70build_arch() {
71 local arch="" quiet=false cmd="" log=""
72 if [ "$1" = "quiet" ]; then
73 quiet=true
74 shift
75 fi
76 arch="$1"
77 log="${OUT}/build-$arch.log"
78 cmd=( make ARCH=$arch "OUT_D=$OUT/build/$arch"
79 ${CCACHE_D:+"BR2_CCACHE_DIR=${CCACHE_D}/$arch"} )
80
81 logevent "start $arch" -
82 if $quiet; then
83 error "building $arch into $log"
84 time "${cmd[@]}" > "$log" 2>&1
85 else
86 time "${cmd[@]}" 2>&1 | tee "$log"
87 fi
88 ret=$?
89 logevent "finish $arch [ret=$ret]"
90 return $ret
91}
92
93get_grub_format() {
94 local arch=$1
95 case "$arch" in
96 powerpc|ppc*) format=ieee;;
97 *) format=efi;;
98 esac
99 echo $format
100}
101
102get_img_size() {
103 local arch=$1
104 case "$arch" in
105 powerpc|ppc*|aarch64) size=96M;;
106 *) size="";;
107 esac
108 echo $size
109}
110
111if [ "$1" = "build_arch" ]; then
112 shift
113 build_arch "$@"
114 exit
115elif [ $# -gt 1 ]; then
116 fail "confused by $# arguments: $*"
117fi
118
119# really just here to check that VER is a tag
120# or source code checkout would fail
121if ! $daily; then
122 revno=$(bzr tags -r "tag:$VER") || fail "$VER: not a tag in $PWD."
123 revno=$(echo "$revno" | awk '{print $2}')
124fi
125
126logevent "begin" -
127tstart=${_RET}
128
129logevent "start download" -
130rm -f download
131mkdir -p ../download
132ln -snf ../download download
133brtgz="buildroot-${BR_VER}.tar.gz"
134dl "http://buildroot.uclibc.org/downloads/$brtgz" "download/$brtgz"
135logevent "end download"
136
137logevent "start unpack" -
138rm -Rf "buildroot-${BR_VER}"
139rm -f buildroot
140tar -xvf download/buildroot-${BR_VER}.tar.gz
141ln -snf buildroot-${BR_VER} buildroot
142
143# we do not do this here, so that we're not dependent on the
144# cvs working (which wont work through http_proxy) and also
145# to have revision controlled information in that file.
146#./bin/mkcabundle > src/etc/ssl/certs/ca-certificates.crt
147
148( cd buildroot && QUILT_PATCHES="$PWD/../patches-buildroot" quilt push -a )
149
150echo "$VER" > "src/etc/cirros/version"
151logevent "end unpack"
152
153# Stage 1: DOWNLOAD
154logevent "start br-source" -
155make ARCH=${ARCHES%% *} br-source
156logevent "end br-source"
157
158for arch in ${ARCHES}; do
159 format=$(get_grub_format "$arch")
160 mkdir -p "$OUT/stage/$arch"
161
162 # grab kernel
163 logevent "start kernel download" -
164 grab-kernels "$KVER" $arch
165 logevent "end kernel download"
166
167 # grab grub
168 logevent "start grub $arch-$format download" -
169 grab-grub-${format} "$GVER" $arch
170 logevent "end grub $arch-$format download"
171done
172
173# STAGE 2: BUILD
174jobs_flag=""
175parallel=true
176case "${CIRROS_PARALLEL:-none}" in
177 none) parallel=false;;
178 0|true) :;;
179 [0-9]|[0-9][0-9]) jobs_flag="--jobs=${CIRROS_PARALLEL}";;
180 auto) command -v parallel >/dev/null || parallel=false;;
181 *) fail "unknown value for CIRROS_PARALLEL=$CIRROS_PARALLEL";;
182esac
183
184if $parallel; then
185 parallel --ungroup ${jobs_flag} \
186 "$0" "$VER" build_arch quiet {} ::: ${ARCHES}
187else
188 for arch in ${ARCHES}; do
189 build_arch "$arch"
190 done;
191fi
192
193# STAGE 3: BUNDLE
194for arch in ${ARCHES}; do
195 # bundle rootfs, kernel & grub
196 format=$(get_grub_format "$arch")
197 size=$(get_img_size "$arch")
198 logevent "start bundling $arch" -
199 sudo ./bin/bundle -v ${size:+--size=$size} --arch="$arch" \
200 "$OUT/build/$arch/rootfs.tar" \
201 ./download/kernel-$arch.tar.gz ./download/grub-${format}-$arch.tar.gz \
202 "$OUT/stage/$arch";
203 logevent "finish bundling $arch"
204done
205
206sudo chown -R $USER:$USER "$OUT/stage"
207
208mkdir -p "$OUT/release"
209
210#srctgz="$OUT/release/cirros-$VER-source.tar.gz"
211#bzr export -r "tag:$VER" --format=tgz --root="cirros-$VER" "$srctgz"
212#echo "wrote source tgz: $srctgz"
213if ! $daily; then
214 ( srcd="$PWD" && tmpd=$(mktemp -d) && cd "$tmpd" &&
215 bzr branch "$srcd" -r tag:$VER cirros-$VER &&
216 rm -Rf cirros-$VER/.bzr &&
217 echo "$VER" > "cirros-$VER/src/etc/cirros/version" &&
218 tar cvzf - cirros-$VER ) > "$OUT/release/cirros-$VER-source.tar.gz"
219fi
220
221rm -f "$OUT/stage"/*/"$pre"*
222for arch in ${ARCHES}; do
223 p=$pre-$arch
224 ( cd "$OUT/stage/$arch" &&
225 ln kernel $p-vmlinuz && ln kernel $p-kernel &&
226 ln initramfs $p-initrd && ln initramfs $p-initramfs &&
227 ln part.img $p-rootfs.img &&
228 ln blank.img $p-blank.img &&
229 ln disk.img $p-disk.img &&
230 ln filesys.tar.gz $p-lxc.tar.gz &&
231 true
232 );
233done
234
235logevent "start populating release" -
236for arch in ${ARCHES}; do
237 p=$pre-$arch
238 ( cd "$OUT/stage/$arch" &&
239 cp $p-kernel $p-initramfs $p-lxc.tar.gz "$OUT/release/" &&
240 gzip -9 -c $p-rootfs.img > $OUT/release/$p-rootfs.img.gz ) &&
241 ( cd "$OUT/stage/$arch" &&
242 tar cvzf - $p-blank.img $p-vmlinuz $p-initrd
243 ) > "$OUT/release/$p-uec.tar.gz"
244 cp "$OUT/stage/$arch/$p-disk.img" "$OUT/release/$p-disk.img"
245done
246
247mkdir -p "$OUT/release/buildroot_rootfs"
248for arch in ${ARCHES}; do
249 t="$OUT/release/buildroot_rootfs/buildroot-$VER-$arch.tar"
250 cp "$OUT/build/$arch/rootfs.tar" "$t"
251 gzip --force -9 "$t"
252done
253
254chmod u+rwX,go+rX -R "$OUT/release/"*
255
256sumfiles=$(cd "$OUT/release" && for f in *; do
257 [ -f "$f" -a "$f" != MD5SUMS ] && echo "$f"; done)
258( cd "$OUT/release" && md5sum $sumfiles > MD5SUMS )
259
260logevent "finish populate release" -
261msg "output in $OUT/release"
262msg "entire process took $SECONDS seconds"
263logevent "finished" "$tstart"
264
265# vi: tabstop=4 expandtab
0266
=== added file 'bin/bundle.OTHER'
--- bin/bundle.OTHER 1970-01-01 00:00:00 +0000
+++ bin/bundle.OTHER 2016-09-20 12:52:40 +0000
@@ -0,0 +1,348 @@
1#!/bin/bash
2#
3# Authors: Scott Moser <smoser@canonical.com>
4# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
5# Rafael Folco <rfolco@br.ibm.com>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, version 3 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19
20source "${0%/*}/common-functions.sh"
21
22TEMP_D=""
23UMOUNT=""
24DEF_SIZE=${DEF_SIZE:-32M}
25DEF_MODULES="acpiphp e1000 ne2k-pci 8139cp pcnet32 ip_tables"
26
27Usage() {
28 cat <<EOF
29Usage: ${0##*/} rootfs.tar kpkg.deb output_dir
30 [re]Bundle a buildroot rootfs into a mini-cloud image
31
32 options:
33 -s | --size S resize image to size (default: ${DEF_SIZE})
34 --arch A prepare for arch A
35
36 Example:
37 ${0##*/} rootfs.tar linux-image-*-virtuaal*.deb build-output/
38EOF
39}
40cleanup() {
41 [ -z "${UMOUNT}" ] || umount "${UMOUNT}"
42 [ -z "${TEMP_D}" -o ! -d "${TEMP_D}" ] || rm -Rf "${TEMP_D}"
43}
44xrsync() {
45 rsync --archive --xattrs --hard-links --acls --sparse "$@"
46}
47
48short_opts="hs:v"
49long_opts="arch:,initrd-busybox:,help,size:,verbose"
50getopt_out=$(getopt --name "${0##*/}" \
51 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
52 eval set -- "${getopt_out}" ||
53 bad_Usage
54
55topdir=$(cd "${0%/*}/.." && pwd)
56size=${DEF_SIZE}
57FS_LABEL="cirros-rootfs"
58fs_type="ext3"
59arch=""
60
61while [ $# -ne 0 ]; do
62 cur=${1}; next=${2};
63 case "$cur" in
64 -h|--help) Usage; exit 0;;
65 -s|--size) size=${next}; shift;;
66 --arch) arch=${next}; shift;;
67 -v|--verbose) DEBUG=$((${DEBUG}+1));;
68 --) shift; break;;
69 esac
70 shift;
71done
72
73[ $# -eq 4 ] || bad_Usage "must give rootfs.tar, kernel pkg, grub-{efi|ieee}.tar, out_dir"
74rootfs_in=${1}
75kpkg_in=${2}
76grub_in=${3}
77out_d_in=${4}
78
79PATH="$topdir/bin:$PATH"
80src_dir="${topdir}/src"
81src_symlinks="${topdir}/symlinks.list"
82makedevs_list="${topdir}/makedevs.list"
83fixup_fs="${topdir}/fixup-fs"
84xgrubd="$topdir/grubd"
85
86[ "$(id -u)" = "0" ] || fail "sorry... must be root"
87
88[ -d "${src_dir}" ] || fail "no source dir ${src_d}"
89
90TEMP_D=$(mktemp -d "${TMPDIR:-/tmp}/.${0##*/}.XXXXXX") ||
91 fail "failed to make tempd"
92trap cleanup EXIT
93
94mkdir -p "${out_d_in}" && out_d=$(readlink -f "${out_d_in}") &&
95 rootfs=$(readlink -f "${rootfs_in}") &&
96 kpkg=$(readlink -f "${kpkg_in}") ||
97 fail "failed to get full path for input"
98
99out_partimg="${out_d}/part.img"
100out_diskimg="${out_d}/disk.img"
101out_kernel="${out_d}/kernel"
102out_initramfs="${out_d}/initramfs"
103out_diskimg="${out_d}/disk.img"
104out_blankimg="${out_d}/blank.img"
105out_filesys_lxc="${out_d}/filesys.tar.gz"
106inter_d="$out_d/intermediate"
107
108mp="${TEMP_D}/mnt"
109kernel_d="${TEMP_D}/kernel"
110kern_list_full="${TEMP_D}/kernel.files.full"
111kern_files="${TEMP_D}/kernel.files"
112kern_modules="${TEMP_D}/kernel.files.modules"
113overlay_d="${TEMP_D}/overlay"
114initramfs_d="${TEMP_D}/initramfs"
115initramfs="${TEMP_D}/initramfs.img"
116stage_d="$TEMP_D/staging"
117
118kernel_tar="$inter_d/kernel.tar"
119overlay_tar="$inter_d/overlay.tar"
120filesys_tar="$inter_d/filesys.tar"
121
122modfile="$src_dir/etc/modules"
123if [ -f "$modfile" ]; then
124 MODULES=$("$src_dir/etc/init.d/load-modules" parse_modules \
125 "$modfile" "$arch") ||
126 fail "failed to read modules"
127 MODULES=$(echo "$MODULES" | sed 's, .*,,' | tr '\n' ' ')
128else
129 MODULES=${DEF_MODULES}
130fi
131debug 1 "modules: $MODULES"
132
133prepare-grub "$xgrubd" ||
134 fail "failed to get grub binary"
135
136mkdir -p "${mp}" "${kernel_d}" "${overlay_d}" \
137 "${initramfs_d}" "$inter_d" "$stage_d" ||
138 fail "failed to make temp dirs"
139
140debug 1 "creating filesystem in ${out_partimg}"
141rm -f "$out_partimg"
142truncate "--size=${size}" "${out_partimg}" ||
143 fail "failed to create ${out_partimg} of size ${size}"
144
145out=$("mkfs.${fs_type}" -F "${out_partimg}" -L "${FS_LABEL}" 2>&1) ||
146 fail "failed to make filesystem of type ${fs_type}: ${out}"
147
148cp "$out_partimg" "$out_blankimg" ||
149 fail "failed to to copy blank partition image"
150
151debug 1 "preparing kernel overlay"
152# creating kernel tarball
153case "$kpkg_in" in
154 *.deb)
155 dpkg -x "${kpkg_in}" "${kernel_d}" ||
156 fail "failed extracting kernel deb package in ${kpkg_in}"
157 ;;
158 *.tar*)
159 tar -C "$kernel_d" -xf "$kpkg_in" ||
160 fail "failed extracting kernel tarball in ${kpkg_in}"
161 ;;
162 *) fail "unknown file format for $kpkg_in";;
163esac
164
165( cd "${kernel_d}" && find * -type f ) > "${kern_list_full}" ||
166 fail "failed to extract kernel to ${kernel_d}"
167
168kver=""
169for x in "$kernel_d/lib/modules"/*; do
170 [ -d "$x/kernel" ] || continue
171 [ -z "$kver" ] ||
172 fail "2 or more things looked like kernels in lib/modules of $kpkg_in"
173 kver="${x##*/}"
174done
175[ -n "$kver" ] ||
176 fail "failed to find kernel version. no lib/modules/* ?"
177
178depmod -a --basedir "${kernel_d}" "${kver}" ||
179 fail "failed to run depmod"
180
181mdep="${kernel_d}/lib/modules/${kver}/modules.dep"
182for x in ${MODULES}; do
183 grep -q "/${x}.ko" "${mdep}" ||
184 { error "WARNING: no ${x} in kernel package!"; continue; }
185 awk -F: '$1 ~ mat {
186 sub(":","",$1)
187 printf("%s/%s\n",p,$1)
188 leng=split($0,deps," ")
189 x=2 # strange, but 0 contains nothing, 1 contains first field (with :)
190 while ( x<=leng ) {
191 printf("%s/%s\n", p, deps[x]);
192 x++
193 }
194 }' mat="/${x}.ko$" p="lib/modules/${kver}" "${mdep}"
195done > "${kern_modules}"
196sort -u "${kern_modules}" > "${kern_files}"
197vmlinuz=$( cd "${kernel_d}" && [ -f boot/vmlinu?-* ] &&
198 echo boot/vmlinu?-* ) && echo "${vmlinuz}" >> "${kern_files}" &&
199 ln -sf "$vmlinuz" "$kernel_d/vmlinuz" && echo "vmlinuz" >> "$kern_files" ||
200 fail "no kernel (boot/vmlinuz-*) found in ${kpkg_in}"
201echo "boot/config-$kver" >> "$kern_files"
202
203tar -C "${kernel_d}" -cpf - \
204 --files-from "${kern_files}" > "${kernel_tar}" ||
205 fail "failed to collect kernel files"
206
207debug 1 "preparing source overlay from ${src_dir}"
208xrsync "${src_dir}/" "${overlay_d}" ||
209 fail "failed to copy source dir"
210
211chown -R 0:0 "${overlay_d}" || fail "failed to chown files in overlay"
212
213if [ -f "${src_symlinks}" ]; then
214 ( cd "${overlay_d}" &&
215 while read src target; do
216 { [ -d "${target%/*}" ] || mkdir -p "${target%/*}"; } ||
217 { error "could not create ${target%/*}"; exit 1; }
218 ln -sf "${src}" "${target}" || exit 1
219 done < "${src_symlinks}"
220 ) || fail "failed to create symlinks"
221fi
222if [ -f "${makedevs_list}" ]; then
223 xmakedevs "$makedevs_list" "$overlay_d" ||
224 fail "failed to makedevs on overlay"
225fi
226
227( cd "$overlay_d" && tar -cpf - * ) > "$overlay_tar" ||
228 fail "failed to make overlay_tar"
229
230debug 1 "populating staging directory"
231tar -C "$stage_d" -xpf - < "$rootfs_in" ||
232 fail "failed to extract rootfs_tar"
233tar -C "$stage_d" -xpf - < "$overlay_tar" ||
234 fail "failed to extract overlay_tar"
235
236if [ -x "${fixup_fs}" ]; then
237 "${fixup_fs}" "${stage_d}" ||
238 fail "failed to fixup filesystem"
239fi
240
241( cd "$stage_d" && tar -Scpzf - -- * ) > "$out_filesys_lxc" ||
242 fail "failed to create filesys tarball"
243
244tar -C "$stage_d" -xpf - < "$kernel_tar" ||
245 fail "failed to extract kernel_tar"
246tar -C "$stage_d" -xpf - < "$xgrubd/bootgrub.tar" ||
247 fail "failed to extract bootgrub"
248
249depmod -a --basedir "$stage_d" "${kver}" ||
250 fail "failed to run depmod for kver ${kver} in output"
251
252debug 1 "creating initramfs"
253xrsync "$stage_d/" "$initramfs_d" ||
254 fail "failed to copy to initramfs_d"
255rm -Rf "$initramfs_d/vmlinuz" "$initramfs_d/boot" ||
256 fail "failed to remove files in initramfs staging dir"
257
258( cd "$initramfs_d" && find . | cpio --quiet -o -H newc |
259 gzip -9 ) > "$initramfs"
260
261# Here we create /boot/initrd.img-${kver}.
262# That is the initramfs that is put inside of disk images.
263# Since the disk images have all the modules available in the
264# filesystem, we put no modules in this initramfs. Having them
265# in both places would just waste space.
266#
267# That means that the kernel must have builtin drivers for
268# any block devices. Another path to accomplishing the same
269# space savings is what cloud-initramfs-copymods does.
270# The solution there is that if there is no /lib/modules/<kver>
271# inside the target filesystem, then the initramfs mount binds
272# its /lib/modules/<kver> into the target.
273rm -Rf "$initramfs_d/lib/modules/$kver" ||
274 fail "failed to remove lib/modules for mini initramfs"
275
276( cd "$initramfs_d" && find . | cpio --quiet -o -H newc |
277 gzip -9 ) > "${initramfs}.smaller"
278
279cp "${initramfs}.smaller" "$stage_d/boot/initrd.img-${kver}" &&
280 ln -s "boot/initrd.img-${kver}" "${stage_d}/initrd.img" ||
281 fail "failed to copy initramfs to stage dir"
282
283debug 1 "packing clean kernel_tar"
284tar -C "$stage_d" -cpf - \
285 vmlinuz initrd.img boot/ lib/modules/ > "$kernel_tar" ||
286 fail "failed to create clean kerne_tar"
287
288( cd "$stage_d" && tar -cpf - * ) > "$filesys_tar" ||
289 fail "failed to create filesys_tar"
290
291debug 1 "populating image"
292mount -o loop "${out_partimg}" "${mp}" && UMOUNT=${mp} ||
293 fail "failed to mount ${out_partimg} loopback"
294
295tar -C "$mp" -xpf - < "$filesys_tar" ||
296 fail "failed to populate mount point"
297
298umount "${mp}" && UMOUNT="" ||
299 fail "failed to unmount ${out_partimg}"
300
301cp "${kernel_d}/${vmlinuz}" "${out_kernel}" ||
302 fail "failed to copy kernel to ${out_kernel}"
303
304{ [ -z "${out_initramfs}" ] || cp "${initramfs}" "${out_initramfs}"; } ||
305 fail "failed to copy initramfs to ${out_initramfs}"
306
307debug 1 "fixing grub entry in partimg"
308tmp_part="$TEMP_D/part.img.disk"
309cp "$out_partimg" "$tmp_part" &&
310 mount -o loop "$tmp_part" "$mp" && UMOUNT="$mp" ||
311 fail "failed to mount $tmp_part"
312sed -i 's/(hd0)/(hd0,0)/' "$mp/boot/grub/menu.lst" ||
313 fail "failed to edit /boot/grub/menu.lst in image"
314umount "$mp" && UMOUNT="" ||
315 fail "failed to unmount partimg"
316
317case $arch in
318 i386|x86_64) grub_options="--grub1 --grub-efi";;
319 arm|aarch64) grub_options="--grub-efi";;
320 powerpc|ppc*) grub_options="--grub-ieee";;
321 *) grub_options=;;
322esac
323
324debug 1 "creating disk image"
325out=$(PATH=$xgrubd:$PATH part2disk $grub_options "$tmp_part" \
326 "$grub_in" "$arch" "$out_diskimg.raw" 2>&1) ||
327 fail "failed to create disk image: $out"
328qemu-img convert -O qcow2 -c "$out_diskimg.raw" "$out_diskimg" ||
329 fail "failed to convert disk image"
330rm -f "$out_diskimg.raw" "$tmp_part"
331
332if [ -n "${SUDO_USER}" ]; then
333 u=${SUDO_USER}
334 g=$(id -g "${u}") || g=${u}
335 chown "${u}:${g}" -R "$out_d" ||
336 fail "failed to grant ownership of ${u}:${g} to ${u}:${g}"
337fi
338
339echo "wrote ${out_partimg}"
340echo "wrote ${out_diskimg}"
341echo "wrote ${out_kernel}"
342echo "wrote ${out_initramfs}"
343echo "wrote ${out_blankimg}"
344echo "wrote ${out_filesys_lxc}"
345
346exit 0
347
348# vi: tabstop=4 expandtab
0349
=== added file 'bin/grab-grub-ieee'
--- bin/grab-grub-ieee 1970-01-01 00:00:00 +0000
+++ bin/grab-grub-ieee 2016-09-20 12:52:40 +0000
@@ -0,0 +1,100 @@
1#!/bin/bash
2#
3# Copyright (C) 2016 IBM Corp.
4#
5# Author: Rafael Folco <rfolco@br.ibm.com>
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, version 3 of the License.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19
20source "${0%/*}/common-functions.sh"
21
22burl="https://launchpad.net/ubuntu/+archive/primary/+files/"
23outdir="./download"
24def_arches="ppc64le powerpc ppc64"
25
26[ "$1" = "--outdir" ] && { outdir="$1" && shift; }
27gver="$1"
28shift
29
30if [ $# -eq 0 ]; then
31 set -- ${def_arches}
32fi
33
34[ -d "$outdir" ] || mkdir -p "$outdir" ||
35 fail "failed mkdir $outdir"
36
37[ -n "$gver" ] || fail "must give grub version"
38
39deb2tar() {
40
41 local deb="$1" tar="$2"
42
43 t=$(dirname "$deb")
44 tdir=$(mktemp -d "$t/.XXXXXX") || return
45
46 debug 1 "creating $out in tempdir at $tdir"
47
48 mkdir -p "$tdir/deb"
49 dpkg -x "$deb" "$tdir/deb" || fail "failed to unpack $deb"
50
51 gbin="grub"
52 gmod="boot cat configfile echo ext2 halt loadenv minicmd normal part_gpt
53 reboot search search_fs_uuid search_fs_file search_label serial sleep
54 test linux"
55
56 debug 2 "grub-mkimage: creating grub powerpc-ieee1275 image"
57 grub-mkimage --directory "${tdir}/deb/usr/lib/grub/powerpc-ieee1275" \
58 --prefix "(ieee1275/disk,gpt1)/boot/grub" \
59 --output "$tdir/${gbin}" \
60 --format "powerpc-ieee1275" \
61 --compression "none" $gmod
62
63 rm -rf "$tdir/deb"
64 debug 2 "creating grub.tar.gz"
65 tar -C "$tdir/" -czf "$tdir/grub.tar.gz" $gbin &&
66 mv "$tdir/grub.tar.gz" "$tar" || {
67 error "failed creating tarball";
68 rm -Rf "$tdir"
69 return 1;
70 }
71 rm -Rf "$tdir"
72 return 0
73
74}
75
76for arch in "$@"; do
77 case "$arch" in
78 ppc64le)
79 debarch='ppc64el'
80 ;;
81 powerpc|ppc64)
82 debarch='powerpc'
83 ;;
84 *) debug 1 "no grub-ieee1275 for $arch";;
85 esac
86
87 # e.g. https://launchpad.net/ubuntu/+archive/primary/+files/grub-ieee1275-bin_2.02~beta2-36ubuntu8_ppc64el.deb
88 deb="grub-ieee1275-bin_${gver}_${debarch}.deb"
89 if [ ! -f "${outdir}/${deb}" ]; then
90 dl $burl/$deb "$outdir/$deb" || fail "failed dl $burl/$deb"
91 fi
92 tar="grub-ieee-${gver}-${arch}.tar.gz"
93 deb2tar "$outdir/$deb" "$outdir/$tar" ||
94 fail "failed deb2tar from $deb to $tar"
95
96 error "wrote $outdir/${tar}"
97 ln -sf "${tar}" "$outdir/grub-ieee-${arch}.tar.gz" ||
98 fail "failed symlink for $outdir/grub-ieee-${arch}.tar.gz"
99done
100# vi: ts=4 expandtab
0101
=== added file 'bin/part2disk.OTHER'
--- bin/part2disk.OTHER 1970-01-01 00:00:00 +0000
+++ bin/part2disk.OTHER 2016-09-20 12:52:40 +0000
@@ -0,0 +1,284 @@
1#!/bin/bash
2# part2disk - wrap a partition image in a disk image
3#
4# Copyright (C) 2010 Canonical Ltd.
5#
6# Authors: Scott Moser <smoser@canonical.com>
7# Marcin Juszkiewicz <marcin.juszkiewicz@linaro.org>
8# Rafael Folco <rfolco@br.ibm.com>
9#
10# This program is free software: you can redistribute it and/or modify
11# it under the terms of the GNU General Public License as published by
12# the Free Software Foundation, version 3 of the License.
13#
14# This program is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17# GNU General Public License for more details.
18#
19# You should have received a copy of the GNU General Public License
20# along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22source "${0%/*}/common-functions.sh"
23
24DEF_SECTOR_SIZE=512
25base_d=$(dirname $(readlink -f "${0}"))
26PATH="${PATH}:${base_d}"
27
28getsize() {
29 local fname="$1" kname="" size=""
30 if [ -b "${fname}" ]; then
31 kname=$(readlink -f "${fname}") &&
32 size=$(awk '$4 == kn { print $3 * 1024 }' \
33 "kn=${kname##*/}" /proc/partitions) &&
34 [ -n "${size}" ] || {
35 error "failed to read size of ${fname} from /proc/partitions";
36 return 1;
37 }
38 else
39 size=$(stat --format "%s" "${fname}") || {
40 error "failed to get size of ${fname}"
41 return 1;
42 }
43 fi
44 _RET="$size"
45}
46
47Usage() {
48 cat <<EOF
49Usage: ${0##*/} [options] partition-image grub-{efi|ieee}-tarball architecture disk-image
50
51 Create disk image 'disk-image' with 'partition-image' in a partition
52 inside it. Add grub if requested.
53
54 options:
55 -G | --grub install grub to disk image mbr
56 | --grub1 install grub1 to disk image mbr
57 | --grub-efi install EFI grub to disk image
58 | --grub-ieee install ieee1275 grub to disk image prep partition
59 -s | --size S create the disk image of size 'S'.
60 default is large enough to fit partition-image
61 -v | --verbose increase verbosity
62EOF
63}
64human2bytes() {
65 # converts size suitable for input to resize2fs to bytes
66 # s:512 byte sectors, K:kilobytes, M:megabytes, G:gigabytes
67 # none: block size of the image
68 local input=${1} defunit=${2:-1024}
69 local unit count;
70 case "$input" in
71 *s) count=${input%s}; unit=512;;
72 *K) count=${input%K}; unit=1024;;
73 *M) count=${input%M}; unit=$((1024*1024));;
74 *G) count=${input%G}; unit=$((1024*1024*1024));;
75 *) count=${input} ; unit=${2:-1024};;
76 esac
77 _RET=$((${count}*${unit}))
78}
79
80cleanup() {
81 umount "$TMP/efi"
82 umount "$TMP/rootfs"
83 kpartx -d "$dimg"
84}
85
86trap cleanup EXIT
87
88short_opts="b:c:Ghs:v"
89long_opts="grub-ieee,grub-efi,grub1,grub,help,size:,verbose"
90getopt_out=$(getopt --name "${0##*/}" \
91 --options "${short_opts}" --long "${long_opts}" -- "$@") &&
92 eval set -- "${getopt_out}" ||
93 bad_Usage
94
95ssize=${DEF_SECTOR_SIZE}
96size_in=""
97grub_ptnum=1
98grub=0
99grub1=0
100grub_efi=0
101grub_ieee=0
102while [ $# -ne 0 ]; do
103 cur=${1}; next=${2};
104 case "$cur" in
105 -G|--grub)
106 grub=1
107 ;;
108 -G|--grub1)
109 grub1=1
110 ;;
111 --grub-efi)
112 grub_efi=1
113 ptype="ef00" # EFI System
114 ;;
115 --grub-ieee)
116 grub_ieee=1
117 ptype="4100" # PowerPC PreP Boot
118 ;;
119 -h|--help) Usage; exit 0;;
120 -s|--size) size_in=$2; shift;;
121 -v|--verbose) DEBUG=$((${DEBUG}+1));;
122 --) shift; break;;
123 esac
124 shift;
125done
126
127[ $# -eq 4 ] || bad_Usage "must supply partition image, grub-{efi|ieee} tarball, architecture and output file"
128
129pimg=${1}
130grub_in=${2}
131arch=${3}
132dimg=${4}
133
134{ [ ${grub} -eq 0 ] || phelper=$(command -v part2disk-grubhelper); } ||
135 fail "no part2disk-grubhelper in PATH"
136[ $grub1 -eq 0 ] || command -v grub >/dev/null || fail "no 'grub' in path";
137
138[ -f "${pimg}" -o -b "${pimg}" ] || fail "${pimg}: not a file or block device"
139
140getsize "$pimg" ||
141 fail "failed to get size of $pimg"
142pimg_s="$_RET"
143
144front_pad=$((12*1024*1024))
145tot_size=$(($front_pad+$pimg_s))
146tot_size_sectors=$(($tot_size/$ssize))
147
148if [ -n "${size_in}" ]; then
149 human2bytes "${size_in}" 1 || fail "failed to convert ${size_in} to bytes"
150 size=${_RET}
151else
152 size=$tot_size_sectors
153fi
154
155if [ -e "$dimg" ]; then
156 getsize "$dimg" ||
157 fail "failed to get size of $dimg"
158 dimg_s="$_RET"
159else
160 dimg_s="$size"
161fi
162
163if [ "${dimg_s}" -lt "$size" ]; then
164 fail "size of $dimg ($dimg_s) not large enough to fit $size"
165fi
166
167debug 1 "input is ${pimg_s} bytes."
168debug 1 "target is ${tot_size} bytes."
169
170debug 2 "create target image"
171dd if=/dev/zero of="${dimg}" bs=$ssize count=$tot_size_sectors \
172 2>/dev/null ||
173 fail "failed to write to ${dimg}"
174
175debug 2 "create partitions"
176sgdisk -n 15:2048:+8M -t 15:${ptype} -N 1 $dimg
177loop_nr=`kpartx -av $dimg | head -n1 | cut -d" " -f3 | cut -d"p" -f2`
178
179debug 2 "parted $dimg print"
180parted $dimg print
181
182# copy partition image. this writes $pimg bytes even if that is
183# not divivisble by $ssize
184debug 2 "copying ${pimg} to partition in ${dimg}"
185dd if="$pimg" of=/dev/mapper/loop${loop_nr}p1 conv=notrunc \
186 2>/dev/null ||
187 fail "failed to write ${pimg} into ${dimg}"
188
189if [ ${grub} -ne 0 ]; then
190 debug 2 "invoking part2disk-grubhelper ${dimg}"
191 sudo "${phelper}" "${dimg}" ||
192 fail "part2disk-grubhelper ${dimg} failed"
193fi
194
195if [ $grub1 -ne 0 ]; then
196 debug 2 "installing grub"
197 grub --no-floppy --batch <<EOF
198device (hd0) $dimg
199root (hd0,0)
200setup (hd0)
201quit
202EOF
203fi
204
205if [ $grub_efi -ne 0 ]; then
206 case $arch in
207 x86_64) efiarch=x64;;
208 aarch64) efiarch=aa64;;
209 i386) efiarch=ia32;;
210 arm) efiarch=arm;;
211 *) fail "arch $arch without EFI grub"
212 esac
213 TMP=$(mktemp -d)
214 install -d $TMP/tar $TMP/efi $TMP/rootfs
215
216 mkfs.vfat /dev/mapper/loop${loop_nr}p15
217 mount /dev/mapper/loop${loop_nr}p15 $TMP/efi
218 install -d $TMP/efi/EFI/BOOT $TMP/efi/EFI/ubuntu
219 tar -xf $grub_in -C $TMP/efi/EFI/BOOT
220
221 mount /dev/mapper/loop${loop_nr}p1 $TMP/rootfs
222 kernelfile=$(cd $TMP/rootfs/boot; ls vmlinu* | head -n1)
223 initrdfile=$(cd $TMP/rootfs/boot; ls initrd.img-* | head -n1)
224
225
226 cat >$TMP/efi/EFI/ubuntu/grub.cfg <<EOF
227set default=0
228set timeout=1
229menuentry 'CirrOS' {
230 set root='hd0,gpt1'
231 if [ x$feature_platform_search_hint = xy ]; then
232 search --no-floppy --label --set=root --hint-bios=hd0,gpt1 --hint-efi=hd0,gpt1 --hint-baremetal=ahci1,gpt1 cirros-rootfs
233 else
234 search --no-floppy --label --set=root cirros-rootfs
235 fi
236
237 linux /boot/${kernelfile} LABEL=cirros-rootfs ro
238 initrd /boot/${initrdfile}
239}
240EOF
241
242 umount "$TMP/efi"
243 umount "$TMP/rootfs"
244fi
245
246set -x
247
248# grub-ieee1275 (powerpc)
249if [ $grub_ieee -ne 0 ]; then
250 TMP=$(mktemp -d)
251 install -d $TMP/rootfs $TMP/tar
252
253 mkfs.vfat /dev/mapper/loop${loop_nr}p15
254 tar -xf $grub_in -C $TMP/tar
255 dd if=$TMP/tar/grub of=/dev/mapper/loop${loop_nr}p15
256
257 mount /dev/mapper/loop${loop_nr}p1 $TMP/rootfs
258 kernelfile=$(cd $TMP/rootfs/boot; ls vmlinu* | head -n1)
259 initrdfile=$(cd $TMP/rootfs/boot; ls initrd.img-* | head -n1)
260
261 cat >$TMP/rootfs/boot/grub/grub.cfg <<EOF
262set default=0
263set timeout=1
264menuentry 'CirrOS' {
265 set root='ieee1275/disk,gpt1'
266
267 if [ x$feature_platform_search_hint = xy ]; then
268 search --no-floppy --label --set=root --hint-ieee1275=ieee1275/disk,gpt1 cirros-rootfs
269 else
270 search --no-floppy --label --set=root cirros-rootfs
271 fi
272
273 linux /boot/${kernelfile} LABEL=cirros-rootfs ro
274 initrd /boot/${initrdfile}
275}
276EOF
277
278 umount "$TMP/rootfs"
279fi
280
281
282kpartx -d "$dimg"
283error "wrote to ${dimg}"
284# vi: ts=4 noexpandtab
0285
=== added directory 'doc'
=== added file 'doc/README-powerpc.txt.OTHER'
--- doc/README-powerpc.txt.OTHER 1970-01-01 00:00:00 +0000
+++ doc/README-powerpc.txt.OTHER 2016-09-20 12:52:40 +0000
@@ -0,0 +1,49 @@
1
2CirrOS PowerPC images
3=====================
4
5 * Use the build-release script w/ daily option
6 $ export ARCHES="ppc64le powerpc ppc64"; ./bin/build-release daily
7
8 This will build rootfs, grab kernels and grub, install grub w/ modules on
9 prep partition, and bundle image. The *-disk.img is a qcow2 bootable image
10 and contains a grub2 installed on a PreP Boot partition.
11
12 * Quick test
13 $ img=cirros-{YYMMDD}-ppc64le-disk.img; qemu-system-ppc64le -echr 0x05 \
14 -machine pseries-2.5,accel=kvm,usb=off -cpu host -m 512 -nographic \
15 $img
16
17 * Add the image to OpenStack
18 $ openstack image create --disk-format qcow2 --container-format bare \
19 --public --property os_command_line="console=hvc0 console=tty0" \
20 --property arch=ppc64le --property hypervisor_type=kvm \
21 --property hw_disk_bus=scsi --property hw_scsi_model=virtio-scsi \
22 --property hw_cdrom_bus=scsi cirros_qcow2 \
23 < cirros-{YYMMDD}-ppc64le-disk.img
24
25 NOTE: ppc64le/ppc64 images have been tested extensively on the OpenStack CI
26 using the daily builds - http://download.cirros-cloud.net/daily/ - and works
27 well with virtio drivers (network and disk).
28
29Currently known working on PowerKVM:
30
31$ { echo '#!/bin/sh'; echo 'echo HELLO WORLD'; } > user-data
32$ cloud-localds seed.img user-data
33
34## usb=off is required
35## -net nic and -drive get default (ibmveth and ibmvscsi) drivers
36$ qemu-system-ppc64 -machine pseries,accel=kvm,usb=off -m 1G \
37 -name foo -M pseries \
38 -device spapr-vscsi \
39 -net nic -net user \
40 -display none -nographic \
41 -drive file=disk1.img \
42 -kernel "$1" ${2:+-initrd "$2"} \
43 -append "root=/dev/sda console=hvc0"
44
45Also known working is adding 'blank.img' as a '-drive'.
46
47Historical NOTE(smoser) about virtio:
48What is not working is virtio. I have not successfully gotten virtio network
49or virtio disk working.

Subscribers

People subscribed via source and target branches