By admin on

Server Storage Upgrade Using LVM

Recently I was faced with the task of coming up with and testing out the storage upgrade steps of a bare metal Centos7 virtual machine managed with vSphear.

The virtual machine was used to run a Django application.

Since 90% of the storage usage at runtime comes from application logs, the upgrade process will involve creating a new mount point /data and updating the django application to use is as the new logs destination

the OS installation used LVM for partitioning and sizing of the volumes so upgrade process is also done using LVM

Terms and Abbreviations

  • Physical Volume (PV) - Consists of Raw disks attached to VM
  • Volume Group (VG) - Combines the physical volumes into storage groups
  • Logical Volume (LV) - VGs are divided into LV's which are then mounted as partitions
  • The vm will maintain one VG (that is created at OS installation, probably named centos) more PVs will be added to the above VG

    all the commands are run as root

    Storage upgrade steps

    1. Creating a new disk from VSphear and attaching it to the VM

    this procedure was tested using a vm with a 10GiB disk and 5GiB disk is to be added

    once the disk has been attached, you can verify it's existence using fdisk -l

    Disk /dev/vdb: 5368 MB, 5368709120 bytes, 10485760 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
    

    2. Create a single primary partition on the disk

    use the command fdisk /dev/vdbuse n to create the partitions and save changes with w

    [root@localhost ~]# fdisk /dev/vdb
    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.
    
    Device does not contain a recognized partition table
    Building a new DOS disklabel with disk identifier 0x6716328c.
    
    Command (m for help): n
    Partition type:
       p   primary (0 primary, 0 extended, 4 free)
       e   extended
    Select (default p): p
    Partition number (1-4, default 1): 1
    First sector (2048-10485759, default 2048): 
    Using default value 2048
    Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759): 
    Using default value 10485759
    Partition 1 of type Linux and of size 5 GiB is set
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    [root@localhost ~]#
    

    Screenshot from 2020-02-18 10-44-01.png


    After Creating the partitions, use fdisk -l to verify

    [root@localhost ~]# fdisk -l
    
    Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000f1aa5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     2099199     1048576   83  Linux
    /dev/vda2         2099200    20971519     9436160   8e  Linux LVM
    
    Disk /dev/vdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x6716328c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048    10485759     5241856   83  Linux
    

    2020-02-18_10-46.png

    3. Set the partition type to Linux LVM 0x8e

    use fdisk and the t command

    [root@localhost ~]# fdisk /dev/vdb
    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): t
    Selected partition 1
    Hex code (type L to list all codes): 8e
    Changed type of partition 'Linux' to 'Linux LVM'
    
    Command (m for help): w
    The partition table has been altered!
    
    Calling ioctl() to re-read partition table.
    Syncing disks.
    

    2020-02-18_10-56.png

    You can verify by using fdisk -l

    [root@localhost ~]# fdisk -l
    
    Disk /dev/vda: 10.7 GB, 10737418240 bytes, 20971520 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: 0x000f1aa5
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048     2099199     1048576   83  Linux
    /dev/vda2         2099200    20971519     9436160   8e  Linux LVM
    
    Disk /dev/vdb: 5368 MB, 5368709120 bytes, 10485760 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: 0x6716328c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vdb1            2048    10485759     5241856   8e  Linux LVM
    
    Disk /dev/mapper/centos-root: 8585 MB, 8585740288 bytes, 16769024 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/centos-swap: 1073 MB, 1073741824 bytes, 2097152 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
    
    [root@localhost ~]#
    

    2020-02-18_10-57.png

    make sure to reload the partition table after the change using partprobe

    [root@localhost ~]# partprobe 
    [root@localhost ~]#
    

    2020-02-18_11-00.png

    4. Create Physical Volume (PV)

    using the pvcreate command

    [root@localhost ~]# pvcreate /dev/vdb1 
      Physical volume "/dev/vdb1" successfully created.
    [root@localhost ~]#
    

    2020-02-18_10-49.png

    5. Extende the current volume group with the new physical volume

    Add the new Physical Volume to the centos volume group using vgextend

    use vgdisplay to view the VG name
    [root@localhost ~]# vgextend centos /dev/vdb1
      Volume group "centos" successfully extended
    [root@localhost ~]#
    

    2020-02-18_11-04.png

    6. Create Logical Volumes

    lvcreate -n data --size 4.99G centos

    creating for 5GB failed because of lack of enough space, so i had to create 4.99GB
    [root@localhost ~]# lvcreate -n data --size 4.99G centos
      Rounding up size to full physical extent 4.99 GiB
      Logical volume "data" created.
    [root@localhost ~]#
    

    2020-02-18_11-12.png


    Use  lvdisplay to verify this creation

    7.Format the logical volume to ext4

    mkfs.ext4 /dev/centos/data

    [root@localhost ~]# mkfs.ext4 /dev/centos/data
    mke2fs 1.42.9 (28-Dec-2013)
    Filesystem label=
    OS type: Linux
    Block size=4096 (log=2)
    Fragment size=4096 (log=2)
    Stride=0 blocks, Stripe width=0 blocks
    327680 inodes, 1308672 blocks
    65433 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=1340080128
    40 block groups
    32768 blocks per group, 32768 fragments per group
    8192 inodes per group
    Superblock backups stored on blocks: 
    	32768, 98304, 163840, 229376, 294912, 819200, 884736
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done 
    
    [root@localhost ~]#
    

    2020-02-18_11-14.png

    8. Finally Mount the file system for use

    the mount point have to exist before mounting. you can create it using mkdir /data

    mount /dev/centos/data /data

    [root@localhost ~]# mount /dev/centos/data /data
    [root@localhost ~]#
    

    2020-02-18_11-16.png


    0 comments

    Write a response
    Publish