Baby steps to extend disk size in Linux

There are several steps involved in extending the hard drive.

  • Check the current disk usage
# df -h

Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   46G  6.3G   39G  14% /
devtmpfs                12G     0   12G   0% /dev
tmpfs                   12G     0   12G   0% /dev/shm
tmpfs                   12G   13M   12G   1% /run
tmpfs                   12G     0   12G   0% /sys/fs/cgroup
/dev/sda1             1014M  200M  815M  20% /boot
tmpfs                  2.4G   12K  2.4G   1% /run/user/988
tmpfs                  2.4G     0  2.4G   0% /run/user/0
  • Use fdisk command  for creating and manipulating disk partition table
# fdisk -l

Disk /dev/sda: 96.6 GB, 96636764160 bytes, 188743680 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
Disk label type: dos
Disk identifier: 0x000bf21d

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/mapper/rhel-root: 48.4 GB, 48444211200 bytes, 94617600 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

Disk /dev/mapper/rhel-swap: 4160 MB, 4160749568 bytes, 8126464 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
  • # fdisk /dev/sda
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3):
First sector (104857600-188743679, default 104857600):
Using default value 104857600
Last sector, +sectors or +size{K,M,G} (104857600-188743679, default 188743679):
Using default value 188743679
Partition 3 of type Linux and of size 40 GiB is set

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.


  • # partprobe
  • # pvscan
PV /dev/sda2   VG rhel            lvm2 [<49.00 GiB / 4.00 MiB free]
  Total: 1 [<49.00 GiB] / in use: 1 [<49.00 GiB] / in no VG: 0 [0   ]
  • vgextend rhel /dev/sda3
 Physical volume "/dev/sda3" successfully created.
  Volume group "rhel" successfully extended
  • pvscan
PV /dev/sda2   VG rhel            lvm2 [<49.00 GiB / 4.00 MiB free]
  PV /dev/sda3   VG rhel            lvm2 [<40.00 GiB / <40.00 GiB free]
  Total: 2 [88.99 GiB] / in use: 2 [88.99 GiB] / in no VG: 0 [0   ]
  • # lvdisplay
 --- Logical volume ---
  LV Path                /dev/rhel/swap
  LV Name                swap
  VG Name                rhel
  LV UUID                hGgz4r-7jFf-oHZz-eJWs-RBtb-3RqQ-DS0wYA
  LV Write Access        read/write
  LV Creation host, time rhel76.lab.opentext.com, 2019-01-22 15:23:44 +0530
  LV Status              available
  # open                 2
  LV Size                <3.88 GiB
  Current LE             992
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

  --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                beJf86-1F0L-eu8J-suwq-ItZg-Z4qv-spCLf9
  LV Write Access        read/write
  LV Creation host, time rhel76.lab.opentext.com, 2019-01-22 15:23:44 +0530
  LV Status              available
  # open                 1
  LV Size                <45.12 GiB
  Current LE             11550
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
  • # xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=2956800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11827200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5775, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
  • # pvscan
PV /dev/sda2 VG rhel lvm2 [<49.00 GiB / 4.00 MiB free]
PV /dev/sda3 VG rhel lvm2 [<40.00 GiB / <40.00 GiB free]
Total: 2 [88.99 GiB] / in use: 2 [88.99 GiB] / in no VG: 0 [0 ]
  • # lvextend /dev/rhel/root /dev/sda3
 Size of logical volume rhel/root changed from <45.12 GiB (11550 extents) to 85.11 GiB (21789 extents).
Logical volume rhel/root successfully resized.
  • # xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root isize=512 agcount=4, agsize=2956800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=11827200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=5775, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 11827200 to 22311936
  • # df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/rhel-root 86G 6.3G 79G 8% /
devtmpfs 12G 0 12G 0% /dev
tmpfs 12G 0 12G 0% /dev/shm
tmpfs 12G 13M 12G 1% /run
tmpfs 12G 0 12G 0% /sys/fs/cgroup
/dev/sda1 1014M 200M 815M 20% /boot
tmpfs 2.4G 12K 2.4G 1% /run/user/988
tmpfs 2.4G 0 2.4G 0% /run/user/0

Now observe that available hard disk is increased from 39 GB to 79 GB

 

 

 

 

 

 

 

Leave a comment