User Tools

Site Tools


create_box_debian

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

create_box_debian [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadmcreate_box_debian [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== Criando box Debian - libvirt ====== 
-===== Instalando a vm ===== 
-<file bash> 
-$ 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 
-</file> 
  
-FIXME foi feito uma instalação mínima do Debian, apenas o pacote do **//SSH//** foi selecionado para instalação. 
-===== Configurando a VM ===== 
- 
-<file bash> 
-$ sudo virsh domifaddr debian11 
- Nome       Endereço MAC        Protocol     Address 
-------------------------------------------------------------------------------- 
- vnet0      52:54:00:c5:71:ab    ipv4         192.168.122.106/24 
-</file> 
- 
-<file bash> 
-$ 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:~$ 
-</file> 
- 
-FIXME Usuário e senha **//vagrant//**, criados durante a instalação. 
- 
-<file bash> 
-vagrant@debian:~$ su - 
-Senha: 
-root@debian:~# 
-</file> 
- 
-==== Configuração do sudo ==== 
-<file bash> 
-# apt install sudo 
-</file> 
- 
-<file bash> 
-# echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/99_vagrant 
-# chmod 440 /etc/sudoers.d/99_vagrant 
-</file> 
- 
-==== Configuração de rede ==== 
-<file bash> 
-# 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 
-</file> 
- 
-==== Removendo arquivo temporários e logs ==== 
-<file bash> 
-# 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 
-</file> 
- 
-<file bash> 
-# exit 
-sair 
-vagrant@debian:~$ exit 
-sair 
-Connection to 192.168.122.106 closed. 
-</file> 
- 
-==== Configurando as chaves SSH ==== 
-<file bash> 
-$ wget https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant 
-$ wget https://raw.githubusercontent.com/hashicorp/vagrant/master/keys/vagrant.pub 
-</file> 
- 
-<file bash> 
-$ 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. 
-</file> 
- 
-<file bash> 
-$ 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:~$ 
-</file> 
- 
-<file bash> 
-$ export HISTSIZE=0 
-vagrant@debian:~$ exit 
-sair 
-Connection to 192.168.122.106 closed. 
-</file> 
- 
-==== Criando a box ==== 
-<file bash> 
-$ sudo virsh shutdown debian11 
-</file> 
- 
-<file bash> 
-$ wget https://raw.githubusercontent.com/vagrant-libvirt/vagrant-libvirt/master/tools/create_box.sh 
-</file> 
- 
-<file bash> 
-$ 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' 
-</file> 
- 
-==== Testando a box local ==== 
-<file bash> 
-$ vagrant box add debian11.box --name debian11 
-</file> 
- 
-<file ruby Vagrantfile> 
-# -*- 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 
-</file> 
- 
-<file bash> 
-$ vagrant up 
-</file> 
- 
-<file bash> 
-$ 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`. 
-</file> 
- 
-<file bash> 
-$ 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:~$ 
-</file> 
- 
-<file bash> 
-$ vagrant halt 
-==> debian11: Attempting graceful shutdown of VM... 
-</file> 
- 
-<file bash> 
-$ vagrant destroy 
-    debian11: Are you sure you want to destroy the 'debian11' VM? [y/N] y 
-==> debian11: Removing domain... 
-==> debian11: Deleting the machine folder 
-</file> 
- 
-<file bash> 
-$ vagrant box remove debian11 
-</file> 
- 
-==== Publicando uma box ==== 
-<file bash> 
-$ 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 
-</file> 
- 
-===== Referências ===== 
-  - [[https://computingforgeeks.com/create-rocky-linux-8-vagrant-boxes-using-packer/|How To Create Rocky Linux 8 Vagrant Boxes Using Packer]] 
-  - [[https://leyhline.github.io/2019/02/16/creating-a-vagrant-base-box/|Creating a Vagrant Base Box (from Fedora 29 Server, using Libvirt as Provider)]] 
-  - [[https://unix.stackexchange.com/questions/222427/how-to-create-custom-vagrant-box-from-libvirt-kvm-instance|how to create custom vagrant box from libvirt/kvm instance?]] 
create_box_debian.1753560543.txt.gz · Last modified: by wikiadm