Extend existing logical volumes

Exercise I

For this exercise, we will work with a new blank disk (vdb) and extend the LV root from 5.29 GB to 6.29 GB.

First check the free space on the new disk with parted command:

[root@cliente1 ~]# parted /dev/vdb unit GB print free
 Error: /dev/vdb: unrecognised disk label
 Model: Virtio Block Device (virtblk)                                      
 Disk /dev/vdb: 2.25GB
 Sector size (logical/physical): 512B/512B
 Partition Table: unknown
 Disk Flags: 

1. Create a new partition of 1 GB:

[root@cliente1 ~]# 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 0x324be3c5.

 Command (m for help): n
 Partition type:
    p   primary (0 primary, 0 extended, 4 free)
    e   extended
 Select (default p): 
 Using default response p
 Partition number (1-4, default 1): 
 First sector (2048-4404019, default 2048): 
 Using default value 2048
 Last sector, +sectors or +size{K,M,G} (2048-4404019, default 4404019): +1G
 Partition 1 of type Linux and of size 1 GiB is set
 Command (m for help): p
 Disk /dev/vdb: 2254 MB, 2254858240 bytes, 4404020 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: 0x324be3c5
 Device Boot      Start         End      Blocks   Id  System
 /dev/vdb1            2048     2099199     1048576   83  Linux

 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): p
 Disk /dev/vdb: 2254 MB, 2254858240 bytes, 4404020 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: 0x324be3c5
 Device Boot      Start         End      Blocks   Id  System
 /dev/vdb1            2048     2099199     1048576   8e  Linux LVM

 Command (m for help): w
 The partition table has been altered!
 Calling ioctl() to re-read partition table.
 Syncing disks.

 [root@cliente1 ~]# partprobe -s
 /dev/vda: msdos partitions 1 2
 /dev/vdb: msdos partitions 1

2. Create a physical volume /dev/vdb1

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

3. Extend the vg myvg1 with the pv created

[root@cliente1 ~]# vgs
   VG    #PV #LV #SN Attr   VSize VFree
   myvg1   1   2   0 wz--n- 6.00g 4.00m

 [root@cliente1 ~]# vgextend myvg1 /dev/vdb1
   Volume group "myvg1" successfully extended

[root@cliente1 ~]# vgs
   VG    #PV #LV #SN Attr   VSize VFree
   myvg1   2   2   0 wz--n- 6.99g 1.00g  <-- new size and free space

4. Extend the logical volume root

[root@cliente1 ~]# lvextend /dev/myvg1/root -L +1G -r -t  <--test mode
   TEST MODE: Metadata will NOT be updated and volumes will not be (de)activated.
   Size of logical volume myvg1/root changed from 5.29 GiB (1355 extents) to 6.29 GiB (1611 extents).
   Logical volume myvg1/root successfully resized.

 [root@cliente1 ~]# lvextend /dev/myvg1/root -L +1G -r
   Size of logical volume myvg1/root changed from 5.29 GiB (1355 extents) to 6.29 GiB (1611 extents).
   Logical volume myvg1/root successfully resized.
 meta-data=/dev/mapper/myvg1-root isize=512    agcount=4, agsize=346880 blks
          =                       sectsz=512   attr=2, projid32bit=1
          =                       crc=1        finobt=0 spinodes=0
 data     =                       bsize=4096   blocks=1387520, imaxpct=25
          =                       sunit=0      swidth=0 blks
 naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
 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 1387520 to 1649664 

Check the new size with lvs command:

[root@cliente1 ~]# lvs
   LV   VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
   root myvg1 -wi-ao----   6.29g         <-- new size                                           
   swap myvg1 -wi-ao---- 716.00m                                                    

Exercise II

For this exercise, is required to create a new partition to work with:

  • VG name –> myvg2
  • 15 LE name –> lv_01,
  • PE size –> 8MB

As we don’t know the size of the partition, must calculate it:

LE x PE = X + 1PE = SIZE PARTITION
15 x 8  = 120 +8  = 128 MB

Check the available space:

[root@cliente1 ~]# parted /dev/vdb unit GB print free
 Model: Virtio Block Device (virtblk)
 Disk /dev/vdb: 2.25GB
 Sector size (logical/physical): 512B/512B
 Partition Table: msdos
 Disk Flags: 
 Number  Start   End     Size    Type     File system  Flags
         0.00GB  0.00GB  0.00GB           Free Space
  1      0.00GB  1.07GB  1.07GB  primary               lvm
         1.07GB  2.25GB  1.18GB           Free Space

1. Create the partition of 128MB so finally the size will be of 120MB:

[root@cliente1 ~]# 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): n
 Partition type:
    p   primary (1 primary, 0 extended, 3 free)
    e   extended
 Select (default p): 
 Using default response p
 Partition number (2-4, default 2): 
 First sector (2099200-4404019, default 2099200): 
 Using default value 2099200
 Last sector, +sectors or +size{K,M,G} (2099200-4404019, default 4404019): +128M
 Partition 2 of type Linux and of size 128 MiB is set
 Command (m for help): p
 Disk /dev/vdb: 2254 MB, 2254858240 bytes, 4404020 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: 0x324be3c5
 Device Boot      Start         End      Blocks   Id  System
 /dev/vdb1            2048     2099199     1048576   8e  Linux LVM
 /dev/vdb2         2099200     2361343      131072   83  Linux
 Command (m for help): t
 Partition number (1,2, default 2): 
 Hex code (type L to list all codes): 8e
 Changed type of partition 'Linux' to 'Linux LVM'
 Command (m for help): p
 Disk /dev/vdb: 2254 MB, 2254858240 bytes, 4404020 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: 0x324be3c5
 Device Boot      Start         End      Blocks   Id  System
 /dev/vdb1            2048     2099199     1048576   8e  Linux LVM
 /dev/vdb2         2099200     2361343      131072   8e  Linux LVM
 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.

 [root@cliente1 ~]# partprobe -s
 /dev/vda: msdos partitions 1 2
 /dev/vdb: msdos partitions 1 2

2. Create the VG

note: when you create a VG, the system create a PV automatically.

[root@cliente1 ~]# vgcreate myvg2 -s 8M /dev/vdb2
   Physical volume "/dev/vdb2" successfully created.
   Volume group "myvg2" successfully created
The new VG with a size of 120MB

3. Create the LV

[root@cliente1 ~]# lvcreate -n lv_01 myvg2 -l 15
Logical volume "lv_01" created.
#lvs
LV    VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
   root  myvg1 -wi-ao----   6.29g                                                    
   swap  myvg1 -wi-ao---- 716.00m                                                    
   lv_01 myvg2 -wi-a----- 120.00m 

[root@cliente1 ~]# lvdisplay myvg2
   --- Logical volume ---
   LV Path                /dev/myvg2/lv_01
   LV Name                lv_01
   VG Name                myvg2
   LV UUID                OGTfht-8Vww-DP1s-z53t-1kY7-M9TR-l3fFdH
   LV Write Access        read/write
   LV Creation host, time cliente1.example.com, 2019-05-14 21:24:21 -0400
   LV Status              available
   # open                 0
   LV Size                120.00 MiB
   Current LE             15
   Segments               1
   Allocation             inherit
   Read ahead sectors     auto
 currently set to     8192
 Block device           253:2 

4. Create and assign a file system

[root@cliente1 ~]# mkfs.    
 mkfs.btrfs   mkfs.ext2    mkfs.ext4    mkfs.minix   mkfs.vfat    
 mkfs.cramfs  mkfs.ext3    mkfs.fat     mkfs.msdos   mkfs.xfs 
    
 [root@cliente1 ~]# mkfs.xfs /dev/myvg2/lv_01 
 meta-data=/dev/myvg2/lv_01       isize=512    agcount=4, agsize=7680 blks
          =                       sectsz=512   attr=2, projid32bit=1
          =                       crc=1        finobt=0, sparse=0
 data     =                       bsize=4096   blocks=30720, imaxpct=25
          =                       sunit=0      swidth=0 blks
 naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
 log      =internal log           bsize=4096   blocks=855, version=2
          =                       sectsz=512   sunit=0 blks, lazy-count=1
 realtime =none                   extsz=4096   blocks=0, rtextents=0

 [root@cliente1 ~]# blkid | grep myvg2
 /dev/mapper/myvg2-lv_01: UUID="acf5a0fd-bb95-4eda-88d2-98b019b1d5d2" TYPE="xfs" 

[root@cliente1 ~]# echo "UUID="acf5a0fd-bb95-4eda-88d2-98b019b1d5d2" /mnt/data xfs defaults 0 0" >> /etc/fstab 

5. Create the mount point, check and mount all:

[root@cliente1 mnt]# mkdir /mnt/data

[root@cliente1 mnt]# df -h
 Filesystem              Size  Used Avail Use% Mounted on
 /dev/mapper/myvg1-root  6.3G  3.0G  3.4G  48% /
 devtmpfs                905M     0  905M   0% /dev
 tmpfs                   920M  152K  920M   1% /dev/shm
 tmpfs                   920M  8.9M  911M   1% /run
 tmpfs                   920M     0  920M   0% /sys/fs/cgroup
 /dev/vda1              1014M  173M  842M  17% /boot
 tmpfs                   184M  4.0K  184M   1% /run/user/42
 tmpfs                   184M   12K  184M   1% /run/user/1000

 [root@cliente1 mnt]# mount -a

 [root@cliente1 mnt]# df -h
 Filesystem               Size  Used Avail Use% Mounted on
 /dev/mapper/myvg1-root   6.3G  3.0G  3.4G  48% /
 devtmpfs                 905M     0  905M   0% /dev
 tmpfs                    920M  152K  920M   1% /dev/shm
 tmpfs                    920M  8.9M  911M   1% /run
 tmpfs                    920M     0  920M   0% /sys/fs/cgroup
 /dev/vda1               1014M  173M  842M  17% /boot
 tmpfs                    184M  4.0K  184M   1% /run/user/42
 tmpfs                    184M   12K  184M   1% /run/user/1000
 /dev/mapper/myvg2-lv_01  117M  6.2M  111M   6% /mnt/data

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *