How To - Create XFS or EXT4 Filesystem using LVM
How to create a new 6GB xfs filesystem using LVM:
Note: Performing these steps outside of single-user mode can cause unexpected issues. Please inform the customer before making any changes and ensure all users are logged off before beginning.
1. Identify the current disks by listing the device files in the /dev directory (disks are /dev/sda, /dev/sdb, /dev/sdc, etc…) Look at the last /dev/sdc and predict the next disk identifier (e.g, if /dev/sdc is the current last disk, then the next one will be /dev/sdd).
- You can optionally check the same by using command # fdisk -l
2. After UT-V confirms the new disk has been added to the host virtual machine. To avoid a reboot, you may rescan your devices if the new disk is not yet discovered by the system in /dev directory.
# echo "- - -" > /sys/class/scsi_host/host0/scan (If the request was to add a new separate disk)
- You may need to replace ‘host0’ to ‘host1’ depending on the output from command # ls /sys/class/scsi_host
# echo 1 > /sys/class/scsi_device/0\:0\:0\:0/device/rescan (If the request was to increase existing disk)
- You may need to replace ‘0\:0\:0\:0’ with the actual scsi bus name found with command # ls /sys/class/scsi_device. This will rescan the current scsi bus and the newly increased disk size will show up.
- /dev/xvdf is the new disk detected in this instance (From screenshot above)
3. Find the new partition on newly discovered disk /dev/xvdf
# fdisk -l (To list existing disk and partition information)
# fdisk /dev/xvdf
'n' for creation of a new partition.
'p' for creation of a primary partition.
'1' for creation of partition #1.
'1' or 'enter' for the identification of the first cylinder (default value).
'enter' Accept the default value for the last partition if you want to utilize complete disk space or provide custom size for your use case in GB or MB ( ex= '+7G' for 7 GB partition )
't' to change the partition type to LVM
'L' to list all HEX codes
'8e' or “8e00” changes partition type to Linux LVM. Pick the appropriate one for your O/S version.
'p' to print the partition table and verify the partition was defined correctly ( /dev/xvdf1 )
'w' to write out the new partition table on the new disk.
kpartx to make kernel aware of newly created partition without a need of reboot.
The new partition should appear as /dev/xvdf1
5. Create a physical volume from newly created partition (syntax: pvcreate /dev/PartitionName)
This will be used to extend the existing volume group ( testvg ).
# pvcreate /dev/xvdf1
6. Create or extent a volume group (syntax: vgcreate NewVolumeGroupName /dev/PartitionName)
# vgcreate vgtest /dev/xvdf1
# vgextend vgtest /dev/xvdf1
7) Create or extend a logical volume (syntax: lvcreate -L LogicalVolumeSize -n LogicalVolumeName VolumeGroupName)
# lvcreate -L 6G -n lvtest vgtest
# lvextend -l -6 lvtest vgtest
8. Following commands will list information about Physical volumes, Volumes groups and Logical volumes
# pvdisplay or pvs
# vgdisplay or vgs
# lvdisplay or lvs
9. Create “xfs” filesystem on top of logical volume and create a new directory which is served as a mount point for the new filesystem.
XFS is a high-performance 64-bit journaling file system. XFS file system is the default file system on RHEL 7 and higher.
XFS excels in the execution of parallel input/output (I/O) operations due to its design, which is based on allocation groups, because of this, XFS enables extreme scalability of I/O threads, file system bandwidth, and size of files and of the file system itself when spanning multiple physical storage devices. A disadvantage of the XFS file system is that it cannot be shrunk, also metadata operations in have historically been slower than with other file systems, resulting in, for example, poor performance with operations such as deletions of large numbers of files.
For xfs type filesystem:
# xfs_growfs /dev/VolumeGroupName/LogicalVolumeName
For ext4 type filesystem:
# resize2fs /dev/VolumeGroupName/LogicalVolumeName
10. Mount the filesystem (if needed)
Syntax: (mount /dev/VolumeGoupName/LogicalVolumeName /MountPoint)
# mount /dev/vgtest/lvtest /root/xfsmount
11. Edit and add an entry in /etc/fstab to mount the filesystem permanently. (if needed)
The last number in etc/fstab entry (here 2) is related to the fsck command: ‘0‘ means no fsck run at boot ‘1‘ fsck is run first (root filesystem), ‘2‘ fsck is run just after the root filesystem. The second to last argument is in relation with the dump command (normally set at ‘1‘ for real filesystems, ‘0‘ for swap and NFS mounted filesystems).
Best practice is to execute the mount -a command, each time you change something in the /etc/fstab file to detect any boot problem before it occurs.
# df -h