For the complete documentation index, see llms.txt. This page is also available as Markdown.

26.2 Linux File Systems

FreeBSD provides native support for some Linux file systems. This section demonstrates how to load and mount these supported Linux file systems.

EXT Series File Systems

Since FreeBSD 2.2, the kernel has supported the ext2 file system from the Extended File System (EXT) series. FreeBSD 9.0 merged important allocation code from NetBSD's clean-room implementation, making the ext2fs driver BSD-licensed. Starting from FreeBSD 12.0-RELEASE, the ext2fs driver natively supports mounting ext4 file systems in read-write mode, but does not support journaling and encryption features.

Warning

Since FreeBSD's ext2fs driver does not support ext4 journaling, mounting ext4 file systems in read-write mode may result in data corruption or metadata inconsistency in the event of unexpected power loss, system crash, or improper shutdown. In severe cases, the file system may become unmountable. Do not perform write operations on ext4 volumes containing critical data, or ensure the device is connected to a UPS or other power loss protection.

Formatting a Disk as Ext4 File System

The Port filesystems/e2fsprogs must be installed separately; it provides the mke2fs tool for formatting disks to ext format.

  • Create a GPT partition table

# gpart create -s gpt ada0
  • Create a partition containing all remaining space

# gpart add -t linux-data ada0
  • Format as Ext4

# mke2fs -t ext4 /dev/ada0p1
  • Verify the file system used by the /dev/ada0p1 partition:

# fstyp /dev/ada0p1
ext2fs

Test Mounting an Ext4 File System

  • Create the mount directory /home/ykla/test:

Adjust according to the actual path; the same applies below.

  • Mount partition /dev/ada0p1 to /home/ykla/test:

  • Verify the mount status

  • Try reading and writing some files:

Btrfs and XFS File Systems

fusefs-lkl is a FUSE implementation based on the Linux Kernel Library (LKL). By running Linux kernel code in user space, it provides complete support for Btrfs, XFS, and other Linux file systems. Compared to fusefs-ext2, fusefs-lkl supports a wider range of file system types but with slightly lower performance.

For ease of demonstrating mount operations, this section assumes an example environment containing multiple Linux file system partitions for verifying each mount method.

Display partition information for the nda1 device:

The -p parameter displays full device paths.

The example partitions are pre-configured with files and directories for subsequent mount verification.

The relevant directory structure is as follows:

Installing fusefs-lkl

  • Install using pkg:

  • Or install using Ports:

Loading the FUSE Kernel Module

fusefs is the FUSE framework kernel module for FreeBSD, providing underlying support for all FUSE-based file systems. Run the following command to add it to the system startup load list:

The above command makes the configuration persistent. To apply it immediately, run:

Test Mounting a Btrfs Partition

Use lklfuse to mount the Btrfs partition nda1p2 to /home/ykla/btrfs:

Test Mounting an XFS Partition

Use lklfuse to mount the XFS partition nda1p4 to /home/ykla/xfs:

Troubleshooting and Outstanding Issues

Unmounting File Systems

Use the umount command to unmount file systems. Before unmounting, ensure that no processes are accessing the mount point; otherwise, the unmount will fail. If the mount point is busy, use umount -f to force unmount (which may cause undefined behavior in applications accessing the file system). The basic syntax is:

Persistent Mount Configuration

Persistent mounting can be configured by writing entries to the /etc/fstab file. For FUSE file systems, pay attention to mount parameters and the delayed mount option latelate ensures the file system is mounted only after the system has finished booting, preventing boot failures caused by FUSE dependencies not being ready.

References

Last updated