Created
September 22, 2025 16:12
-
-
Save eduardomazolini/a83b111a93904f209202e41060d51638 to your computer and use it in GitHub Desktop.
Cria um VM usando debian13, console serial, cloud-init no disco lvm. Edite para sua necessidade.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| set -e | |
| VMID=1021 | |
| IMAGE="debian-13-genericcloud-amd64-custom.qcow2" | |
| # Senha | |
| SENHA="Mude a senha que esta aqui" | |
| # Verificar se a imagem existe | |
| if [ ! -f "$IMAGE" ]; then | |
| echo "Erro: Imagem $IMAGE não encontrada!" | |
| exit 1 | |
| fi | |
| # 1. Criar VM base (sem discos) | |
| qm create $VMID --name debian13-custom --memory 2024 --cores 1 --cpu host --agent enabled=1,fstrim_cloned_disks=1 | |
| # 2. BIOS e hardware básico (sem EFI ainda) | |
| qm set $VMID --scsihw virtio-scsi-pci | |
| qm set $VMID --bios ovmf | |
| qm set $VMID --ostype l26 | |
| qm set $VMID --balloon 1024 | |
| # 3. Console serial | |
| qm set $VMID --serial0 socket | |
| qm set $VMID --vga serial0 | |
| # 4. Rede | |
| qm set $VMID --net0 virtio,bridge=vmbr0 | |
| # 5. IMPORTAR o disco PRIMEIRO (criará disk-0) | |
| qm importdisk $VMID $IMAGE local-lvm | |
| qm set $VMID --virtio0 local-lvm:vm-$VMID-disk-0,discard=on,iothread=1 | |
| # 6. AGORA criar EFI (criará disk-1) | |
| qm set $VMID --efidisk0 local-lvm:0,efitype=4m,pre-enrolled-keys=1,format=raw | |
| # 7. Cria o cloud-init CD | |
| qm set $VMID --ide2 local-lvm:cloudinit | |
| # 8. Configura Cloud-Init | |
| qm set $VMID --ciuser emazolini | |
| qm set $VMID --cipassword "$SENHA" | |
| qm set $VMID --sshkeys sshkeys.pub | |
| qm set $VMID --ipconfig0 ip=dhcp | |
| qm set $VMID --nameserver 8.8.8.8,1.1.1.1 | |
| echo "VM $VMID criada com sucesso!" | |
| echo "=== Configuração final ===" | |
| qm config $VMID | |
| echo "=== Verificação de storage ===" | |
| pvesm list local-lvm | grep vm-$VMID |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment