$ sudo virt-install \ --name debian11 \ --description="Debian 11 - bullseye" \ --ram 2048 \ --vcpus 2 \ --disk size=32,format=qcow2 \ --cdrom /datastore/imagens/isos/debian-11.3.0-amd64-netinst.iso \ --virt-type kvm \ --os-type=Linux \ --os-variant=debian10 \ --graphics vnc,listen=0.0.0.0 \ --noautoconsole
foi feito uma instalação mínima do Debian, apenas o pacote do SSH foi selecionado para instalação.
$ sudo virsh domifaddr debian11 Nome Endereço MAC Protocol Address ------------------------------------------------------------------------------- vnet0 52:54:00:c5:71:ab ipv4 192.168.122.106/24
$ ssh vagrant@192.168.122.106 The authenticity of host '192.168.122.106 (192.168.122.106)' can't be established. ECDSA key fingerprint is SHA256:0x8BllzbuyMuQKEM/C19XLjYwbaHzrDg255bLPz5YJQ. ECDSA key fingerprint is MD5:37:1a:8b:59:59:ac:26:44:70:c8:cd:0e:2a:3a:f5:1b. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added '192.168.122.106' (ECDSA) to the list of known hosts. vagrant@192.168.122.106's password: Linux debian 5.10.0-17-amd64 #1 SMP Debian 5.10.136-1 (2022-08-13) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. vagrant@debian:~$
Usuário e senha vagrant, criados durante a instalação.
vagrant@debian:~$ su - Senha: root@debian:~#
# apt install sudo
# echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/99_vagrant # chmod 440 /etc/sudoers.d/99_vagrant
# sed -i 's/en[[:alnum:]]*/eth0/g' /etc/network/interfaces; # sed -i 's/GRUB_CMDLINE_LINUX="\(.*\)"/GRUB_CMDLINE_LINUX="net.ifnames=0 biosdevname=0 \1"/g' /etc/default/grub; # update-grub; # truncate -s 0 /etc/machine-id
# find /var/log -type f -exec truncate --size=0 {} \; # find /var/cache -type f -exec rm -rf {} \; # rm -rf /tmp/* /var/tmp/* # rm -f /var/lib/systemd/random-seed # history -c
# exit sair vagrant@debian:~$ exit sair Connection to 192.168.122.106 closed.
$ wget https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant $ wget https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub
$ ssh-copy-id -i vagrant.pub vagrant@192.168.122.106 /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "vagrant.pub" /usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys vagrant@192.168.122.106's password: Number of key(s) added: 1 Now try logging into the machine, with: "ssh 'vagrant@192.168.122.106'" and check to make sure that only the key(s) you wanted were added.
$ chmod 0600 vagrant [suporte@mba-vm-03 box]$ ssh -i vagrant vagrant@192.168.122.106 Linux debian 5.10.0-17-amd64 #1 SMP Debian 5.10.136-1 (2022-08-13) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. vagrant@debian:~$
$ export HISTSIZE=0 vagrant@debian:~$ exit sair Connection to 192.168.122.106 closed.
$ sudo virsh shutdown debian11
$ wget https://raw.githubusercontent.com/vagrant-libvirt/vagrant-libvirt/master/tools/create_box.sh
$ sudo bash create_box.sh /datastore/imagens/debian11.qcow2 {32} ==> Creating box, tarring and gzipping ./metadata.json ./Vagrantfile ./box.img gzip: stdout: No space left on device ==> debian11.box created ==> You can now add the box: ==> 'vagrant box add debian11.box --name debian11'
$ vagrant box add debian11.box --name debian11
# -*- mode: ruby -*- # vi: set ft=ruby : ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt' Vagrant.configure("2") do |config| config.vm.define :debian11 do |debian11| debian11.vm.box = "debian11" debian11.vm.hostname = "vm-01" debian11.vm.provider :libvirt do |lv| lv.memory = 2048 lv.cpus = 2 end end config.vm.synced_folder ".", "/vagrant", disabled: true end
$ vagrant up
$ vagrant status Current machine states: debian11 running (libvirt) The Libvirt domain is running. To stop this machine, you can run `vagrant halt`. To destroy the machine, you can run `vagrant destroy`.
$ vagrant ssh debian11 Linux vm-01 5.10.0-17-amd64 #1 SMP Debian 5.10.136-1 (2022-08-13) x86_64 The programs included with the Debian GNU/Linux system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. Last login: Fri Sep 2 15:56:29 2022 from 192.168.122.1 vagrant@vm-01:~$
$ vagrant halt
==> debian11: Attempting graceful shutdown of VM...
$ vagrant destroy
debian11: Are you sure you want to destroy the 'debian11' VM? [y/N] y
==> debian11: Removing domain...
==> debian11: Deleting the machine folder
$ vagrant box remove debian11
$ vagrant cloud publish g3anmart1ns/Debian11 1.0 libvirt debian11.box \ --description "Debian 11 Minimal" \ --version-description "Debian 11 instalação mínima" \ --release --no-private