virsh console ubuntu 18 container and frozen

I tried to install ubuntu 18.04 container on the centos 7 host

qemu-img create -f raw /data/pools/ubuntu1804.img 50G

make sure download the iso file to /data/images folder ubuntu-18.04.2-server-amd64.iso

virt-install \
--name ubuntu1804 \
--ram 4096 \
--disk path=/data/pools/ubuntu1804.img,size=20,bus=virtio \
--vcpus 2 \
--os-type linux \
--os-variant ubuntu18.04 \
--network bridge=virbr0 \
--graphics none \
--console pty,target_type=serial \
--location '/data/images/ubuntu-18.04.2-server-amd64.iso' \
--extra-args 'console=ttyS0,115200n8 serial' \
--force --debug

after finishing all the process, when i tried virsh console ubuntu1804, it is frozen, googled and tried a lot of different options, finally this one worked

sudo apt install libguestfs-tools 
sudo virt-edit -d ubuntu1804 /boot/grub/grub.cfg

Replace all instances of quiet with quiet console=ttyS0 in the grub.cfg file and start my VM for console connect. then try to start the container and login again

virsh start ubuntu1804
virsh console ubuntu1804

after login, make sure update the grub

vi /etc/default/grub 

change GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash” to GRUB_CMDLINE_LINUX_DEFAULT=”quiet splash console=ttyS0″, then

sudo update-grub

How to Enable or Disable Services in Ubuntu Systemd/Upstart

Often, there is a need to enable or disable services temporarily or permanently on our Ubuntu system. Sometimes, we may require certain services to start up automatically on boot up e.g ssh or web servers and sometimes we may need to disable services we no longer require and are hogging the CPU and RAM.

In this article, we take a look at how we can enable and disable services on Ubuntu.

To do this, we must first understand that there are 3 main init systems for Ubuntu

  • Systemd
  • Upstart
  • SysV

Each init system has a different way of starting and stopping services. We’ll take a look at each one of these.

How to enable and disable services in  Systemd init

To start a service in systemd run the command as shown:

systemctl start service-name

For example, to start apache web service, run

systemctl start apache2

To verify that the service is running, run

systemctl status apache2


● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: active (running) since Thu 2018-03-15 17:09:05 UTC; 35s ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/apache2.service
           ├─2499 /usr/sbin/apache2 -k start
           ├─2502 /usr/sbin/apache2 -k start
           └─2503 /usr/sbin/apache2 -k start

Mar 15 17:09:04 ip-172-31-41-251 systemd[1]: Starting LSB: Apache2 web server...
Mar 15 17:09:04 ip-172-31-41-251 apache2[2475]:  * Starting Apache httpd web ser
Mar 15 17:09:05 ip-172-31-41-251 apache2[2475]:  *
Mar 15 17:09:05 ip-172-31-41-251 systemd[1]: Started LSB: Apache2 web server.

To stop the service running service

systemctl stop apache2

To confirm that the service is not running, run

systemctl status apache2


