Working with targets and systemd CentOS7

Several years ago when I heard about Linux for the first time, I though about like a abstract and useless piece of software, of course I used to ignore 99% of it and I couldn’t be more wrong. Now Linux has became my daily basis and I want to learn more and more every day and this blog it’s proof of that.

First steps for LFCS

Most of the certifications includes what you should learn in order to pass the exam, so I started digging in Linux Foundation webpage to find objetives of the LFCS “LFCS Domain and Competencies V2.16“, this blog will focus to cover all or the most relevant aspects of the list, hence I would start from “Boot systems into different runlevels manually”. In  CentOS 7 they are no longer called run levels and now they  are called “targets”, however they the system it’s backwards compatible and we still are able to use the “telinit” command which was used to change the different run levels in previous versions, if you want to test it the command it’s as simple as “$telinit <run level number>”.

Let’s say that you installed centos with all the graphical features but for security reasons you want to keep the server only text (or multi-user), you can achieve it changing the the targets, I will explain about how to make them work below.

The run levels has been in Linux for long time it’s necessary to make the comparission between targets and runlevels as follows:

createdbyme

Most of them are very self-explanatory, hence I will focus on the one less easy to understand, considering the image above where we find the different targets and their equals in run levels, there is a biggers list for targets however these are the one most used and important to know.

Run level 1 or rescue.target: We use the rescue target when we either lose the root password or if the system is inacessible, basically when the things go wrong, this mode it’s available only if you have physical access to the server.

multi-user.target: The mode it’s to login in a multi-user operative system but without any graphic interface, just plain text let’s say.

We can list the targets availables wiht the following command:

$sudo systemctl list-units –type=target

listing

In order to check what target we are currently at, the command it’s the following:

$systemctl get-default

get-defa

If we want to change temporary the target of the system we should just type the following command as root:

$sudo systemctl isolate <target name>.target

isolate-target

The change will apply automatically and in this case it will look like this:

multi-user

If we want to change target of the system and preserve the change after restart, this is the command we should use:

$sudo systemctl set-default <target name>.target

set-default

Struggle

Part of this blog it’s to show you the commons issues that I face making this changes to the system this troubleshooting step by step it’s difficult to find on internet and I believe it has great value, this is the first of the big list to come.

After changing the target I wanted to come back to the graphical mode, it turned out that the graphical target was no longer on the list. However, if you pay attention you can find what you are looking for, at the end of the output of the list-units command it says to type –all to find the complete target list.

.

graphicaltarget

WALAAA there it is

To go back, make sure to type the “sudo” before the command as the multi-user mode doesn’t have the ability to prompt password and you need root access to make this change.

changingback

If you like to access in rescue mode, follow the steps below:

  1. Restart your system and press”e” for edit in the grub screen

grubscreen

2. You will be passed to a plain text screen and from there we need to go down and look for “ro crashkernel=auto” as the image below:

rw

3. This text will need to be replace it by “rw init=/sysroot/bin/bash” and “Ctrl – X”

init

In the next screen, you will enter in the emergency mode and typing the following command you will get fully access to the system again as root.

#chroot /sysroot/

emergencymode

From there you have full access to your system and you even able to change the root password.

I’d recommend you to play around with the targets of your system (In a test enviroment) and get involved with it.

If you liked it share with your collegues, if you think something it’s missing send me a comment, I hope you enjoyed.

See you in the next post…

Ops4life!

 

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s