November 18

Linux: Expanding a raw xfs drive

Example:
------------------------------------------------
/data is mapped to a second attached hard drive /dev/sdb

[[email protected] ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Mon Mar  5 08:08:09 2018
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root   /                       xfs     defaults        0 0
UUID=90afc952-90eb-48bd-9cf4-f1790f23e159 /boot                   xfs     defaults        0 0
/dev/mapper/rhel-usr    /usr                    xfs     defaults        0 0
/dev/mapper/rhel-var    /var                    xfs     defaults        0 0
/dev/mapper/rhel-swap   swap                    swap    defaults        0 0
/dev/sdb		/data			xfs	defaults	0 0

Using the command pvs, we determined that LVM was not used on this volume

------------------------------------------------
1. Verify the drive mappings and space

[[email protected]~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               5.8G     0  5.8G   0% /dev
tmpfs                  5.8G     0  5.8G   0% /dev/shm
tmpfs                  5.8G   34M  5.8G   1% /run
tmpfs                  5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   15G  1.9G   14G  13% /
/dev/mapper/rhel-usr   5.0G  3.8G  1.3G  76% /usr
/dev/sdb               100G   92G  8.6G  92% /data
/dev/sda1              3.0G  288M  2.8G  10% /boot
/dev/mapper/rhel-var    15G  2.4G   13G  16% /var
tmpfs                  1.2G     0  1.2G   0% /run/user/0
tmpfs                  1.2G     0  1.2G   0% /run/user/990
tmpfs                  1.2G   12K  1.2G   1% /run/user/42
tmpfs                  1.2G     0  1.2G   0% /run/user/1000

2. Determine if LVM was used on the target drive /dev/sdb
[[email protected] ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <37.00g    0 

In our case it was not used as you can see their is no reference above.


3. Determine which file system was installed on the drive /dev/sdb
[[email protected] ~]# blkid
/dev/mapper/rhel-var: UUID="0d05bcc2-b292-4e9f-a34a-b93539fbd8c0" TYPE="xfs" 
/dev/sda2: UUID="NQlV2B-EhAF-O7j2-hUDj-q2U8-EVCY-8obFEc" TYPE="LVM2_member" 
/dev/sda1: UUID="90afc952-90eb-48bd-9cf4-f1790f23e159" TYPE="xfs" 
/dev/sdb: UUID="93f4b905-330e-4a89-ad9f-454067886d70" TYPE="xfs" 
/dev/mapper/rhel-root: UUID="557b5ecd-0c1c-4c41-af04-827b5427e90b" TYPE="xfs" 
/dev/mapper/rhel-swap: UUID="a742138f-ae4a-4801-b8e0-d76a5260775a" TYPE="swap" 
/dev/mapper/rhel-usr: UUID="507a540b-3edd-4cee-9440-cfe7187bb43e" TYPE="xfs" 

4. Verify the current seen drive size
[[email protected]~]# fdisk -l /dev/sdb
Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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


5. Expand the drive in VCENTER if this is a virtual machine.  Make certain to select the correct drive

6. recan the target drive for changed information
[[email protected]~]# echo 1>/sys/class/block/sdb/device/rescan

7. Check the drive to verify the the OS see the new drive size
[[email protected]~]# fdisk -l /dev/sdb
Disk /dev/sdb: 161.1 GB, 161061273600 bytes, 314572800 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

8. Expand the xfs partition to take all of the additional space.
[[email protected]~]# xfs_growfs /dev/sdb
meta-data=/dev/sdb               isize=512    agcount=4, agsize=6553600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=26214400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=12800, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 26214400 to 39321600

9. Verify that the drive was expanded
[[email protected]~]# df -h
Filesystem             Size  Used Avail Use% Mounted on
devtmpfs               5.8G     0  5.8G   0% /dev
tmpfs                  5.8G     0  5.8G   0% /dev/shm
tmpfs                  5.8G   34M  5.8G   1% /run
tmpfs                  5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/mapper/rhel-root   15G  1.9G   14G  13% /
/dev/mapper/rhel-usr   5.0G  3.8G  1.3G  76% /usr
/dev/sdb               150G   92G   59G  62% /data
/dev/sda1              3.0G  288M  2.8G  10% /boot
/dev/mapper/rhel-var    15G  2.4G   13G  16% /var
tmpfs                  1.2G     0  1.2G   0% /run/user/0
tmpfs                  1.2G     0  1.2G   0% /run/user/990
tmpfs                  1.2G   12K  1.2G   1% /run/user/42
tmpfs                  1.2G     0  1.2G   0% /run/user/1000


Copyright 2021. All rights reserved.

Posted November 18, 2021 by Timothy Conrad in category "Linux

About the Author

If I were to describe myself with one word it would be, creative. I am interested in almost everything which keeps me rather busy. Here you will find some of my technical musings. PGP: 4CB8 91EB 0C0A A530 3BE9 6D76 B076 96F1 6135 0A1B