diff --git a/features.in/build-vm/README b/features.in/build-vm/README index c4c46971..5ad17802 100644 --- a/features.in/build-vm/README +++ b/features.in/build-vm/README @@ -1,3 +1,6 @@ -Эта фича конфигурирует создание образа виртуальной машины (VM). +Эта фича конфигурирует создание образа виртуальной машины (VM) +или тарбола rootfs для использования его на реальном компьютере. Дополняет финальную стадию сборки (lib/, image-scripts.d/). -Требует для работы sudo(8) -- см. тж. doc/vm.txt +Для создания образа виртуальной машины требуется sudo(8) +Для создания тарбола sudo не требуется. +-- см. тж. doc/vm.txt diff --git a/features.in/build-vm/lib/90-build-vm.mk b/features.in/build-vm/lib/90-build-vm.mk index 5fdbe42d..e161fbcf 100644 --- a/features.in/build-vm/lib/90-build-vm.mk +++ b/features.in/build-vm/lib/90-build-vm.mk @@ -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 + qemu-img convert $$VM_COMPRESS -O "$$VM_FORMAT" \ + "$(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) diff --git a/features.in/pack/config.mk b/features.in/pack/config.mk index 88eaf823..fbace003 100644 --- a/features.in/pack/config.mk +++ b/features.in/pack/config.mk @@ -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