Revision fcae4e91 snf-image-host/snf-image-update-helper.in
b/snf-image-host/snf-image-update-helper.in | ||
---|---|---|
123 | 123 |
echo -n "Allocating space for helper disk image..." |
124 | 124 |
helper_img=$(mktemp "$HELPER_DIR/image.XXXXXX") |
125 | 125 |
|
126 |
dd if=/dev/zero of="$helper_img" bs=1k count=800000 &> /dev/null
|
|
126 |
dd if=/dev/zero of="$helper_img" bs=1k count=400000 &> /dev/null
|
|
127 | 127 |
echo "done" |
128 | 128 |
|
129 | 129 |
echo "Creating partitions..." |
... | ... | |
142 | 142 |
# The helper vm should never do filesystem checks... |
143 | 143 |
tune2fs -i 0 -c 0 "$root_dev" 2>&1 | sed -e 's/^/TUNE2FS: /g' |
144 | 144 |
|
145 |
blkid=$(blkid -s UUID -o value $root_dev)
|
|
145 |
root_uuid=$(blkid -s UUID -o value "$root_dev")
|
|
146 | 146 |
|
147 | 147 |
target=$(mktemp -d) |
148 | 148 |
add_cleanup rmdir "$target" |
... | ... | |
212 | 212 |
# /etc/fstab: static file system information. |
213 | 213 |
# |
214 | 214 |
# <file system> <mount point> <type> <options> <dump> <pass> |
215 |
UUID=$blkid / ext3 defaults 0 1
|
|
215 |
UUID=$root_uuid / ext3 defaults 0 1
|
|
216 | 216 |
proc /proc proc defaults 0 0 |
217 | 217 |
EOF |
218 | 218 |
echo "done" |
219 | 219 |
|
220 |
echo -n "Extracting kernel..." |
|
221 |
if [ ! -L "$target/vmlinuz" -o ! -L "$target/vmlinuz" ]; then |
|
222 |
echo -e "\033[1;31mfailed\033[0m" |
|
223 |
log_error "vmlinuz or initrd.img link in root is missing." |
|
224 |
log_error "I don't know how to find a usable kernel/initrd pair." |
|
225 |
exit 1 |
|
226 |
fi |
|
227 |
echo "done" |
|
220 | 228 |
|
229 |
kernel=$(readlink -en "$target/vmlinuz") |
|
230 |
initrd=$(readlink -en "$target/initrd.img") |
|
221 | 231 |
|
232 |
echo "Moving $(basename "$kernel") and $(basename "$initrd") to \`$HELPER_DIR'" |
|
233 |
mv "$kernel" "$initrd" "$HELPER_DIR" |
|
222 | 234 |
|
223 |
setup_image() { |
|
224 |
# setup_image pkg suffix |
|
225 |
|
|
226 |
echo "Getting linux image $1" |
|
227 |
chroot "$target" apt-get install -y --force-yes -qq "$1" &>/dev/null |
|
228 |
|
|
229 |
echo -n "Extracting kernel..." |
|
230 |
if [ ! -L "$target/vmlinuz" -o ! -L "$target/vmlinuz" ]; then |
|
231 |
echo -e "\033[1;31mfailed\033[0m" |
|
232 |
log_error "vmlinuz or initrd.img link in root is missing." |
|
233 |
log_error "I don't know how to find a usable kernel/initrd pair." |
|
234 |
exit 1 |
|
235 |
fi |
|
236 |
echo "done" |
|
237 |
|
|
238 |
kernel=$(readlink -en "$target/vmlinuz") |
|
239 |
initrd=$(readlink -en "$target/initrd.img") |
|
240 |
|
|
241 |
echo "Moving $(basename "$kernel") and $(basename "$initrd") to \`$HELPER_DIR'" |
|
242 |
mv "$kernel" "$initrd" "$HELPER_DIR" |
|
243 |
|
|
244 |
kernel=$(basename "$kernel") |
|
245 |
initrd=$(basename "$initrd") |
|
246 |
|
|
247 |
( |
|
248 |
cd "$HELPER_DIR"; |
|
249 |
ln -fs "$kernel" kernel$2; |
|
250 |
ln -fs "$initrd" initrd$2; |
|
251 |
) |
|
252 |
|
|
253 |
rm "$target/vmlinuz" "$target/initrd.img" |
|
254 |
|
|
255 |
} |
|
256 |
|
|
235 |
kernel=$(basename "$kernel") |
|
236 |
initrd=$(basename "$initrd") |
|
257 | 237 |
|
258 |
setup_image $HELPER_LINUX_IMAGE_PKG "" |
|
259 |
setup_image $HELPER_LINUX_IMAGE_XEN_PKG "-xen" |
|
238 |
(cd "$HELPER_DIR"; ln -fs "$kernel" kernel; ln -fs "$initrd" initrd) |
|
260 | 239 |
|
240 |
rm "$target/vmlinuz" "$target/initrd.img" |
|
261 | 241 |
|
262 | 242 |
echo "Installing snf-image-helper pkg in the new image..." |
263 | 243 |
cp "$HELPER_PKG" "$target/tmp/" |
... | ... | |
283 | 263 |
echo "WARNING: NOT calling snf-image-helper, add snf_image_activate_helper" |
284 | 264 |
echo "to the kernel command line if you want to do so." |
285 | 265 |
else |
286 |
for x in \$(cat /proc/cmdline); do |
|
287 |
case x in |
|
288 |
hypervisor*) eval \$x |
|
289 |
;; |
|
290 |
esac |
|
291 |
done |
|
292 |
case \$hypervisor in |
|
293 |
xen-pvm|xen-hvm) |
|
294 |
mount -t xenfs xenfs /proc/xen |
|
295 |
iptables -P OUTPUT DROP |
|
296 |
ip6tables -P OUTPUT DROP |
|
297 |
ip link set eth0 up |
|
298 |
;; |
|
299 |
esac |
|
300 | 266 |
/usr/bin/snf-image-helper --force |
301 | 267 |
fi |
302 | 268 |
|
Also available in: Unified diff