Hello all,
As I started to learn CHEF, to install 'Chef Workstation' on my Virtual env, I discover Chef/Bento which help me to easily build VM from scratch following my customization rules .
I started with success with Virtual box but I would also try KVM/QEMU.
To imitate VM design of my company, I would just like to keep a boot disk with mainly the OS matters and a second one with all other middle-ware and data.
As 'packer' already foreseen this 'disk_additional_size' option for this kind of purpose, I just ad very few line to add a variable def:
variable "qemu_disk_additional_size" {
type = list(string)
default = null
}
to enhance the source def of qemu vm:
source "qemu" "vm" {
# QEMU specific options
[...]
disk_size = var.disk_size
disk_additional_size = var.qemu_disk_additional_size == null ? [] : var.qemu_disk_additional_size
floppy_files = local.floppy_files
[...]
and add requirement in my box setup:
[...]
qemu_disk_additional_size = [ "69632M" ]
#qemu_disk_additional_size = [ "68G" ]
[...]
(i.e. the same kind of tips to build successfully a custom vbox )
'packer' create well the qemu vm with the 2 requested disks.
(as it's a 15min procees I can access the system and check:
Filesystem Size Used Avail Use% Mounted on
devtmpfs 968M 0 968M 0% /dev
tmpfs 997M 4.0K 997M 1% /dev/shm
tmpfs 997M 17M 981M 2% /run
tmpfs 997M 0 997M 0% /sys/fs/cgroup
/dev/sr0 988M 988M 0 100% /run/install/repo
/dev/mapper/live-rw 2.0G 1.6G 386M 81% /
tmpfs 997M 892K 997M 1% /tmp
/dev/mapper/rootvg-root 8.0G 802M 7.3G 10% /mnt/sysimage
/dev/mapper/localvg-house_apps 509M 26M 483M 6% /mnt/sysimage/house_apps
/dev/mapper/localvg-house_apps_data 509M 26M 483M 6% /mnt/sysimage/house_apps_data
/dev/vda2 2.0G 43M 2.0G 3% /mnt/sysimage/boot
/dev/vda1 1022M 12K 1022M 1% /mnt/sysimage/boot/efi
tmpfs 997M 0 997M 0% /mnt/sysimage/dev/shm
/dev/mapper/rootvg-home 2.0G 33M 2.0G 2% /mnt/sysimage/home
/dev/mapper/rootvg-opt 2.0G 33M 2.0G 2% /mnt/sysimage/opt
/dev/mapper/localvg-bakups 1.5G 33M 1.5G 3% /mnt/sysimage/opt/mdwr/bakups
/dev/mapper/localvg-sys_house_apps 509M 26M 483M 6% /mnt/sysimage/sys_house_apps
/dev/mapper/localvg-security 1014M 33M 982M 4% /mnt/sysimage/sys_house_apps/security
/dev/mapper/localvg-moneymaker 1014M 33M 982M 4% /mnt/sysimage/sys_house_apps/moneymaker
/dev/mapper/localvg-mdwr 4.0G 33M 4.0G 1% /mnt/sysimage/sys_house_apps/mdwr
/dev/mapper/rootvg-tmp 2.0G 33M 2.0G 2% /mnt/sysimage/tmp
/dev/mapper/rootvg-stage_area 4.0G 33M 4.0G 1% /mnt/sysimage/stage_area
/dev/mapper/rootvg-var 4.0G 128M 3.9G 4% /mnt/sysimage/var
/dev/mapper/rootvg-syslogs 4.0G 33M 4.0G 1% /mnt/sysimage/var/log
but at the end:
oskvm (pts14)jlst@oskvm:/Extra/vguest_img/IMGs02/Vagrant/osxfce_bento-rudy |\
$ packer build -force -on-error=ask -only=qemu.vm -var-file=os_pkrvars/centos/rudy-UTS-centos7-efi-x86_64.pkrvars.hcl ./packer_templates
[...]
==> qemu.vm: Provisioning with shell script: ./packer_templates/scripts/_common/minimize.sh
==> qemu.vm: + case "$PACKER_BUILDER_TYPE" in
==> qemu.vm: + exit 0
==> qemu.vm: Gracefully halting virtual machine...
==> qemu.vm: Converting hard drive...
==> qemu.vm: Running post-processor: (type vagrant)
==> qemu.vm (vagrant): Creating a dummy Vagrant box to ensure the host system can create one correctly
==> qemu.vm (vagrant): Creating Vagrant box for 'libvirt' provider
qemu.vm (vagrant): Copying from artifact: builds/packer-centos-7.9-x86_64-qemu/centos-7.9-amd64
qemu.vm (vagrant): Compressing: Vagrantfile
qemu.vm (vagrant): Compressing: box.img
qemu.vm (vagrant): Compressing: metadata.json
Build 'qemu.vm' finished after 13 minutes 58 seconds.
==> Wait completed after 13 minutes 58 seconds
==> Builds finished. The artifacts of successful builds are:
--> qemu.vm: 'libvirt' provider box: ./packer_templates/../builds/centos-7.9-x86_64.libvirt.box
i.e. only the first disk is set in the 'box'
oskvm (pts14)jlst@oskvm:/Extra/vguest_img/IMGs02/Vagrant/osxfce_bento-rudy |\
$ ls -lh ./builds/centos-7.9-x86_64.libvirt.box
-rw-r--r-- 1 jlst sysadmin 583M Aug 23 10:08 ./builds/centos-7.9-x86_64.libvirt.box
oskvm (pts14)jlst@oskvm:/Extra/vguest_img/IMGs02/Vagrant/osxfce_bento-rudy |\
$ tar -tslpvf ./builds/centos-7.9-x86_64.libvirt.box
-rw-r--r-- jlst/sysadmin 296 2023-08-23 10:07 Vagrantfile
-rw-r--r-- jlst/sysadmin 1403584512 2023-08-23 10:07 box.img
-rw-r--r-- jlst/sysadmin 58 2023-08-23 10:07 metadata.json
oskvm (pts14)jlst@oskvm:/Extra/vguest_img/IMGs02/Vagrant/osxfce_bento-rudy |\
$ tar -xslpvf ./builds/centos-7.9-x86_64.libvirt.box Vagrantfile
Vagrantfile
oskvm (pts14)jlst@oskvm:/Extra/vguest_img/IMGs02/Vagrant/osxfce_bento-rudy |\
$ cat Vagrantfile
# The contents below were provided by the Packer Vagrant post-processor
Vagrant.configure("2") do |config|
config.vm.provider :libvirt do |libvirt|
libvirt.driver = "kvm"
end
end
# The contents below (if any) are custom contents provided by the
# Packer template during image build.
on the contrary of Virtualbox:
[...]
==> virtualbox-iso.vm (vagrant): Creating a dummy Vagrant box to ensure the host system can create one correctly
==> virtualbox-iso.vm (vagrant): Creating Vagrant box for 'virtualbox' provider
virtualbox-iso.vm (vagrant): Copying from artifact: builds/packer-centos-7.9-x86_64-virtualbox/centos-7.9-amd64-disk001.vmdk
virtualbox-iso.vm (vagrant): Copying from artifact: builds/packer-centos-7.9-x86_64-virtualbox/centos-7.9-amd64-disk002.vmdk
virtualbox-iso.vm (vagrant): Copying from artifact: builds/packer-centos-7.9-x86_64-virtualbox/centos-7.9-amd64.ovf
virtualbox-iso.vm (vagrant): Renaming the OVF to box.ovf...
virtualbox-iso.vm (vagrant): Compressing: Vagrantfile
virtualbox-iso.vm (vagrant): Compressing: box.ovf
virtualbox-iso.vm (vagrant): Compressing: centos-7.9-amd64-disk001.vmdk
virtualbox-iso.vm (vagrant): Compressing: centos-7.9-amd64-disk002.vmdk
virtualbox-iso.vm (vagrant): Compressing: metadata.json
Build 'virtualbox-iso.vm' finished after 6 minutes 33 seconds.
==> Wait completed after 6 minutes 33 seconds
==> Builds finished. The artifacts of successful builds are:
--> virtualbox-iso.vm: 'virtualbox' provider box: ./packer_templates/../builds/centos-7.9-x86_64.virtualbox.box
osxfce154 (pts89)jlst@osxfce154:/Extra/Vagrant.d/jlst/Develop/Vagrant/bento-rudy |\
$ ls -l ./builds/centos-7.9-x86_64.virtualbox.box
centos-7.9-x86_64.virtualbox.box
osxfce154 (pts89)jlst@osxfce154:/Extra/Vagrant.d/jlst/Develop/Vagrant/bento-rudy |\
$ ls -l ./builds/centos-7.9-x86_64.virtualbox.box
-rw-r--r-- 1 jlst sysadmins 689407205 Aug 20 12:22 ./builds/centos-7.9-x86_64.virtualbox.box
Any idea where should I start to investigate : bento, vagrant, packer, ...?
Tia for further advises,
Rudy