Loading...

STORIES

Switch Out Process One with Debian GNU/Linux

The default system manager in Debian GNU/Linux, specifically the latest stable version, Debian 10 or Debian buster, and in many Linux distributions, is systemd. If you wanted to switch that out for something else, specifically sysvinit, you can.

Let's install Debian in VirtualBox and switch out the first process that runs once Linux has started. Then let's build a custom Debian installer specifying an alternative initialisation system.

Requirements

You will need:

Getting Started

Start VirtualBox and add a virtual machine, setting the memory size and setting up a new virtual hard disk (15 GB, and dynamically sized is fine), and remember to go into the machine settings and to increase the number of virtual processors if your system allows for it (under System > Processor) and to enable USB 3 (under Ports > USB). Alternatively, if you're familiar with Vagrant, you can use the Debian Buster Vagrant box.

Start it up and select the downloaded installer disk image to boot from. From the startup menu, go ahead and select the graphical installer.

Run through the installation, selecting your language and location, and the network should be configured automatically: Just use all the defaults. Enter a password for the root user and then add yourself as a user. Make use of guided partitioning when partitioning the disk and use the entire disk, all files in one partition. Installation will then start. Configure the package manager by selecting a network mirror close to you, and confirm installing the boot loader to the single partition. When the installation completes, the virtual machine will restart, and you can log in as the root user.

Take a VirtualBox snapshot at this point as we're going to be coming back to this fresh installation state later.

Change the First Running Process

Run the following to see the first process' command, and to see what the system initialisation daemon is. You should see systemd shown for both of these, the second result returning a soft link to systemd.

cat /proc/1/comm
ls -al /sbin/init

To see a tree of processes, with systemd as the first process in the tree, use the pstree command from the process utilities package:

apt-get psmisc
pstree

To see the services managed by systemd, use the systemctl command. You can use the command to display all services, and for example to get a count of all active services and a count of all running services:

systemctl
systemctl | grep active | wc -l
systemctl | grep running | wc -l

Now change the first process to run from systemd to the init program from the sysvinit package. Install the package (and a required package dbus-x11) and reboot for this change to take effect:

apt-get install sysvinit-core dbus-x11
reboot

Once the system has restarted, running the commands to find out what the first process' command is and what the system initialisation daemon is will now show the /sbin/init program from the sysvinit package:

cat /proc/1/comm
ls -al /sbin/init

Now run the pstree command and note that init is the first process:

pstree

Running systemd's systemctl command will display a message to let you know that the system has not been initialised with systemd.

The inittab file tells the init program what to do. You can have a look at the contents:

cat /etc/inittab | less

To see all the processes, and to specifically see all the active and all the running processes, run:

service --status-all | less
service --status-all | grep active
service --status-all | grep running

A Note on System Startup

See initrd for more details on system startup.

Build a Custom Debian Installer

Now that we know how to switch out the first running process, let's build a custom Debian installer that sets up sysvinit as the initialisation system.

Restore the virtual machine state to the snapshot saved when Debian was just installed.

Install the live-build, live-boot and live-config packages. The source code for these packages is of course available, so these can also be built from source and installed.

apt-get install live-build live-boot live-config

Create a working folder called live-installer. Configure the installer system with the live-build configuration command, specifying Debian 8 or Debian jessie as the distribution version, since Debian 10 does not officially support sysvinit, and of course specifying sysvinit as the initialisation system (line 2). Add any required third-party packages to the installer, in this case the Broadcom wireless networking package as an example (lines 3 and 4). Generate the package installation list with a helper function for the grep-aptavail command (line 5). Add the GNOME desktop environment to the desktop installer environment (line 6). Add the Debian installer launcher to the live installer environment (line 7). See the Debian Live Manual for more details on configuring and customising a Debian live system.

mkdir live-installer && cd live-installer
lb config --distribution jessie --architectures amd64 --initsystem sysvinit --bootappend-live "boot=live components" --debian-installer live
wget http://deb.debian.org/debian/pool/non-free/b/broadcom-sta/broadcom-sta_6.30.223.271.orig.tar.xz
cp broadcom-sta_6.30.223.271.orig.tar.xz config/packages.chroot
echo '! Packages Priority standard' > config/package-lists/standard.list.chroot
echo task-gnome-desktop > config/package-lists/desktop.list.chroot
echo debian-installer-launcher > config/package-lists/installer.list.chroot

Build the Debian installer with the live-build command. Note that this will take a while.

lb build

When the build process completes, connect a USB drive to your machine and connect it to VirtualBox, identify it in the virtual machine, and write the installer disk image to the USB drive:

ls -al /dev/sd*
dd if=live-image-amd64.hybrid.iso of=/dev/[device-example-sdb]

Disconnect the USB drive from VirtualBox, but not your machine yet, so that you can extract a disk image file using Disk Utility:

Now you have a custom Debian live system and installer on a USB drive, and as a saved disk image, that installs a Debian system with sysvinit's init program as the first running process.

Running the Custom System

Let's test the custom Debian installer in VirtualBox. Close the running Debian virtual machine, and add a new virtual machine, setting the memory size and setting up a new virtual hard disk (dynamically sized is fine and 10 GB will do), and remember to go into the machine settings and to increase the number of virtual processors if your system allows for it.

Use the custom Debian installer disk image extracted from the USB drive just now as the disk to boot from when starting the virtual machine.

You will be presented with the startup menu. Select the graphical install option.

Run through the installer. You can use the same settings as when installing the Debian 10 virtual machine previously.

When the installation completes. the system will restart and you will be presented with the graphical login prompt.

After logging into the GNOME desktop environment, select Activities and search for and open the Terminal application.

Running the commands to find out what the first process' command is and what the system initialisation daemon is will show the init program from the sysvinit package: