HowTo Resize The "root" File System Using LVM

From NST Wiki
Jump to navigationJump to search

Overview

This page demonstrates how to resize the root file system by increasing it's size by 2GB using the Logical Volume Manager (LVM). This will be done without rebooting the NST system. The follow environment exists:

[root@nst22 ~]# ssm list;
-----------------------------------------------------------
Device        Free      Used      Total  Pool   Mount point
-----------------------------------------------------------
/dev/sda                       20.00 GB         PARTITIONED
/dev/sda1                     500.00 MB         /boot
/dev/sda2  0.00 KB  19.51 GB   19.51 GB  nst22
-----------------------------------------------------------
-------------------------------------------------
Pool   Type  Devices     Free      Used     Total
-------------------------------------------------
nst22  lvm   1        0.00 GB  19.51 GB  19.51 GB
-------------------------------------------------
------------------------------------------------------------------------------------
Volume           Pool   Volume size  FS      FS size       Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/nst22/root  nst22     17.51 GB  xfs    17.50 GB    5.88 GB  linear  /
/dev/nst22/swap  nst22      2.00 GB                              linear
/dev/sda1                 500.00 MB  ext4  500.00 MB  288.89 MB  part    /boot
------------------------------------------------------------------------------------
  • The root file sytem is of type xfs
[root@nst22 ~]# mount | grep root;
/dev/mapper/nst22-root on / type xfs (rw,relatime,attr2,inode64,noquota)

Demonstration

We will now show a sequence of commands to accomplish resizing the root file system by 2GB. Our NST system is a Virtual Machine (VM) running under the VMware Fusion Hypervisor. Behind the scenes we created a new virtual disk of size 2GB (/dev/sdb). On a physical system we could of used a whole disk or a disk partition for this demonstration.

The root file system size is currently 17.50GB in the Volume Group pool: "nst22". Our goal is to increase the root file system to a total of 19.50GB.

Initialize Disk or Disk Partition for LVM Usage

One can either us a whole disk or a disk partion for LVM:

  • To use a disk partition: Use a partition tool (fdisk, cfdisk, gparted, etc...) to create the disk partition for LVM.
  • To use the whole disk: Make sure the partition table is cleared out:
dd if=/dev/zero of=/dev/sdb bs=512 count=1

We will use the entire disk (/dev/sdb) for LVM using the following pvcreate command to initialize a Physical Volume:

pvcreate /dev/sdb;

Add the Physical Volume To An Existing Volume Group

We will now add (extend) the newly created Physical Volume: /dev/sdb to the nst22 Volume Group.

vgextend 'nst22' /dev/sdb;

We can validate the results of using the vgextend command above using pvscan and ssm list:

[root@nst22 tmp]# pvscan;
  PV /dev/sda2   VG nst22   lvm2 [19.51 GiB / 0    free]
  PV /dev/sdb    VG nst22   lvm2 [2.00 GiB / 2.00 GiB free]
  Total: 2 [21.50 GiB] / in use: 2 [21.50 GiB] / in no VG: 0 [0   ]
[root@nst22 tmp]# ssm list;
-----------------------------------------------------------
Device        Free      Used      Total  Pool   Mount point
-----------------------------------------------------------
/dev/sda                       20.00 GB         PARTITIONED
/dev/sda1                     500.00 MB         /boot
/dev/sda2  0.00 KB  19.51 GB   19.51 GB  nst22
/dev/sdb   2.00 GB   0.00 KB    2.00 GB  nst22
-----------------------------------------------------------
-------------------------------------------------
Pool   Type  Devices     Free      Used     Total
-------------------------------------------------
nst22  lvm   2        2.00 GB  19.51 GB  21.50 GB
-------------------------------------------------
------------------------------------------------------------------------------------
Volume           Pool   Volume size  FS      FS size       Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/nst22/root  nst22     17.51 GB  xfs    17.50 GB    5.88 GB  linear  /
/dev/nst22/swap  nst22      2.00 GB                              linear
/dev/sda1                 500.00 MB  ext4  500.00 MB  288.89 MB  part    /boot

Resize The root File System

We now have unused disk under LVM control in the nst22 Volume Group pool to add to the root file system. We will accomplish the resizing of root without unmounting or rebooting using the following lvextend command (-r option):

[root@nst22 tmp]# lvextend -l "+100%PVS" -r /dev/nst22/root /dev/sdb;
  Size of logical volume nst22/root changed from 17.51 GiB (4482 extents) to 19.50 GiB (4993 extents).
  Logical volume root successfully resized
meta-data=/dev/mapper/nst22-root isize=256    agcount=4, agsize=1147392 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4589568, 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 4589568 to 5112832

The validation of this demonstration for resizing of the root file system by 2GB is now shown:

[root@nst22 tmp]# df -h;
Filesystem              Size  Used Avail Use% Mounted on
devtmpfs                477M     0  477M   0% /dev
tmpfs                   488M  4.0K  488M   1% /dev/shm
tmpfs                   488M  1.1M  487M   1% /run
tmpfs                   488M     0  488M   0% /sys/fs/cgroup
/dev/mapper/nst22-root   20G   12G  7.9G  60% /
tmpfs                   488M  8.0K  488M   1% /tmp
/dev/sda1               477M  163M  285M  37% /boot
tmpfs                    98M     0   98M   0% /run/user/0

[root@nst22 tmp]# ssm list;
-----------------------------------------------------------
Device        Free      Used      Total  Pool   Mount point
-----------------------------------------------------------
/dev/sda                       20.00 GB         PARTITIONED
/dev/sda1                     500.00 MB         /boot
/dev/sda2  0.00 KB  19.51 GB   19.51 GB  nst22
/dev/sdb   0.00 KB   2.00 GB    2.00 GB  nst22
-----------------------------------------------------------
-------------------------------------------------
Pool   Type  Devices     Free      Used     Total
-------------------------------------------------
nst22  lvm   2        0.00 KB  21.50 GB  21.50 GB
-------------------------------------------------
------------------------------------------------------------------------------------
Volume           Pool   Volume size  FS      FS size       Free  Type    Mount point
------------------------------------------------------------------------------------
/dev/nst22/root  nst22     19.50 GB  xfs    19.49 GB    7.88 GB  linear  /
/dev/nst22/swap  nst22      2.00 GB                              linear
/dev/sda1                 500.00 MB  ext4  500.00 MB  288.89 MB  part    /boot
------------------------------------------------------------------------------------
[root@nst22 tmp]# pvscan;
  PV /dev/sda2   VG nst22   lvm2 [19.51 GiB / 0    free]
  PV /dev/sdb    VG nst22   lvm2 [2.00 GiB / 0    free]
  Total: 2 [21.50 GiB] / in use: 2 [21.50 GiB] / in no VG: 0 [0   ]

RPi Resize Flash Partitions

Here is a guide on how to modify partitions on the Raspberry Pi (and Pi clones, such as the Banana Pi) for Linux-based operating systems, such as Raspian Linux, CentOS, Arch, and Linux distributions: RPi Resize Flash Partitions