How To: Update VM title with virsh

Use virsh desc command to update VM title in KVM

I’m updating and migrating the last few of virtual machines on one of my servers, and realised that there’s a virsh list command option that I really like: it shows descriptive titles in addition to just listing virtual machines.

You know, how we usually run virsh list to see the VMs currently running on a server?

root@s2:/ # virsh list
Id Name State
----------------------------------------------------
1 elk running
4 dbm1 running
6 v9.ts.im running
9 infra running

Well, these VM names aren’t terribly informative. So I like using the virsh list –title command to show the list of VMs with their proper titles:

root@s2:/ # virsh list --title
Id Name State Title
----------------------------------------------------------------------------------
1 elk running Elastic + Logstash + Kibana
4 dbm1 running
6 v9.ts.im running wiki [4vCPU 4GB]
9 infra running infra [4 vCPU 4GB]

And if any VMs are not showing descriptive titles yet, it’s very easy to add it (–live means “apply to the running instance of the VM” and –config means “update the VM information on the disk”). Here’s an example forth dbm1 VM:

root@s2:/ # virsh desc dbm1 --title "MariaDB server [4vCPU 4GB]" --live --config
Domain title updated successfully

…and if we check again, dbm1 VM is now sporting a brand new description:

root@s2:/ # virsh list --title
Id Name State Title
----------------------------------------------------------------------------------
1 elk running Elastic + Logstash + Kibana
4 dbm1 running MariaDB server [4vCPU 4GB]
6 v9.ts.im running wiki [4vCPU 4GB]
9 infra running infra [4 vCPU 4GB]



How To List Disks and Partitions in MacOS

2018-09-23_10-37-43.pngNot every Mac user is aware that we’ve got one of the truest Unix operating systems under the great look user interface in MacOS.

That’s why almost everything that you can do using graphics interface and MacOS apps, can also be accomplished using a command line (start the Terminal app).

To get the list of partitions in MacOS, and to learn their sizes and filesystem types, use the diskutil command:

greys@maverick:~ $ diskutil list
/dev/disk0 (internal):
# : TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme 500.3 GB disk0 1: EFI EFI 314.6 MB disk0s1 2: Apple_APFS Container disk1 500.0 GB disk0s2

/dev/disk1 (synthesized):
# : TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +500.0 GB disk1 Physical Store disk0s2 1: APFS Volume Macintosh HD 446.2 GB disk1s1 2: APFS Volume Preboot 27.9 MB disk1s2 3: APFS Volume Recovery 519.0 MB disk1s3 4: APFS Volume VM 9.7 GB disk1s4

/dev/disk2 (disk image):
# : TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme +30.0 GB disk2 1: EFI EFI 209.7 MB disk2s1 2: Apple_APFS Container disk3 29.8 GB disk2s2

/dev/disk3 (synthesized):
# : TYPE NAME SIZE IDENTIFIER
0: APFS Container Scheme - +29.8 GB disk3 Physical Store disk2s2 1: APFS Volume Photos 9.2 GB disk3s1

/dev/disk4 (external, physical):
# : TYPE NAME SIZE IDENTIFIER
0: GUID_partition_scheme *120.0 GB disk4 1: EFI NO NAME 536.9 MB disk4s1 2: Linux Filesystem 21.5 GB disk4s2 3: Linux Filesystem 98.0 GB disk4s3



How To Enable Auto Start for KVM

I had one of my dedicated servers crash the other day and when I fixed it and booted it again, some of my virtual machines didn’t boot.

Turns out, it’s because they didn’t have the autostart enabled:

root@s3:~ # virsh dominfo m
Id: -
Name: m
UUID: f2f9b5aa-7086-89ef-a643-fddb55134ef0
OS Type: hvm
State: shut off
CPU(s): 4
Max memory: 4194304 KiB
Used memory: 4194304 KiB
Persistent: yes
Autostart: disable
Managed save: no
Security model: none
Security DOI: 0

That’s how one can turn the autostart on so that next reboot this VM would start (last parameter is the name of the VM):

root@s3:~ # virsh autostart m     
Domain m marked as autostarted

And just to make sure this actually helped:

root@s3:~ # virsh dominfo m
Id: -
Name: m
UUID: f2f9b5aa-7086-89ef-a643-fddb55134ef0
OS Type: hvm
State: shut off
CPU(s): 4
Max memory: 4194304 KiB
Used memory: 4194304 KiB
Persistent: yes
Autostart: enable
Managed save: no
Security model: none
Security DOI: 0



How To List Files in Ubuntu/Debian Package

dpkg -L

 

If you’re ever looking for a specific list of files included with one of the packages on your Ubuntu/Debian/Mint Linux setup, here’s how you can do it using the dpkg command:

# dpkg --listfiles libcurl4-openssl-dev
/.
/usr
/usr/lib
/usr/lib/x86_64-linux-gnu
/usr/lib/x86_64-linux-gnu/pkgconfig
/usr/lib/x86_64-linux-gnu/pkgconfig/libcurl.pc
/usr/lib/x86_64-linux-gnu/libcurl.a
/usr/lib/x86_64-linux-gnu/libcurl.la
/usr/share
/usr/share/doc
/usr/share/doc/libcurl4-openssl-dev
/usr/share/doc/libcurl4-openssl-dev/copyright
/usr/share/man
/usr/share/man/man1
/usr/share/man/man1/curl-config.1.gz
/usr/share/aclocal
/usr/share/aclocal/libcurl.m4
/usr/include
/usr/include/curl
/usr/include/curl/curlver.h
/usr/include/curl/mprintf.h
/usr/include/curl/stdcheaders.h
/usr/include/curl/easy.h
/usr/include/curl/curlrules.h
/usr/include/curl/multi.h
/usr/include/curl/curlbuild.h
/usr/include/curl/typecheck-gcc.h
/usr/include/curl/curl.h
/usr/bin
/usr/bin/curl-config
/usr/lib/x86_64-linux-gnu/libcurl.so
/usr/share/doc/libcurl4-openssl-dev/changelog.Debian.gz
/usr/share/doc/libcurl4-openssl-dev/NEWS.Debian.gz

The same can also be done with the shorter version of the command line option: dpkg -L

One of the most typical things to check next would be to verify the integrity of all these files in the package – usually dpkg keeps checksums for all the files installed.

Verifying integrity of files instlaled by the package:

# dpkg --verify libcurl4-openssl-dev
??5?????? /usr/include/curl/curl.h

In this example I have gone and edited the comment in the curl.h header file, just to change it enough for dpkg to pick it up. Since checksums are used for highlighting differences and also because most of package installed files are binaries or special non-cleartext formats, you don’t see the text-based diff but instead just get an indication that certain file differs from the original version installed by dpkg.

The shorter version of the same is dpkg -V.




How To Fix Corrupted Packages Database for YUM

I had a server run out of space recently, to the point that it couldn’t complete the yum update. This server ended up corrupting a yum packages database.

Here’s how corrupted YUM database looks

Correctly called rpmdb, packaged database used by YUM looks like this when it can’t be opened:

root@s3:/ # yum update
error: db5 error(11) from dbenv->open: Resource temporarily unavailable
error: cannot open Packages index using db5 - Resource temporarily unavailable (11)
error: cannot open Packages database in /var/lib/rpm
CRITICAL:yum.main:

Error: rpmdb open failed

Rebuilding RPM DB

The fix is to rebuild the RPM database, like this:

root@s3:/ # rpm --rebuilddb

and just to try things, do the same yum update – it should work now:

root@s3:/backup/linux # yum update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
* base: centos.mirror.ate.info
* epel: mirror.1000mbps.com
* extras: rep-centos-fr.upress.io
* updates: centos.mirror.ate.info
Resolving Dependencies
...



How To Fix Fonts in X11 Forwarding

I’m installing VirtualBox on one of my remote Linux servers and installed the software from their repository that deploys all the additional packages required by VirtualBox.

Still, when I first started the graphical interface (VirtualBox Manager), most of text appeared as funny characters that can’t really be read:

This is a common problem when you’re trying to run a graphical (X11) application on a server without graphics system like Xorg. As you probably guess, the problem is to do with fonts.

Specifically, it’s a problem of your remote Linux server not having any fonts installed, because Xorg (graphics system) was never installed on it (servers usually have server-specific version of distro or at least a package selection that disables desktop related things).

Once we install standard fonts package like this:

greys@s5:~ $ sudo yum install xorg-x11-fonts-Type1
...
Installed:
 xorg-x11-fonts-Type1.noarch 0:7.5-9.el7

Dependency Installed:
 libXfont.x86_64 0:1.5.2-1.el7 libfontenc.x86_64 0:1.1.3-3.el7 ttmkfdir.x86_64 0:3.0.9-42.el7 xorg-x11-font-utils.x86_64 1:7.5-20.el7
...

… restarting application will result in a normal window with quite readable fonts:unixtutorial-virtualbox-x11-fonts-correct.png

See Also




How To Check RAID Progress with /proc/mdstat

I explained how to read the /proc/mdstat in my recent post How To Identify RAID Arrays in Linux, so today is a super quick follow up using one of my systems.

I use Synology NAS in my office and disks in the storage array are getting old, so I decided to swap them out one by one in the next few months. Synology runs a Linux based proprietary OS called DSM, and ultimately it relies on software RAID configured and managed with md devices. So all the setup is done using web-based GUI, but I always like double-checking what’s going on by logging directly onto the appliance.

Here’s how I use /proc/mdstat to track the faulty disk replacement:

# cat /proc/mdstat
Personalities : [linear] [raid0] [raid1] [raid10] [raid6] [raid5] [raid4]
md2 : active raid6 sda5[9] sdb5[1] sdh5[7] sdg5[6] sdf5[8] sde5[4] sdd5[3] sdc5[2]
 17552612736 blocks super 1.2 level 6, 64k chunk, algorithm 2 [8/7] [_UUUUUUU]
 [==>..................] recovery = 13.4% (393456896/2925435456) finish=1578.6min speed=26731K/sec

