Skip to Content
문서개발가상 머신 및 컨테이너

가상 머신 및 컨테이너

이 기사에서는 Ubuntu 26.04에서 사용할 수 있는 다양한 가상화 및 시스템 컨테이너 기술을 다룹니다.

하드웨어 가상화 지원 확인

시작하기 전에 CPU가 하드웨어 가상화를 지원하는지 확인하세요.

# Check for virtualization support egrep -c '(vmx|svm)' /proc/cpuinfo

0보다 큰 결과는 지지를 나타냅니다. cpu-checker을 사용할 수도 있습니다.

sudo apt install cpu-checker -y kvm-ok

KVM / QEMU

KVM(Kernel-based Virtual Machine)은 Linux 커널에 내장된 가상화 솔루션입니다. QEMU와 결합되어 완전한 가상화 기능을 제공합니다.

KVM 및 관련 도구 설치

sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager -y

현재 사용자를 필수 그룹에 추가합니다.

sudo usermod -aG libvirt $USER sudo usermod -aG kvm $USER

그룹 변경 사항을 적용하려면 로그아웃했다가 다시 로그인하세요.

설치 확인

# Check libvirt service status sudo systemctl status libvirtd # Verify connection virsh list --all

virt-manager(GUI) 사용

virt-manager

virt-manager는 가상 머신 생성 및 관리를 위한 직관적인 그래픽 인터페이스를 제공합니다.

명령줄을 통해 VM 만들기

# Create a disk image qemu-img create -f qcow2 /var/lib/libvirt/images/ubuntu-vm.qcow2 40G # Install a VM from ISO virt-install \ --name ubuntu-vm \ --ram 4096 \ --vcpus 2 \ --disk path=/var/lib/libvirt/images/ubuntu-vm.qcow2,size=40 \ --os-variant ubuntu26.04 \ --network bridge=virbr0 \ --graphics vnc \ --cdrom /path/to/ubuntu-26.04-desktop-amd64.iso
Note

osinfo-query os | grep ubuntu을 실행하여 로컬 osinfo-db에 ubuntu26.04이 포함되어 있는지 확인하세요. 그렇지 않은 경우 osinfo-db를 업그레이드하거나 가장 가까운 ubuntu24.04으로 대체하거나 --osinfo detect=on,require=off를 사용하여 virt-install이 자동 감지하도록 하세요.

일반적인 virsh 명령

# List all VMs virsh list --all # Start a VM virsh start ubuntu-vm # Shut down a VM virsh shutdown ubuntu-vm # Force stop virsh destroy ubuntu-vm # Suspend and resume virsh suspend ubuntu-vm virsh resume ubuntu-vm # Create snapshots virsh snapshot-create-as ubuntu-vm --name "clean-install" virsh snapshot-list ubuntu-vm virsh snapshot-revert ubuntu-vm --snapshotname "clean-install" # Delete a VM virsh undefine ubuntu-vm --remove-all-storage

QEMU 직접 사용

libvirt 없이 QEMU를 직접 사용:

# Create a disk qemu-img create -f qcow2 disk.qcow2 20G # Start a VM qemu-system-x86_64 \ -enable-kvm \ -m 4G \ -smp 2 \ -hda disk.qcow2 \ -cdrom ubuntu.iso \ -boot d \ -net nic -net user,hostfwd=tcp::2222-:22

버추얼박스

VirtualBox는 깔끔한 그래픽 인터페이스를 갖춘 Oracle의 오픈 소스 가상화 소프트웨어입니다.

버추얼박스 설치

# Method 1: Install from Ubuntu repository sudo apt install virtualbox -y # Method 2: Install from Oracle's official repository (newer version) wget -qO- https://www.virtualbox.org/download/oracle_vbox_2016.asc | sudo gpg --dearmor -o /etc/apt/keyrings/oracle-virtualbox.gpg echo "deb [arch=amd64 signed-by=/etc/apt/keyrings/oracle-virtualbox.gpg] https://download.virtualbox.org/virtualbox/debian $(lsb_release -cs) contrib" | sudo tee /etc/apt/sources.list.d/virtualbox.list sudo apt update # Install VirtualBox (run apt-cache search virtualbox to confirm the current # available package name, e.g. virtualbox-7.1 or a newer version) sudo apt install virtualbox-7.1 -y

확장 팩 설치

확장 팩은 USB 3.0, RDP 원격 데스크톱 및 기타 기능을 제공합니다.

# Install the extension pack after downloading the matching version sudo VBoxManage extpack install Oracle_VirtualBox_Extension_Pack-*.vbox-extpack

VBoxManage 명령줄

# List VMs VBoxManage list vms # Start a VM (headless mode) VBoxManage startvm "vm-name" --type headless # Shut down a VM VBoxManage controlvm "vm-name" acpipowerbutton # Create a snapshot VBoxManage snapshot "vm-name" take "snapshot-name"

LXD / LXC 시스템 컨테이너

LXC는 Linux 컨테이너 기술이고 LXD은 관리 데몬으로 VM과 유사한 경험을 제공하지만 더 가볍습니다.

LXD 설치

sudo snap install lxd

LXD 초기화

lxd init --minimal

또는 더 많은 옵션을 보려면 대화형 구성을 사용하세요.

lxd init

LXD 기본 작업

# Launch an Ubuntu container lxc launch ubuntu:26.04 mycontainer # Launch a VM (yes, LXD supports VMs too) lxc launch ubuntu:26.04 myvm --vm # List instances lxc list # Enter a container lxc exec mycontainer -- bash # Push and pull files lxc file push local-file.txt mycontainer/root/ lxc file pull mycontainer/root/file.txt . # Stop and delete lxc stop mycontainer lxc delete mycontainer # Create snapshots lxc snapshot mycontainer snap0 lxc restore mycontainer snap0

LXD 프로필 구성

# View default profile lxc profile show default # Create a custom profile lxc profile create dev-profile lxc profile set dev-profile limits.cpu 4 lxc profile set dev-profile limits.memory 8GB # Launch a container with a custom profile lxc launch ubuntu:26.04 devbox --profile dev-profile

침골

Incus는 Linux Containers 커뮤니티에서 유지관리하는 LXD의 커뮤니티 포크입니다. 유사한 기능을 가지고 있지만 독립적으로 개발되었습니다.

인커스 설치

# Add the Zabbly repository (officially recommended for Incus) curl -fsSL https://pkgs.zabbly.com/key.asc | sudo gpg --dearmor -o /etc/apt/keyrings/zabbly.gpg echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/zabbly.gpg] https://pkgs.zabbly.com/incus/stable $(. /etc/os-release && echo "$VERSION_CODENAME") main" | sudo tee /etc/apt/sources.list.d/zabbly-incus-stable.list sudo apt update sudo apt install incus -y

초기화 및 사용

# Initialize sudo incus admin init --minimal # Add user to the incus-admin group sudo usermod -aG incus-admin $USER newgrp incus-admin # Usage is similar to LXD incus launch images:ubuntu/26.04 mycontainer incus list incus exec mycontainer -- bash incus stop mycontainer incus delete mycontainer

LXD에서 Incus로 마이그레이션

sudo incus admin migrate-lxd

기술 비교

특징KVM/QEMU버추얼박스LXD/인커스
가상화 유형전체 가상화전체 가상화시스템 컨테이너/VM
성능가까운 원주민좋은가까운 원주민
격리강한강한중간(컨테이너) / 강력(VM)
자원 사용량중간더 높은낮음(컨테이너)
사용 사례서버, 프로덕션데스크탑 개발/테스트개발 환경, 경량 격리

사용 사례에 따라 올바른 가상화 접근 방식을 선택하세요. 프로덕션 서버용 KVM, 데스크톱 사용자용 VirtualBox, 개발 격리 환경용 LXD 또는 Incus.