In the past few years I kind of gotten used to use "KiB" values in the memory allocation of a KVM/QEMU virtual machine, defined in the libvirt XML:
<domain type='kvm'>
<name>vp-kube01-u</name>
<uuid>cf6a0028-83a8-41fd-8c5e-e39d56e42e5c</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://ubuntu.com/ubuntu/20.04"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='KiB'>10485760</memory>
<currentMemory unit='KiB'>10485760</currentMemory>
<vcpu placement='static'>6</vcpu>
But whenever you want to change the memory allocation (using virsh edit <VM>), you need to use a calculator to get the GB value into KiB.
In the example above I know the VM has allocated 10 GiB of memory; 10485760 KiB (10240 MiB). To increase the VM's memory to 16 GB is therefore:
10485760 / 10 * 16 = 16777216 KiB
This is stupid, right?
Interestingly in almost all KVM/QEMU tutorials using libvirt, the examples use "KiB" as memory allocation unit. However the documentation clearly states that different units are allowed, too:
[...] The units for this value are determined by the optional attribute unit, which defaults to "KiB" (kibibytes, 210 or blocks of 1024 bytes). Valid units are "b" or "bytes" for bytes, "KB" for kilobytes (103 or 1,000 bytes), "k" or "KiB" for kibibytes (1024 bytes), "MB" for megabytes (106 or 1,000,000 bytes), "M" or "MiB" for mebibytes (220 or 1,048,576 bytes), "GB" for gigabytes (109 or 1,000,000,000 bytes), "G" or "GiB" for gibibytes (230 or 1,073,741,824 bytes), "TB" for terabytes (1012 or 1,000,000,000,000 bytes), or "T" or "TiB" for tebibytes (240 or 1,099,511,627,776 bytes). [...]
Ha! Just learned something new!
While I was working on such a libvirt KVM machine, I just gave it a try and set the memory unit to GiB:
<domain type='kvm'>
<name>vp-kube01-u</name>
<uuid>cf6a0028-83a8-41fd-8c5e-e39d56e42e5c</uuid>
<metadata>
<libosinfo:libosinfo xmlns:libosinfo="http://libosinfo.org/xmlns/libvirt/domain/1.0">
<libosinfo:os id="http://ubuntu.com/ubuntu/20.04"/>
</libosinfo:libosinfo>
</metadata>
<memory unit='GiB'>16</memory>
<currentMemory unit='GiB'>16</currentMemory>
<vcpu placement='static'>6</vcpu>
Started the VM (virsh start <VM>) and it worked perfectly fine!
So much easier this way!
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Observability Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder