Applying Your Linux Skills to macOS: Devices and System Initialization

The latest installment of the Linux + macOS series focuses on working with macOS devices and system initialization.

A Macbook with the headline Talk Tech to Me: Linux + macOSThis article is part four in a series about using Linux skills when working in a mac operating system. Check out the other articles in the series:

Working with macOS Devices

In Linux, device drivers were either compiled into the Linux kernel and referenced using a block or character device file in the /dev directory or loaded into the Linux kernel as a module. While macOS has a somewhat similar structure – the /dev directory has several block and character device files for many system devices – the names of those device files are different.

For example, the first SATA/SCSI hard disk in Linux is represented by the block device file /dev/sda, and the first primary partition on this hard disk would be represented by the block device file /dev/sda1.

But in macOS, all hard disks typically contain a single partition that is sliced into filesystems.

Block Device File Default Settings

  • /dev/disk0 refers to the whole partition on the
  • first hard disk
  • /dev/disk0s1 refers to the first slice within this partition
  • /dev/disk0s2 refers to the second slice within this partition

Since partition and slice operations cannot be done with block device files in Linux, there are also character (or raw) device files for all disks (e.g., /dev/rdisk0, /dev/rdisk0s1, /dev/rdisk0s2). Block device files within macOS are primarily used for mounting filesystems.

On Linux systems, any device that does not have a device file in the /dev directory typically loads its device driver into the kernel itself from the /lib/modules directory structure. The same is true within macOS, however these modules are called kernel extensions (*.kext) and are loaded into the XNU kernel from the /System/Library/Extensions directory structure.

To view the currently loaded kernel extensions, simply type the kextstat command. Similarly, the kextload and kextunload commands may be used to load and unload kernel extensions.

Alternatively, you can use the /Applications/Utilities/System Information utility to view loaded kernel extensions.

macOS System Initialization

Modern Intel-based Apple computers use an EFI BIOS that controls the loading of the macOS bootloader. To pause the system during startup, simply press the Option key (Alt key on a Windows keyboard) – the EFI BIOS will then scan your hard disk partitions, CD/DVD devices and USB ports for operating systems and allow you to select the operating system to boot (which could include the macOS installation app from a USB stick).

You can also press Command+V on an Intel-based Apple computer during boot time to view detailed information about the boot process as well as interact with the macOS boot process itself (the Command key on an Apple keyboard is the same as the Windows key on a PC keyboard).

The bootloader in macOS is called boot.efi. It is stored in the first slice on the hard disk that contains your operating system (in the /System/Library/CoreServices directory). If the bootloader is missing on the volume, you will see a circle with slash icon, otherwise the bootloader loads the XNU kernel (/System/Library/Kernels/kernel). XNU in turn starts the Launch Daemon (launchd), which is very similar to the systemd daemon on newer Linux systems.

The launchd daemon then loads all other system daemons to bring the system to a useable state via entries within the /Library/LaunchAgents and /Library/LaunchDaemons directories, as well as any optional apps listed in the /System/Library/StartupItems directory. Pressing the Command+S key combination at boot time instructs launchd to boot to Single-User Mode (Runlevel 1 in Linux). As in Linux, Single-User Mode is a useful place to perform system administration or repair the filesystem, since there are few processes loaded to interfere with these tasks.

To list available services (daemons) after system initialization, simply switch to the root user (su - root) and use the launchctl list command. You can then stop and start services using the appropriate arguments to the launchctl command (view the man page for available options).

I hope you found this series helpful! Be sure to check out all of our Linux articles for more tips.

Round out your IT skill set with CompTIA Linux+.

Email us at blogeditor@comptia.org for inquiries related to contributed articles, link building and other web content needs.

Read More from the CompTIA Blog

Leave a Comment