fsadm Command in Linux



The fsadm command in Linux checks and resizes the filesystem on a device. The device can also be the dm-crypt encrypted device. The dm-crypt kernel-level encryption system allows users to encrypt files, partitions, and disks.

The fsadm command uses the same API for various filesystems such as ext2, ext3, ext4, ReiserFS, and XFS. Moreover, it is a simple and easy-to-use utility for checking and managing the filesystem on Linux.

Table of Contents

Here is a comprehensive guide to the options available with the fsadm command −

Syntax of fsadm Command

The syntax for checking the filesystem using the Linux fsadm command is as follows −

fsadm [options] check [device]

The syntax for resizing the filesystem using the fsadm command is given below −

fsadm [options] resize [device] [size]

The [options] field is used to specify the options to modify the command's behavior. While [device] is used to specify the device that needs to be checked and resized. The [size] field is used to specify the new size in [B|K|M|G|T|P|E] of the device that is to be resized.

Note − If the size is not specified the fsadm command will resize the filesystem using the entire available space of the underlying device.

Options of fsadm Command

The options used with the fsadm command are listed in the following table −

Flags Options Description
-e --ext-offline It unmounts the filesystem before resizing
-f --force It bypasses the checks
-h --help It displays help
-l --lvresize It allows resizing of the logical volume
-n --dry-run To execute the command without making the changes
-r --resizefs It automatically resizes the filesystem when used with -l / --lvresize
-v --verbose It displays a detailed output
-y --yes It answers yes to any prompt
-c --cryptresize It resizes the logical volume that is encrypted using dm-crypt

Examples of fsadm Command in Linux

This section demonstrates the usage of the Linux fsadm command in Linux with examples −

Checking Filesystem

To check the filesystem of a device, use the check argument −

sudo fsadm -v check /dev/vda2
fsadm Command in Linux1

The -v option is used for verbose output.

sudo fsadm -v check /dev/mapper/ubuntu--vg-ubuntu--lv
fsadm Command in Linux2

The /dev/mapper/ubuntu--vg-ubuntu--lv is the logical volume.

Resizing a Filesystem

To resize a filesystem using the fsadm command, use the resize option −

sudo fsadm -e resize /dev/vda2 1G
fsadm Command in Linux3

The -e option unmounts the filesystem before resizing.

Resizing a Filesystem with Verbose Output

To get a detailed output while resizing a filesystem, use the -v or --verbose option with the fsadm command −

sudo fsadm -v resize /dev/vda2 1G
fsadm Command in Linux4

Resizing a Logical (LVM) Device

To resize the logical volume, use the -l or --lvresize option −

sudo fsadm -l resize /dev/mapper/ubuntu--vg-ubuntu--lv 1G
fsadm Command in Linux5

Resizing an Encrypted Filesystem

If the volume is encrypted with the dm-crypt encryption system, then it can be resized using the -c or --cryptresize option −

sudo fsadm -c resize /dev/mapper/ubuntu--vg-ubuntu--lv 1G

Dry Running the Filesystem Resize

To dry run the filesystem resize, use the -n or --dry-run option −

sudo fsadm -l -n -v resize /dev/mapper/ubuntu--vg-ubuntu--lv 1G
fsadm Command in Linux6

This command will not make any changes to the filesystem, it will just demonstrate the process.

Conclusion

The fsadm command in Linux is used to identify and resize the filesystem. It is a handy filesystem management tool that can do both check and resize the filesystem. It can also be used to resize the logical device, and dm-crypt encrypted devices.

Advertisements