PG1X WIKI

My Knowledge Base

User Tools

Site Tools


tech:server:linux:virtualization:kvm-qemu:libvirt:libvirt

Libvirt

Specify Domain Disk Block Device. This case specify LVM Logical Volume.

sudo virsh edit nextcloud1.example.com
    <disk type='block' device='disk'>
      <driver name='qemu' io='native' cache='none' type='raw'/>
      <source dev='/dev/hotaru_data/vol-nextcloud1.example.com-data'/>
      <target dev='vdb' bus='virtio'/>
    </disk>
sudo virsh start nextcloud1.example.com --console
wnoguchi@template:~$ sudo fdisk -l /dev/vdb
Disk /dev/vdb: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

virt-install

virt-install \
  --name gitlab \
  --ram 4096 \
  --disk path=/var/lib/libvirt/images/vol-gitlab.qcow2,format=qcow2,size=20 \
  --vcpus 2 \
  --os-type linux \
  --os-variant ubuntu18.04 \
  --cpu kvm64 \
  --network bridge=br0 \
  --graphics none \
  --console pty,target_type=serial \
  --location 'http://jp.archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/' \
  --extra-args 'console=ttyS0,115200n8 serial'

virt-clone and virt-sysprep difference

virt-clone may not clear any data. history, OpenSSH Host Keys, … virt-clone change MAC address only…?

wnoguchi@nextcloud1:~$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
256 SHA256:1EyxDRCXsUGNR9PwPRVFomhU1iu6cEEvWqiXEJpS9Jg root@template (ECDSA)
wnoguchi@nextcloud1:~$ cat /etc/machine-id
72d37da220d649b7bd2a1ce4dc077b32

It seems virt-sysprep clear above history, OpenSSH Host Keys information, etc.

sudo virt-clone --original template --name nextcloud1.example.com --file /var/lib/libvirt/images/nextcloud1.example.com.qcow2

virt-sysprep similar to Windows Sysprep.

reset VM state.

sudo virt-sysprep -d nextcloud1.example.com --operations defaults,-ssh-userdir
root@hotaru:~# sudo virt-sysprep -d nextcloud1.example.com --operations defaults,-ssh-userdir
[   0.0] Examining the guest ...
[   2.7] Performing "abrt-data" ...
[   2.7] Performing "backup-files" ...
[   3.1] Performing "bash-history" ...
[   3.1] Performing "blkid-tab" ...
[   3.1] Performing "crash-data" ...
[   3.1] Performing "cron-spool" ...
[   3.1] Performing "dhcp-client-state" ...
[   3.1] Performing "dhcp-server-state" ...
[   3.1] Performing "dovecot-data" ...
[   3.1] Performing "logfiles" ...
[   3.2] Performing "machine-id" ...
[   3.2] Performing "mail-spool" ...
[   3.2] Performing "net-hostname" ...
[   3.2] Performing "net-hwaddr" ...
[   3.2] Performing "pacct-log" ...
[   3.2] Performing "package-manager-cache" ...
[   3.2] Performing "pam-data" ...
[   3.2] Performing "passwd-backups" ...
[   3.2] Performing "puppet-data-log" ...
[   3.2] Performing "rh-subscription-manager" ...
[   3.2] Performing "rhn-systemid" ...
[   3.2] Performing "rpm-db" ...
[   3.2] Performing "samba-db-log" ...
[   3.2] Performing "script" ...
[   3.2] Performing "smolt-uuid" ...
[   3.2] Performing "ssh-hostkeys" ...
[   3.3] Performing "sssd-db-log" ...
[   3.3] Performing "tmp-files" ...
[   3.3] Performing "udev-persistent-net" ...
[   3.3] Performing "utmp" ...
[   3.3] Performing "yum-uuid" ...
[   3.3] Performing "customize" ...
[   3.3] Setting a random seed
[   3.3] Setting the machine ID in /etc/machine-id
[   3.3] Performing "lvm-uuids" ...

Now, OpenSSH Host Keys, machine-id has been cleared. you cannnot ssh because OpenSSH Host Key does not exist.

sudo virsh start nextcloud1.example.com --console
wnoguchi@nextcloud1:~$ cat /etc/machine-id
387b30b191d00083a4fbb1018ca98d3d
wnoguchi@nextcloud1:~$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
ssh-keygen: /etc/ssh/ssh_host_ecdsa_key.pub: No such file or directory

Let's generate OpenSSH Host Key.

sudo dpkg-reconfigure openssh-server
  ┌──────────────────────┤ Configuring openssh-server ├──────────────────────┐
  │ A new version (/tmp/filedhtrOw) of configuration file                    │
  │ /etc/ssh/sshd_config is available, but the version installed currently   │
  │ has been locally modified.                                               │
  │                                                                          │
  │ What do you want to do about modified configuration file sshd_config?    │
  │                                                                          │
  │           install the package maintainer's version                       │
  │           keep the local version currently installed                     │
  │           show the differences between the versions                      │
  │           show a side-by-side difference between the versions            │
  │           show a 3-way difference between available versions             │
  │           do a 3-way merge between available versions                    │
  │           start a new shell to examine the situation                     │
  │                                                                          │
  │                                                                          │
  │                                  <Ok>                                    │
  │                                                                          │
  └──────────────────────────────────────────────────────────────────────────┘

keep the local version currently installed

Creating SSH2 RSA key; this may take some time ...
2048 SHA256:MR8BEjZ71V9QUO0HQHY2j8qyDYYXDMGkW4Jt2BbV5HA root@nextcloud1 (RSA)
Creating SSH2 ECDSA key; this may take some time ...
256 SHA256:KScGYK9mY+/lfXoCnj9Qft2X4uWTEsJ8LU908xOVuhM root@nextcloud1 (ECDSA)
Creating SSH2 ED25519 key; this may take some time ...
256 SHA256:GyqSVYEn5ROBprLN5pl0HhyzcNz5YMT+tjOKsdMQ5aE root@nextcloud1 (ED25519)
wnoguchi@nextcloud1:~$
wnoguchi@nextcloud1:~$ ssh-keygen -l -f /etc/ssh/ssh_host_ecdsa_key.pub
256 SHA256:KScGYK9mY+/lfXoCnj9Qft2X4uWTEsJ8LU908xOVuhM root@nextcloud1 (ECDSA)

Configure CPU Model kvm64 for live migration

If you use default CPU Model configuraion, newer machine to older machine live migration will fail because lack of older CPU feature set. QEMU defines kvm64 CPU feature set commonly used for guest OS.

sudo virsh edit XXXXXXXXX
  <cpu mode='custom' match='exact' check='partial'>
    <model fallback='allow'>kvm64</model>
  </cpu>

References

tech/server/linux/virtualization/kvm-qemu/libvirt/libvirt.txt · Last modified: 2020/07/15 11:00 by wnoguchi