● apache2.service - LSB: Apache2 web server
   Loaded: loaded (/etc/init.d/apache2; bad; vendor preset: enabled)
  Drop-In: /lib/systemd/system/apache2.service.d
   Active: inactive (dead) since Thu 2018-03-15 17:19:47 UTC; 12s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 2822 ExecStop=/etc/init.d/apache2 stop (code=exited, status=0/SUCCESS
  Process: 2687 ExecStart=/etc/init.d/apache2 start (code=exited, status=0/SUCCE

Mar 15 17:10:11 ip-172-31-41-251 systemd[1]: Starting LSB: Apache2 web server...
Mar 15 17:10:11 ip-172-31-41-251 apache2[2687]:  * Starting Apache httpd web ser
Mar 15 17:10:12 ip-172-31-41-251 apache2[2687]:  *
Mar 15 17:10:12 ip-172-31-41-251 systemd[1]: Started LSB: Apache2 web server.
Mar 15 17:19:46 ip-172-31-41-251 systemd[1]: Stopping LSB: Apache2 web server...
Mar 15 17:19:46 ip-172-31-41-251 apache2[2822]:  * Stopping Apache httpd web ser
Mar 15 17:19:47 ip-172-31-41-251 apache2[2822]:  *
Mar 15 17:19:47 ip-172-31-41-251 systemd[1]: Stopped LSB: Apache2 web server.

To enable apache2 service on boot up run

systemctl enable apache2

To disable apache2 service on boot up run

systemctl disable apache2

To restart the service

systemctl restart apache2

To check whether the service is currently configured to start on the next boot up

systemctl is-enabled apache2


Executing /lib/systemd/systemd-sysv-install is-enabled apache2

To check whether the service is active

systemctl is-active apache2



How to remove Systemd services completely

What if you installed a package, and later on decide that you don’t need it anymore. How do you go about removing it completely ? Follow the commands below.
First, stop the service

systemctl stop service-name

Then disable the service

systemctl disable service-name

Removing the service in systemd

rm /etc/systemd/system/service-name
rm /etc/systemd/system/service-name/[related symlinks]

Reload systemd

systemctl daemon-reload

Finally run,

systemctl reset-failed

How to enable and disable services in Upstart init

Upstart init system was unveiled just before systemd It was used in Ubuntu 9.10 to Ubuntu 14.10. It ws later phased out paving way for systemd init in Ubuntu 15.04 and newer versions. In this example, let’s see how we can start and stop, enable and disable services in Ubuntu 14.04.

Upstart makes use of config files for controlling services.These files are held under the /etc/init directory. These files are made up of plain text sections organized in stanzas and each stanza describes a service and how it works.

To check whether a service is running or not run the command below

initctl status service-name


service service-name status


status service-name

In this example, we’ll check the status of cups, a Linux print server.

 initctl status cups


service cups status


status cups


cups start/running, process 3029

To stop the service run the command below

initctl stop cups


service cups stop


stop cups


cups stop/waiting

To enable a service in Upstart init

In /etc/init/*.conf file, you’ll find the “respawn” directive which jump-starts a service should it crash unexpectedly or should the system reboot. Its normally enabled by default.
For example , in /etc/init/cups.conf file below,

enable and disable services in ubuntu

the first argument (3)  is the number of attempts it will try to restart and the second argument (12) is the time interval between retries. If it fails to restart automictically. it will be kept in a stopped state.

To disable a service in upstart init

run the command below

echo manual >> /etc/init/service.override

This creates an override file that disables a service without altering the job definition at all.
For cups service, the command will be

echo manual >> /etc/init/cups.override

Upon a reboot of the system, cups will be in a stopped state. If you wish to re-enable the service, you must delete the  /etc/init/cups.override file.

Sysv-rc-conf tool

This is a text-based console that gives you an overview of different service and runlevels they are scheduled to start.
It can be installed using the following command

apt-get install sysv-rc-conf

To execute the tool, run


Jobs-Admin tool

This is another feature that allows you to control services and processes in a GUI environment
You can install this by running.

apt-get install jobs-admin

How to enable and disable services in  SysV init

To enable a service in SysV init run

update-rc.d enable service-name

For instance, If you want to enable apache web server, you would run

update-rc.d enable apache2

To disable a service , run

update-rc.d disable service-name

For example

update-rc.d disable apache2

Nearly all Linux systems run on Systemd init From Ubuntu, Debian, RHEL, and CentOS. You’ll, therefore, discover that you’ll be using more of the systemctl command to start, stop, enable and disable services. We welcome you to try out the commands as shown in this article. Thank you.

systemctl: command not found

First you need to check if systemd package is installed – sudo dpkg -l | grep systemd.

If not then install it by hands sudo apt-get install systemd. But if it does it might be damaged, so you may try to reinstall it sudo apt-get install --reinstall systemd.

If the package is installed, even after reinstallation it does not work, list the full path of the files inside this package sudo dpkg -L systemd. Maybe binary files are located in a directory that is not included into $PATH variable

common used docker commands, list all, remove all containers, delete all images

To list all containers by container ID

docker ps -aq

stop all running containers

docker stop $(docker ps -aq)

To remove all containers

docker rm $(docker ps -aq)

To remove all imagees

docker rmi $(docker images -aq)

You might encounter this error

Error response from daemon: conflict: unable to delete 5e7a80b3348c (must be forced) – image is referenced in multiple repositories

Error response from daemon: conflict: unable to delete 5e7a80b3348c (must be forced) – image is referenced in multiple repositories

docker rmi $(docker images -q) --force

Background information:

You can see the containers on your computer using

  • docker container ls

Example output:

  • 3477a4dcdce2 “/usr/local/bin/dock…” 2 days ago Up 2 days>9200/tcp, 9300/tcp elasticsearch1
  • 67997f002f15 appbaseio/dejavu “http-server ‘-p 135…” 2 days ago Up 2 days>1358/tcp dejavu

As we can see, two containers are currently running on this computer.

For each container, the IMAGE column shows us which image the container is running. For example, the second container is running on the appbaseio/dejavu image.

When we tell docker to show us all images currently listed on the computer:

  • $ docker image ls -a
  • <none> <none> 39ac507bd271 11 days ago 962MB
  • <none> <none> 6a2c829a5d4f 11 days ago 962MB
  • 6.7.1 c91b419ac445 3 weeks ago 682MB
  • pypy 3 75e018538e96 4 weeks ago 962MB
  • node 10 64c810caf95a 4 weeks ago 899MB
  • appbaseio/dejavu latest 47b8375dc541 2 months ago 141MB
  • risingstack/alpine 3.4-v4.4.4-3.6.1 2d384efd00ab 2 years ago 247MB

We can immediately see that there are way more images than containers

There are four main reasons for that:

  • Docker keeps old versions of containers, they are not automatically deleted. In this example, there are two versions of Version 6.7.1 and version 7.0.0 even though I’m currently only using version 6.7.1. According to the list, version 7.0.0 takes up an additional 682 Megabytes of space on my SSD but note that this number may not be accurate (see layered images below)
  • Docker does not automatically delete images that you no longer use (e.g. if you used a an image just for a quick test but don’t use it any more)
  • Docker uses layered images. This means that an image like appbaseio/dejavu is not standalone but is (usually) based on some underlying image like ubuntu or debian. In most cases there are many layers (typically around 5-10) of an image due to the way they are built. While this leads to less disk space being consumed since some images are used by multiple “daughter” images, this still leads to a lot of images laying around on your drive, often including unused intermediary images.
  • In case you build docker images yourself, especially in case you are creating your own Dockerfile, during development often a lot of images are generated (representing intermediary versions of the software you are developing)

In order to delete an image that you no longer need, use the docker image rm <image ID> command. Copy the image ID from the IMAGE ID column of the output of docker image ls as shown above.

For example, in order to delete the version 7.0.0 image of elasticsearch, use

  • $ docker image rm 0e92b9e5fe1e
  • Untagged:
  • Untagged:[email protected]:e9ab1f4c2ffbc7054dab91e8dc7fd9a56d53cce734098910d876eb14849b1ba3
  • Deleted: sha256:0e92b9e5fe1e0949f5174ed86d9cbc3c2a041df493453f82b6c044ff78c7d17b
  • Deleted: sha256:c2a552806b86aba72a6e6ea5efaaa295286e8b0cf42a14d799428e58f20e7090
  • Deleted: sha256:71e7a706f7c03f0c7add24844f7b311edf83838ef383a877bcb94684b011893d
  • Deleted: sha256:d43e5d351c26273e43b11f6937cb9a3192d856b4e083acfbc14b8500056221f2
  • Deleted: sha256:f3a2ae77ca96f2f55300b00beedbf14ade0a27bf29c395dcbf84b5bf02ef80ad
  • Deleted: sha256:5d7f2d83e59c0684b4a94ab5f6479d798444bdca8fe6c813f7ef6188cdd12ce5
  • Deleted: sha256:cc16decd0c6f218c3a21749e747d43deced9e8929e8db0b6050dd4102301651a

As you can see from the output, this will not only delete the ElasticSearch image 0e92b9e5fe1e itself but also all the other images that image depended on (which are not also used by any other image).

upgrade ubuntu 14.04 to latest 18.04

You’ll first need to make sure update-manager-core is present (it may already be installed):

sudo apt-get install update-manager-core

Next, run:

sudo do-release-upgrade

You may need to check /etc/update-manager/release-upgrades and change the line: