How to solve 'System has not been booted with systemd as init system (PID 1).'? I can't reboot Ubuntu

I've got a problem during setup of apache. I am using Ubuntu version 18.04. I don't know what made this problem appeared...

I will just list all my commands.

apt-get update
apt-get upgrade

I saw an error after I tried to upgrade:

E: Sub-process /usr/bin/dpkg returned an error code (1) 

To solve it or a solution I used some commands below:

vi usr/sbin/policy-rc.d

contents:

#!bin/sh
exit 101

chmod +x /usr/sbin/policy-rc.d
dpkg-divert --local --rename --add /sbin/initctl
ln -s /bin/true /sbin/initctl

These are from this documentation

apt-get install apache2
apt-get install php
apt-get install libapache2-mod-php
apt-get install php-mbstring
apt-get install php-gd
apt-get install php-curl php-xml
apt-get install mariadb-server
/usr/bin/mysql_secure_installation

use mysql;
update user set plugin='' where User='root';
flush privileges;
exit;
apt-get install php-mysql

adduser

a2ensite

I downloaded phpmyadmin.

After all these commands I wanted to reboot Ubuntu but it didn't work. After the command reboot I saw a message like this:

System has not been booted with systemd as init system (PID 1). Can't 
operate. Failed to talk to init daemon.

and for reboot -f:

Rebooting.
Failed to reboot: Invalid argument

I am complete newbie... I have no idea what I should do

I just reinstalled Ubuntu and I got the same messages mentioned above, though I did nothing but just tried reboot after reinstalling.


Solution 1:

I have/had a similar problem when trying to install Docker using Docker's instructions to install on Linux (https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-18-04) or (https://docs.docker.com/install/linux/docker-ce/ubuntu/#install-docker-ce-1).

The solution is to install Docker using the Windows installation process then linking your Windows Subsystem for Linux to the Windows Docker. As I understand, the reason for the failure is lack of access from the Windows Subsystem to files needed by docker, which are ultimately on Windows. The solution circumvents this. Hope this helps!

https://blog.jayway.com/2017/04/19/running-docker-on-bash-on-windows/

Solution 2:

If you are using Docker, you may try an image that has Ubuntu with System D already active with this command:

docker run -d --name systemd-ubuntu --privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro jrei/systemd-ubuntu

Then you just need to run:

docker exec -it systemd-ubuntu /bin/bash

and there you can just install, start and restart any service you need.

Solution 3:

I had the same problem, accidentally removed the /bin/bash file. After that my server would not boot.

I mounted an old backup and copied the bash file from the mounted drive. Once dismounted, everything was fine except the mounted drive still appeared when I ran df.

I force dismounted the previously mounted back up and got stuck with the same problem.

Try doing the following:

bash --login
exec bash 
bash --login; exit

Here is my source:

https://superuser.com/questions/353723/how-do-i-reload-the-terminal-in-ubuntu

In addition, I also installed aptitude and ran aptitude reinstall bash.

I cannot exactly say what fixed it but the problem is resolved and I can ssh as usual.