User Tools

Site Tools


create_box_ubuntu

Differences

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

Link to this comparison view

create_box_ubuntu [2025/07/26 17:09] – - Imported by DokuWiki Advanced Plugin wikiadmcreate_box_ubuntu [Unknown date] (current) – removed - external edit (Unknown date) 127.0.0.1
Line 1: Line 1:
-====== Criando box Ubuntu - libvirt ====== 
-===== Instalando a vm ===== 
-<file bash> 
-$ sudo virt-install \ 
---name ubuntu22 \ 
---description="Ubuntu Server 22.04" \ 
---ram 2048 \ 
---vcpus 2 \ 
---disk size=32,format=qcow2 \ 
---cdrom /datastore/imagens/isos/ubuntu-22.04.1-live-server-amd64.iso \ 
---virt-type kvm \ 
---os-type=Linux \ 
---os-variant=ubuntu20.04 \ 
---graphics vnc,listen=0.0.0.0 \ 
---noautoconsole 
-</file> 
  
-===== Configurando a VM ===== 
-<file bash> 
-$ sudo virsh domifaddr ubuntu22 
- Nome       Endereço MAC        Protocol     Address 
-------------------------------------------------------------------------------- 
- vnet0      52:54:00:52:65:3f    ipv4         192.168.122.8/24 
-</file> 
- 
-<file bash> 
-$ ssh vagrant@192.168.122.8 
-</file> 
- 
-===== Configuração do sudo ===== 
-<file bash> 
-$ sudo echo 'vagrant ALL=(ALL) NOPASSWD:ALL' >/etc/sudoers.d/99_vagrant 
-$ sudo chmod 440 /etc/sudoers.d/99_vagrant 
-</file> 
- 
-===== Configuração de rede ===== 
-<file sh networking.sh> 
-# $ vim /tmp/networking.sh 
-#!/bin/sh -eux 
- 
-ubuntu_version="`lsb_release -r | awk '{print $2}'`"; 
-major_version="`echo $ubuntu_version | awk -F. '{print $1}'`"; 
- 
-if [ "$major_version" -ge "18" ]; then 
-echo "Create netplan config for eth0" 
-cat <<EOF >/etc/netplan/01-netcfg.yaml; 
-network: 
-  version: 2 
-  ethernets: 
-    eth0: 
-      dhcp4: true 
-EOF 
-else 
-  # Adding a 2 sec delay to the interface up, to make the dhclient happy 
-  echo "pre-up sleep 2" >> /etc/network/interfaces; 
-fi 
- 
-# Disable Predictable Network Interface names and use eth0 
-[ -e /etc/network/interfaces ] && 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; 
-</file> 
- 
-<file bash> 
-$ sudo bash /tmp/networking.sh 
-</file> 
- 
-===== Removendo arquivo temporários e logs ===== 
-<file bash> 
-$ sudo find /var/cache -type f -exec rm -rf {} \; 
-$ sudo find /var/log -type f -exec truncate --size=0 {} \; 
-$ sudo truncate -s 0 /etc/machine-id 
-$ sudo rm -rf /tmp/* /var/tmp/* 
-$ sudo rm -f /var/lib/systemd/random-seed 
-$ export HISTSIZE=0 
-</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.8 
-</file> 
- 
-<file bash> 
-$ chmod 0600 vagrant 
-$ ssh -i vagrant vagrant@192.168.122.8 
-</file> 
- 
-===== Criando a box ===== 
-<file bash> 
-$ sudo virsh shutdown ubuntu22 
-$ wget https://raw.githubusercontent.com/vagrant-libvirt/vagrant-libvirt/master/tools/create_box.sh 
-$ sudo bash create_box.sh /datastore/imagens/ubuntu22.qcow2 
-</file> 
- 
-===== Publicando uma box ===== 
- 
-<file bash> 
-$ vagrant cloud publish g3anmart1ns/ubuntu22 1.0 libvirt ubuntu22.box \ 
---description "Ubuntu Server 22.04" \ 
---version-description "Ubuntu Server 22.04 mínima" \ 
---release --no-private 
-</file> 
- 
-===== Testando a box ===== 
-<file ruby Vagrantfile> 
-# -*- mode: ruby -*- 
-# vi: set ft=ruby : 
-  
-ENV['VAGRANT_DEFAULT_PROVIDER'] = 'libvirt' 
-  
-Vagrant.configure("2") do |config| 
-  config.vm.define :ubuntu22 do |ubuntu22| 
-    ubuntu22.vm.box = "g3anmart1ns/ubuntu22" 
-    ubuntu22.vm.hostname = "vm-01" 
-  
-    ubuntu22.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> 
create_box_ubuntu.1753560543.txt.gz · Last modified: by wikiadm