Introduction
LVM is a tool used for volume management which includes striping, resizing and mirroring of logical volumes, and XFS is an high performance file system created by silicon graphics, it is the default file system for Rhel7/CentOS 7 operating systems, it supports quick crack recovery, is is used when large amount of data is required to be stored.Some of LVM based articles has been published already with unixmen.com, you can access some of them on following links:
Increase Disk Space And Memory In Linux VMware Virtual Machines
Procedure
We will be using Ubuntu 15.10 ,add some extra hard disk space to Your demo system, let us have a extra piece of 10 GB space:
# fdisk /dev/sdb
Create primary file system, change File system, by typing t, and have a look on available file systems and select 8e type file system, save and exit:
Welcome to fdisk (util-linux 2.26.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table. Created a new DOS disklabel with disk identifier 0x8d3381ac. Command (m for help): p Disk /dev/sdb: 1.1 GiB, 1138817024 bytes, 2224252 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0x8d3381ac Command (m for help): n Partition type p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): o Value out of range. p primary (0 primary, 0 extended, 4 free) e extended (container for logical partitions) Select (default p): p Partition number (1-4, default 1): First sector (2048-2224251, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-2224251, default 2224251): Created a new partition 1 of type 'Linux' and of size 1.1 GiB. Command (m for help): t <-FILE SYSTEM TYPE Selected partition 1 Partition type (type L to list all types): 8e <-SELECTED FILE SYSTEM TYPE Changed type of partition 'Linux' to 'Linux LVM'. Command (m for help): w <-SAVE AND EXIT The partition table has been altered. Calling ioctl() to re-read partition table. Syncing disks.
Create LVM
First Create physical volume, then Volume group followed by Logical volume:
root@user:/home/user# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created root@user:/home/user# vgcreate um_vg /dev/sdb1 Volume group "um_vg" successfully created root@user:/home/user# lvcreate -L +1G -n xfs_lv um_vg Logical volume "xfs_lv" created.
Now, create XFS file system, before that install xfs file system utilities in Ubuntu
# apt-get install xfsprogs
Create a directory where this xfs file system will be mounted
# mkdir /home/user/xfs
Create .xfs file system
# mkfs.xfs /dev/um_vg/xfs_lv
Sample output
Display all 214 possibilities? (y or n) root@user:/home/user# mkfs.xfs /dev/um_vg/xfs_lv meta-data=/dev/um_vg/xfs_lv isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal log bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0
Mount file system on the created directory
# mount -t xfs /dev/um_vg/xfs_lv /home/user/xfs/
Have a look
# df -Th /home/user/xfs/ Filesystem Type Size Used Avail Use% Mounted on /dev/mapper/um_vg-xfs_lv xfs 1014M 33M 982M 4% /home/user/xfs
Extend LVM size
root@user:/home/user# lvextend -L +10M /dev/um_vg/xfs_lv -r
Sample output
Rounding size to boundary between physical extents: 12.00 MiB Size of logical volume um_vg/xfs_lv changed from 1.01 GiB (259 extents) to 1.02 GiB (262 extents). Logical volume xfs_lv successfully resized meta-data=/dev/mapper/um_vg-xfs_lv isize=256 agcount=4, agsize=65536 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=262144, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=2560, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 262144 to 268288
Again have a look on mounted file system whether it got extended or not
#df -h /dev/um_vg/xfs_lv
Sample output
Filesystem Size Used Avail Use% Mounted on /dev/mapper/um_vg-xfs_lv 1.1G 33M 1006M 4% /home/user/xfs
Now, compare with previous file size, you will notice that file system size got increased automatically as we are using XFS file system.
Have a nice day!!