우분투 KVM

https://help.ubuntu.com/community/KVM

우분투 리눅스의 Kernel vertual machine으로 다른 OS를 설치하는 문서.

아래는 2021년 1월 30일 추가하였음.

우분투 20.04에 kvm 설치하고 브릿지 네트워크 설정하는 방법.

설치환경 확인

버전확인.

# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 20.04.1 LTS
Release:        20.04
Codename:       focal

만약 아래 명령의 결과가 0이라면 CPU가 가상환경을 지원하지 않는다. 1이면 BIOS에서 가상머신을 지원하도록 설정해야한다.

# egrep -c '(vmx|svm)' /proc/cpuinfo
64

kvm-ok 명령으로 KVM을 지원하는지 확인한다. 만약, kvm-ok 명령을 찾지 못한다면, cpu-checker 패키지를 설치한다.

# kvm-ok
[sudo] password for snowfox:
INFO: /dev/kvm exists
KVM acceleration can be used

KVM 설치

# apt-get install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virt-manager

systemd에 등록되어있는지 확인해 본다.

# systemctl status libvirtd
● libvirtd.service - Virtualization daemon
     Loaded: loaded (/lib/systemd/system/libvirtd.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2021-01-28 17:04:28 KST; 5min ago
TriggeredBy: ● libvirtd-ro.socket
             ● libvirtd-admin.socket
             ● libvirtd.socket
       Docs: man:libvirtd(8)
             https://libvirt.org
   Main PID: 3974 (libvirtd)
      Tasks: 19 (limit: 32768)
     Memory: 38.2M
     CGroup: /system.slice/libvirtd.service
             ├─3974 /usr/sbin/libvirtd
             ├─4122 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp>
             └─4123 /usr/sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default.conf --leasefile-ro --dhcp>

Jan 28 17:04:28 machine7 dnsmasq[4122]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lu>
Jan 28 17:04:28 machine7 dnsmasq-dhcp[4122]: DHCP, IP range 192.168.122.2 -- 192.168.122.254, lease time 1h
Jan 28 17:04:28 machine7 dnsmasq-dhcp[4122]: DHCP, sockets bound exclusively to interface virbr0
Jan 28 17:04:28 machine7 dnsmasq[4122]: reading /etc/resolv.conf
Jan 28 17:04:28 machine7 dnsmasq[4122]: using nameserver 127.0.0.53#53
Jan 28 17:04:28 machine7 dnsmasq[4122]: read /etc/hosts - 7 addresses
Jan 28 17:04:28 machine7 dnsmasq[4122]: read /var/lib/libvirt/dnsmasq/default.addnhosts - 0 addresses
Jan 28 17:04:28 machine7 dnsmasq-dhcp[4122]: read /var/lib/libvirt/dnsmasq/default.hostsfile
Jan 28 17:04:28 machine7 dnsmasq[4122]: reading /etc/resolv.conf
Jan 28 17:04:28 machine7 dnsmasq[4122]: using nameserver 127.0.0.53#53

만약 실행되고 있지 않고, 재부팅시 실행되지 않는다면, 아래 명령으로 등록하고 시작해준다.

# systemctl enable libvirtd
# systemctl start libvirtd

네트워크 설정
만약에, 게스트 OS를 호스트어댑터가 사용하는 네트워크에 붙여 사용하고자 한다면, 네트워크 인터페이스를 브릿지로 만들어야한다.

먼저 현재 구성을 확인한다.

# ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
    link/ether 94:40:c9:ec:9f:f8 brd ff:ff:ff:ff:ff:ff
    inet 172.16.100.227/24 brd 172.16.100.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::9640:c9ff:feec:9ff8/64 scope link
       valid_lft forever preferred_lft forever
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
    link/ether 94:40:c9:ec:9f:f9 brd ff:ff:ff:ff:ff:ff

...

10: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:b7:fb:4a brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:b7:fb:4a brd ff:ff:ff:ff:ff:ff

현재 네트워크 설정 확인하고, eno1을 브릿지로 만든다.
/etc/netplan 디렉토리에서 관련 파일 확인한다.

$ more 00-installer-config.yaml
# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      addresses:
      - 172.16.100.227/24
      gateway4: 172.16.100.1
      nameservers:
        addresses:
        - 8.8.8.8
  version: 2

이제 아래처럼 변경하고 적용한다.

# This is the network config written by 'subiquity'
network:
  ethernets:
    eno1:
      #addresses:
      #- 172.16.100.227/24
      #gateway4: 172.16.100.1
      #nameservers:
      #  addresses:
      #  - 8.8.8.8
      dhcp4: false
      dhcp6: false

  bridges:
    br0:
      interfaces:
      - eno1
      addresses:
      - 172.16.100.227/24
      gateway4: 172.16.100.1
      nameservers:
        addresses:
        - 172.16.100.21
      parameters:
        stp: true
        forward-delay: 4
  version: 2

netplan apply 명령으로 적용하고 확인하면 br0가 생성되었다.

$ ip addr
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq master br0 state UP group default qlen 1000
link/ether 94:40:c9:ec:9f:f8 brd ff:ff:ff:ff:ff:ff
3: eno2: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 94:40:c9:ec:9f:f9 brd ff:ff:ff:ff:ff:ff
4: eno3: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 94:40:c9:ec:9f:fa brd ff:ff:ff:ff:ff:ff
5: eno4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 94:40:c9:ec:9f:fb brd ff:ff:ff:ff:ff:ff
6: ens12f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 48:df:37:b2:4f:38 brd ff:ff:ff:ff:ff:ff
7: ens12f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 48:df:37:b2:4f:39 brd ff:ff:ff:ff:ff:ff
8: ens11f0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 48:df:37:b2:4f:3e brd ff:ff:ff:ff:ff:ff
9: ens11f1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000
link/ether 48:df:37:b2:4f:3f brd ff:ff:ff:ff:ff:ff
10: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
link/ether 52:54:00:b7:fb:4a brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
valid_lft forever preferred_lft forever
11: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
link/ether 52:54:00:b7:fb:4a brd ff:ff:ff:ff:ff:ff
12: br0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether 94:40:c9:ec:9f:f8 brd ff:ff:ff:ff:ff:ff
inet 172.16.100.227/24 brd 172.16.100.255 scope global br0
valid_lft forever preferred_lft forever
inet6 fe80::9640:c9ff:feec:9ff8/64 scope link
valid_lft forever preferred_lft forever

이제, virt-manager를 실행하여 게스트 OS를 만들면 된다.

답글 남기기

Your email address will not be published.