Read a sample: 1. Build a Safe Practice Environment
A service-management lab becomes much more useful when you are free to make mistakes. A failed service, an incorrect dependency, or a system that will not complete startup can teach you a great deal—provided the machine is yours to repair and you have a reliable way back.
In this chapter, you will prepare a Linux virtual machine for the exercises ahead. You will verify that it uses systemd, establish administrative and console access, and create a known-good recovery point. You will also practice the shell conventions used throughout the book. By the end, you should have a small, disposable system on which you can investigate startup and services without treating your everyday computer as the test subject.
The goal is not to make every experiment risk-free. A virtual machine can still contain files you care about, reach other systems over a network, or consume resources on its host. The goal is to define a clear boundary, understand how to recover within that boundary, and keep anything valuable outside it.
The host is the physical computer running your virtualization software. The guest is the Linux system running inside the virtual machine, often shortened to VM. Commands in this book are intended for the guest unless the text explicitly says otherwise.
Use a virtualization application that supports virtual disks, an interactive display or console, and snapshots. The application may call its console a display, screen, or window. The essential feature is that you can interact with the guest even if its network connection is unavailable.
For the guest, choose a current Linux distribution that uses systemd as its service manager. A mainstream server or desktop installation is suitable. A minimal server installation keeps the environment uncluttered, while a desktop may be more comfortable if you prefer graphical tools. The labs primarily use the shell, so neither choice requires you to manage services through a graphical interface.
Download the installation image from the distribution’s official source. Follow its published instructions for checking the image when practical, especially if you obtained it through a mirror. Record the distribution name and release in your lab notes; service names, package tools, bootloader layouts, and default settings can differ between distributions.
A reasonable starting allocation is two virtual CPUs, 2 GiB of memory, and a 20 GiB virtual disk, provided your host has enough resources to run comfortably. Some desktop installers or distributions may need more. Consult the distribution’s installation guidance if the installer is slow or reports insufficient resources. The disk belongs to the lab: do not attach an existing disk that contains important data.
Create a new VM in your virtualization application and attach the Linux installation image as its virtual installation media. If the application asks you to select an operating system type, choose the closest match to your distribution and architecture.
Use a simple, clearly identifiable name such as linux-services-lab. During installation:
1. Install to the new virtual disk, not to a physical host disk or an existing shared disk.
2. Create a normal user account and choose a password you can retrieve.
3. Configure that account for administrative access if the installer offers the option.
4. Select a standard installation rather than a specialized container or appliance image.
5. Finish installation, remove or disconnect the installation media if necessary, and boot from the virtual disk.
A VM network mode using network address translation, commonly called NAT, is a practical starting point. It usually lets the guest reach package repositories without making the guest directly visible as a separate machine on your local network. Exact behavior depends on the virtualization application and host configuration, so do not treat the network mode as a complete security boundary. Avoid connecting the lab to sensitive networks, and do not add shared folders or forwarded ports unless you need them and understand the exposure.
Log in through the VM console. If the guest starts a graphical desktop, open its terminal application. On a text console, log in at the prompt. You do not need remote access for the labs in this book; keeping the console available is more important than setting up SSH.
Start by identifying the system from inside the guest:
bash
cat /etc/os-release
uname -r
The first command shows operating system identification information. The second prints the running kernel release. Your output will not necessarily match anyone else’s, and that is fine. These commands establish which environment you are observing; they do not change it.
Now check the process running as PID 1 and ask systemd for its version:
bash
ps -p 1 -o comm=
systemctl --version
On the intended lab system, the first command should normally print systemd, and the second should display version information. PID 1 is the first userspace process started by the kernel in a conventional Linux boot. Later chapters will examine how the system reaches it and how systemd brings units into operation.
A systemctl executable alone does not prove that systemd is managing the running system. It may be installed in an environment where another process is PID 1. If PID 1 is not systemd, or if systemctl cannot communicate with the manager, check that you booted the VM normally from the installed virtual disk. You may have started an installer’s temporary environment or selected an image designed for a container. Resolve that mismatch before proceeding.
You can also make a read-only query of the manager:
bash
systemctl is-system-running