This tells me:

  • md2 is the name of a RAID array device
  • RAID type is RAID6 (confirmed by raid6 personality AND level 6 words)
  • my array consists of 8 disks (sda5/sdb5/…/sdh5)
  • RAID block size is 64K
  • 7 devices are up (that’s what each of the Us mean in the [_UUUUUUU] section)
  • 1 device is down (that’s what the underscore _ means in [_UUUUUUU])
  • Array is going through a recovery procedure, we’re 13.4% there with another 26 hours (finish=1578.6min) to go
  • Speed of the RAID array recovery (effectively that’s the speed of populating the new disk with parity-based data from other disks in the array) is 26.1MB/sec (speed=26731K/sec)



How-To: Show Modules Loaded by Apache

Just a quick tip today, should help all of you who are setting up their very first Linux/Apache/PHP/MySQL (LAMP) webserver.

To list all the Apache modules that were loaded upon httpd start, use the apachectl -M command:

root@webserver1# apachectl -M

Loaded Modules:
 core_module (static)
 so_module (static)
 http_module (static)
 access_compat_module (shared)
 actions_module (shared)
 alias_module (shared)
 allowmethods_module (shared)
 auth_basic_module (shared)
 auth_digest_module (shared)
 authn_anon_module (shared)
 authn_core_module (shared)
 authn_dbd_module (shared)
 authn_dbm_module (shared)
 authn_file_module (shared)
 authn_socache_module (shared)
 authz_core_module (shared)
 authz_dbd_module (shared)
 authz_dbm_module (shared)
 authz_groupfile_module (shared)
 authz_host_module (shared)
 authz_owner_module (shared)
 authz_user_module (shared)
 autoindex_module (shared)
 cache_module (shared)
 cache_disk_module (shared)
 cache_socache_module (shared)
 data_module (shared)
 dbd_module (shared)
 deflate_module (shared)
 dir_module (shared)
 dumpio_module (shared)
 echo_module (shared)
 env_module (shared)
 expires_module (shared)
 ext_filter_module (shared)
 filter_module (shared)
 headers_module (shared)
 http2_module (shared)
 include_module (shared)
 info_module (shared)
 log_config_module (shared)
 logio_module (shared)
 macro_module (shared)
 mime_magic_module (shared)
 mime_module (shared)
 negotiation_module (shared)
 remoteip_module (shared)
 reqtimeout_module (shared)
 request_module (shared)
 rewrite_module (shared)
 setenvif_module (shared)
 slotmem_plain_module (shared)
 slotmem_shm_module (shared)
 socache_dbm_module (shared)
 socache_memcache_module (shared)
 socache_shmcb_module (shared)
 status_module (shared)
 substitute_module (shared)
 suexec_module (shared)
 unixd_module (shared)
 userdir_module (shared)
 version_module (shared)
 vhost_alias_module (shared)
 watchdog_module (shared)
 dav_module (shared)
 dav_fs_module (shared)
 dav_lock_module (shared)
 lua_module (shared)
 mpm_prefork_module (shared)
 proxy_module (shared)
 lbmethod_bybusyness_module (shared)
 lbmethod_byrequests_module (shared)
 lbmethod_bytraffic_module (shared)
 lbmethod_heartbeat_module (shared)
 proxy_ajp_module (shared)
 proxy_balancer_module (shared)
 proxy_connect_module (shared)
 proxy_express_module (shared)
 proxy_fcgi_module (shared)
 proxy_fdpass_module (shared)
 proxy_ftp_module (shared)
 proxy_http_module (shared)
 proxy_hcheck_module (shared)
 proxy_scgi_module (shared)
 proxy_uwsgi_module (shared)
 proxy_wstunnel_module (shared)
 cgi_module (shared)
 php7_module (shared)



How To Determine OS Version on Your Raspberry Pi

Someday you may realise that you had your Raspberry Pi for so long that you no longer remember what OS release it’s running.

Turns out, it’s super easy to double-check:

root@s7:~# cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
NAME="Raspbian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums" 
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"

See Also




How to Confirm which Ports are Open on Your Linux System

If you wish to see which ports are open on your Linux system, perhaps to check your configuration, you can use the nmap tool. It’s a powerful tool, but we’ll focus on just this simple task.

If you don’t have nmap, first install it. For example, on Ubuntu just run sudo apt-get install nmap. On Fedora it should be sudo yum install nmap. On Arch it should be sudo pacman -Sy nmap.

Once you’ve got nmap just run this simple command. Note that we’re running it with superuser privileges (sudo), which is necessary.

$ nmap localhost

Your output may look something like this:

Starting Nmap 6.40 ( http://nmap.org ) at 2014-11-26 23:56 CET
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0089s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 994 closed ports
PORT STATE SERVICE
21/tcp open ftp
22/tcp open ssh
53/tcp open domain
80/tcp open http
443/tcp open https
3306/tcp open mysql

So it shows you the open port numbers and the service that is using each. The above is pretty standard stuff. If you don’t see what you expected you should check your configuration.

If you’d like to do more with nmap you can explore the nmap built in documentation by running man nmap, which contains a breadth of information.

See Also