Administration of Packages and Services in FreeBSD / OpenBSD / NetBSD

Administration of Packages and Services in FreeBSD / OpenBSD / NetBSD

06.03.2024
Author: HostZealot Team
2 min.
244

FreeBSD, OpenBSD, and NetBSD are operating systems that present an alternative to Linux in the paradigm of UNIX-like operating systems. They are too frequently used as server operating systems, having their advantages as well as specificities. Today we are particularly going to explore package administration within these three OS.

Exploring FreeBSD

Among the protagonists of the article, FreeBSD is the most popular one. It’s key features are:

Portability: It is available on x86, ARM, AArch64, RISC-V, POWER, and PowerPC architectures.

Stability and reliability: FreeBSD is often praised for stability and reliability. Besides this, the system is highly suitable for networking with the TCP/IP stack.

Virtualization Jails: Virtualization Jails are lightweight in-built virtualization solutions for creating isolated environments and enhancing security and resource management.

Ports collection: Ports collection is a powerful framework for managing and installing third-party applications.

ZFS file system: FreeBSD supports the ZFS file system, with features like data integrity verification, support for large storage capacities, efficient data compression, and robust snapshot capabilities.

Security: Among others, things FreeBSD has a focus on security, which is expressed in a proactive security team, regular security updates, and a default installation that prioritizes secure configurations.

Overview of OpenBSD

Another 4.4BSD-based UNIX-like multiplatform operating system with a focus on portability, standardization, correctness, security, and integrated cryptography. OpenBSD is available for free. It’s developed by enthusiasts and has been used for a series of successful projects.

Key Features of NetBSD

NetBSD is a free and open-source UNIX-like OS. Its features encompass:

Portability: NetBSD is highly portable, supported on x86, ARM, MIPS, SPARC, PowerPC, and more.

Cross-platform compatibility: The package system of NetBSD is highly portable and cross-platform, allowing you to build and install software packages on various Unix-like operating systems.

Modern storage technologies support: NetBSD supports ZFS filesystems, RAIDframe software, RAID systems, and cgd disk encryption.

ARM hardware support: NetBSD has robust support for ARM architectures, making it versatile for use on a variety of ARM-based devices, ranging from embedded systems to single-board computers and ARM-based servers.

Xen and NVMM virtualization support: This virtualization support enables users to run multiple operating systems concurrently on the same hardware, with each operating system running in its own isolated virtual environment.

Modern x86 hardware support: NetBSD offers strong support for modern x86 hardware, including compatibility with a wide range of processors, chipsets, and peripherals commonly found in modern PC systems.

Administration of Packages and Services in FreeBSD, OpenBSD, and NetBSD

1. Managing Packages and Services in FreeBSD

The installation of third-party software in FreeBSD occurs with the help of two technologies – FreeBSD Ports Collection and FreeBSD Package Manager.

FreeBSD Ports Collection presents a set of files that are used for automating the compilation of an app from the source code. This set of files contains the information necessary for automatic downloading, extractions, patching, compiling, and installation of an app.

Also, there is a great number of apps that are already ported to FreeBSD and can be downloaded in a pre-compiled form.

As for FreeBSD package management commands, they are used to perform a variety of activities with packages. Such manipulations as register, add, remove, upgrade and more are performed with the help of the pkg packages manager.

Both approaches know how to deal with dependencies.

In the case a library misses while an app is installed, this will be added automatically.

Utilizing the Ports Collection

The port collection consists of a set of makefiles, that is different types of files involved in the compilation and installation of an app on FreeBSD. The original directory for the port collection is /usr/ports/.

In the Ports Collection, you can find directories for each category of software, which in turn are broken down into sub-directories, with files that are basically instructions on the compilation and the installation of an app, which are commonly referred to as ports skeleton. The basic files and directories for a ports skeleton are:

makefile: Contains instructions on the compilation and the location of components to be installed.

distinfo: Contains names and checksums of files that should be downloaded for building the port.

files/: patches required for compilation and installation.

pkg-descr: A detailed program description.

pgk-plist: The list of files to be installed.

Procedures for Port Installation and Upgrades

The FreeBSD port collection is a system used for managing and installing third-party applications on your FreeBSD system. Let’s review some of its basic commands.

  • Updating the ports tree, a necessary operation to be performed before installing or  updating anything:
sudo portsnap fetch update
  • Navigating to the Poer Directory: Each software package has its own directory in the Ports Collection. You might want to navigate between directories for the installation of diverse software. For example, in case you want to install Apache web server, you would need to go to the Apache directory:
cd /usr/ports/www/apache24
  • Review and Customize Options: In many ports, you can customize the software before you install it. With the “make config” command you can open a menu with the available options:
  • After all the options have been configured, you can compile and install the software with the command:
make install clean
  • In the FreeBSD Ports system dependencies are handled automatically. This means that if the app you’re installing relies on other packages, the Ports system will make sure these dependencies are also installed.
  • Upgrading installed ports: For upgrading a port that is already installed, you should navigate to its directory and execute the make upgrade command:
cd /usr/ports/www/apache24
make upgrade

This way you will fetch the latest source code, recompile the software, and upgrade it to the latest version.

  • To remove a port, you should use the make deinstall command:
make deinstall

While the software will be uninstalled, the dependencies will remain.

  • If you need to find one particular port, use the make search command:
make search keyword=nginx

Additional tools: Apart from the ones described above, there are a number of additional tools used for managing ports, such as portmaster, poudriere, and others.

Service Management in FreeBSD

Let’s have a look at how to manage services on FreeBSD.

To start Nginx Web Service in FreeBSD, you need to modify nginx_enable to YES in /etc/rc.conf file:

nginx_enable="YES"

Then execute the command:

$ sudo /usr/local/etc/rc.d/nginx start

Or:

$ service nginx start

Conversely, to stop Nginx Web Server Service:

$ sudo /usr/local/etc/rc.d/nginx stop

Or:

service nginx stop

To restart the Nginx Web Server service:

$ sudo /usr/local/etc/rc.d/nginx restart

Or:

sudo service nginx restart

To check the Nginx configuration file for errors:

$ sudo nginx -c /usr/local/etc/nginx/nginx.conf -t

2. Managing Packages and Services in NetBSD

To manage and install third-party software in NetBSD, the pkgsrc framework is used. The framework can be used either to install package tools or to use binary packages that have been pre-made, or to build your own packages, combining them with third-party packages.

Installation of Binary Packages using pkgin

NetBSD by default covers binaries for lots of software packages. A common way to install them is with pkgin in the default /usr/pkg/ directory.

In case pkgin is not installed yet, you can do it on your own:

sudo pkg_add pkgin

Package update:

sudo pkgin update && pkgin upgrade -y

Search for a package:

pkgin search <pkg_name>

Package installation:

pkgin install <pkg_name>

Installing and searching for Nginx web server:

$ sudo pkgin install nginx
$ pkgin search nginx

The list of packages installed:

$ pkgin list

To see available for pkgin:

$ pkgin help

Removing a package:

$ sudo pkgin remove nginx

System Service Management

In NetBSD system startup and services management is performed through rc(8) system stored at /etc/rc.d.

Let’s see how to install and manage Apache as an example:

sudo pkgin install apache

Restart:

$ sudo /etc/rc.d/httpd onerestart

Otherwise you can edit /etc/rc.conf and enable httpd:

sudo vim /etc/rc.conf


##Enable httpd##
httpd=YES

Restart:

$ sudo service httpd restart

Stop:

$ sudo service httpd stop

Run httpd on startup on port 8080 edit the file adding:

$ sudo vim /etc/rc.conf
##Add this parameter##
httpd_flags='-I 8080'

Restart.

3. Handling Packages and Services in OpenBSD

pkg_add is the package manager of OpenBSD that is used particularly for installing third-party apps in binary format.

If sudo has been already installed, edit the sudo file so user details are included:

# pkg_add sudo
#visudo

First, update your system packages:

sudo pkg_add -u

Installing a package:

sudo pkg_add <pkg_name>

Removing a package:

sudo pkg_delete <pkg_name>

Finding an installed package:

pkg_info -Q <pkg_name>

Display info on packages:

pkg_info <pkg_name>

Service Management (System Daemons)

System daemons are regulated through the rc(8) script via rc.d(8). Most services and daemons are installed on OpenBSD through variables from  /etc/rc.conf.

Instead of modifying the config file, it’s generally more convenient to use the rcctl utility to avoid making changes in the file that could potentially interfere with upgrades.

To install Apache and manage services:

sudo pkg_add php
sudo pkg_add php-apache
sudo pkg_add php-mysqli

Enabling Apache:

sudo rcctl enable apache2

Starting Apache service:

sudo rcctl start apache2
apache2(ok)

Checking the status of Apache2:

rcctl check apache2      
apache2(ok)

Stopping the Apache2 service:

$ sudo rcctl stop apache2
apache2(ok)

Conclusion

This was the overlook of the package and service management of FreeBSD, OpenBSD, and NetBSD. We hope that we’ve covered all the essential basics and now you’ll have more confidence when getting acquainted with these operating systems. Good luck!

Related Articles