Scott Reeves explains how LVM and fsadm can be used to grow ext4 file systems without incurring any downtime for critical applications — even while the file system is being expanded.
One aspect of moving towards a highly available, always up system is being able to add space to a server without having to shutdown the applications and without having to unmount file systems. LVM on HP-UX has been used for many years to provide online file system expansion. The version of LVM used on Linux has many similar features to the versions used on HP-UX. LVM and ext4 combined are a giant leap to being able to run mission critical applications on Linux systems.
The process of growing a file system consists of two parts. The first part is to grow the logical volume, whilst the second part is to grow the file system. It is possible to grow a logical volume online; however, earlier file system types were not able to be resized online. Growing the file system required the file system to be un-mounted. This example uses ext4 file systems which can be resized when mounted.
The command used to extend a logical volume is called lvextend. There are a few options that can be used with this command. The main ones used are -L, where the size can be specified in Megabytes, Gigabytes, Terabytes, Petabytes or Exabytes and -l, where the size can be specified in extents. Using a '+' sign in front of the extents or size means that the logical volume is to be grown by the specified size or by the specified number of extents. Omitting the ‘+' means grow the logical volume to the specified size.
For example, typing in
lvextend -L +1024M /dev/vg01/db01
means grow the logical volume another 1024 Megabytes.
lvextend -L 2048M /dev/vg01/db01will extend the logical volume size up to 2048 Megabytes. For the purpose of this example, the two commands shown produce the same result: the logical volume is grown to 2048 Megabytes in size. Figure D shows the command string used in this example. The -v option is for verbose output.
The logical volume is now 2GB. The next step is to use fsadm to grow the file system online. For this example, fsadm is run with the options shown in Figure F. Note that if the size is omitted, fsadm will grow the file system up to the same amount occupied by the logical volume. Again, the -v option is for verbose and can be omitted.
In summary, LVM and fsadm can be used to grow ext4 file systems without incurring an outage. For Linux, this is a substantial feature, as it allows highly critical applications to keep running even when the underlying file system is being expanded.