How to use the command "resize2fs" (with examples)

How to use the command "resize2fs" (with examples)

Resize automatically the filesystem

resize2fs /dev/sdXN

Motivation

The motivation for automatically resizing a filesystem is when you want to adjust the size of the filesystem to match the size of the underlying partition. This can be useful in cases where you have resized a disk partition and want the filesystem to utilize the additional space.

Explanation

The resize2fs command with the specified device /dev/sdXN automatically resizes the ext2, ext3, or ext4 filesystem on the specified partition. The command will adjust the filesystem to utilize the full size of the partition. It does not resize the underlying partition itself.

Example Output

resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/sdXN to 12345678 (4k) blocks.
Begin pass 1 (max = 10023)
...

Resize the filesystem to a size of 40G, displaying a progress bar

resize2fs -p /dev/sdXN 40G

Motivation

The motivation for resizing the filesystem to a specific size is when you want to allocate a specific amount of space for the filesystem. This can be useful when you want to limit the size of the filesystem or when you want to allocate more space for the filesystem to accommodate growing data.

Explanation

The resize2fs command with the -p option and the specified device /dev/sdXN resizes the ext2, ext3, or ext4 filesystem on the specified partition to the specified size of 40G. The -p option displays a progress bar during the resizing process.

Example Output

resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/sdXN to 41943040 (4k) blocks.
Begin pass 1 (max = 10023)
...

Shrink the filesystem to its minimum possible size

resize2fs -M /dev/sdXN

Motivation

The motivation for shrinking a filesystem to its minimum possible size is to reclaim unused space on the filesystem and reduce its size. This can be useful when you want to free up disk space or when you need to reduce the size of the filesystem to match the available partition space.

Explanation

The resize2fs command with the -M option and the specified device /dev/sdXN shrinks the ext2, ext3, or ext4 filesystem on the specified partition to its minimum possible size. This operation will reclaim any unused blocks on the filesystem and reduce its size to the minimum required.

Example Output

resize2fs 1.45.6 (20-Mar-2020)
Resizing the filesystem on /dev/sdXN to 123456 (4k) blocks.
Begin pass 1 (max = 10023)
...

Related Posts

How to use the command lrzip (with examples)

How to use the command lrzip (with examples)

The lrzip command is a tool used for compressing large files.

Read More
ipset (with examples)

ipset (with examples)

1: Creating an empty IP set Code: ipset create set_name hash:ip Motivation: Creating an empty IP set allows us to later add IP addresses to this set.

Read More
Monitoring All Occurring X Events (with examples)

Monitoring All Occurring X Events (with examples)

Code xev Motivation The motivation behind using this example is to monitor all occurring X events in a Linux system.

Read More