Commit 1ef77caf authored by Anton Midyukov's avatar Anton Midyukov Committed by Michael Shigorin

build-vm, pack: implement tar, tar.gz, tar.xz support for vm/* target

build-vm ceases to be a target for building only virtual machine images. Now it can be used to build tarballs designed for installation on real machines. This commit is the result of transferring the required functionality from build-mr (mipsel rootfs) by Ivan Melnikov <iv@altlinux.org>. NB: mike@ strongly objected to this dilution but gave up eventually; the whole kernel/build-vm/tar2fs/pack mess should be split into distinct layers busy with their own responsibilities: 1) a tarball with kernel is done without tar2fs at all (and no build-vm bits should be needed either, maybe it's worth splitting and renaming as "vm" meaning disk image for some armh board is grossly misleading); 2) a tarball with kernel can be further (multi-)packed as, well, (compressed) tarball and a disk image (only the latter one should employ build-vm/tar2fs); 3) compression should be done in pack feature style, preferably described once and not duplicated all over the profile for every single new kind of its output. In the mean time, running into this and moving no further starts to hurt more than it could help.
parent 8e1dd12f
Эта фича конфигурирует создание образа виртуальной машины (VM).
Эта фича конфигурирует создание образа виртуальной машины (VM)
или тарбола rootfs для использования его на реальном компьютере.
Дополняет финальную стадию сборки (lib/, image-scripts.d/).
Требует для работы sudo(8) -- см. тж. doc/vm.txt
Для создания образа виртуальной машины требуется sudo(8)
Для создания тарбола sudo не требуется.
-- см. тж. doc/vm.txt
......@@ -22,18 +22,22 @@ VM_RAWDISK := $(IMAGE_OUTDIR)/$(IMAGE_NAME).raw
VM_FSTYPE ?= ext4
VM_SIZE ?= 0
VM_GZIP_COMMAND ?= gzip
VM_XZ_COMMAND ?= xz -T0
check-sudo:
@if ! type -t sudo >&/dev/null; then \
echo "** error: sudo not available, see doc/vm.txt" >&2; \
fi
check-qemu:
@if ! type -t qemu-img >&/dev/null; then \
echo "** error: qemu-img not available" >&2; \
exit 1; \
fi
prepare-image: check-sudo
@# need to copy $(BUILDDIR)/.work/chroot/.host/qemu* into chroot
@#if qemu is used
@(cd "$(BUILDDIR)/.work/chroot/"; \
tar -rf "$(VM_TARBALL)" ./.host/qemu*) ||:; \
if [ -x /usr/share/mkimage-profiles/bin/tar2fs ]; then \
tar2fs: check-sudo
@if [ -x /usr/share/mkimage-profiles/bin/tar2fs ]; then \
TOPDIR=/usr/share/mkimage-profiles; \
fi; \
if ! sudo $$TOPDIR/bin/tar2fs \
......@@ -43,26 +47,40 @@ prepare-image: check-sudo
exit 1; \
fi
convert-image: prepare-image
prepare-image:
@# need to copy $(BUILDDIR)/.work/chroot/.host/qemu* into chroot
@#if qemu is used
@(cd "$(BUILDDIR)/.work/chroot/"; \
tar -rf "$(VM_TARBALL)" ./.host/qemu*) ||:
convert-image/tar:
mv "$(VM_TARBALL)" "$(IMAGE_OUTPATH)"
convert-image/tar.gz:
$(VM_GZIP_COMMAND) < "$(VM_TARBALL)" > "$(IMAGE_OUTPATH)"
convert-image/tar.xz:
$(VM_XZ_COMMAND) < "$(VM_TARBALL)" > "$(IMAGE_OUTPATH)"
convert-image/img: tar2fs
mv "$(VM_RAWDISK)" "$(IMAGE_OUTPATH)"
convert-image/qcow2 convert-image/qcow2c convert-image/vmdk \
convert-image/vdi convert-image/vhd: check-qemu tar2fs
@VM_COMPRESS=; \
case "$(IMAGE_TYPE)" in \
"img") \
mv "$(VM_RAWDISK)" "$(IMAGE_OUTPATH)"; \
if [ "0$(DEBUG)" -le 1 ]; then rm "$(VM_TARBALL)"; fi; \
exit 0;; \
"vhd") VM_FORMAT="vpc";; \
"qcow2c") VM_FORMAT="qcow2"; VM_COMPRESS="-c";; \
*) VM_FORMAT="$(IMAGE_TYPE)"; \
esac; \
if ! type -t qemu-img >&/dev/null; then \
echo "** error: qemu-img not available" >&2; \
exit 1; \
else \
qemu-img convert $$VM_COMPRESS -O "$$VM_FORMAT" \
"$(VM_RAWDISK)" "$(IMAGE_OUTPATH)"; \
rm "$(VM_RAWDISK)"; \
if [ "0$(DEBUG)" -le 1 ]; then rm "$(VM_TARBALL)"; fi; \
fi
"$(VM_RAWDISK)" "$(IMAGE_OUTPATH)"
post-convert:
@rm -f "$(VM_RAWDISK)"; \
if [ "0$(DEBUG)" -le 1 ]; then rm -f "$(VM_TARBALL)"; fi
convert-image: prepare-image convert-image/$(IMAGE_TYPE) post-convert; @:
run-image-scripts: GLOBAL_CLEANUP_PACKAGES := $(CLEANUP_PACKAGES)
......
......@@ -29,12 +29,18 @@ use/pack/$(1).$(2): use/pack/$(1)
@$$(call set,IMAGE_COMPRESS,$(2))
endef
ifeq (ve,$(IMAGE_CLASS))
$(foreach c,$(VE_ARCHIVES), \
$(eval $(call PACK_containers,$(c))) \
$(foreach z,$(VE_COMPRESSORS), \
$(eval $(call PACK_compressors,$(c),$(z)))))
endif
# virtual machines
VM_EXTS := .img .qcow2 .qcow2c .vdi .vmdk .vhd
# extensions for buld-vm
VM_EXTS := .tar .tar.gz .tar.xz .img .qcow2 .qcow2c .vdi .vmdk .vhd
ifeq (vm,$(IMAGE_CLASS))
$(VM_EXTS:.%=use/pack/%): use/pack; @:
endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment