rhel volume groups

RHEL Volume Groups

I have a new all Installed

I then created 3 Hard Drives on it.

Show Devices

I use the lvmdiskscan command

 lvmdiskscan


  /dev/rhel/swap [       2.80 GiB] 
  /dev/sda1      [     500.00 MiB] 
  /dev/rhel/root [      24.67 GiB] 
  /dev/sda2      [      27.51 GiB] LVM physical volume
  /dev/sdb       [       1.00 GiB] 
  /dev/sdc       [       1.00 GiB] 
  /dev/sdd       [       1.00 GiB] 
  5 disks
  1 partition
  0 LVM physical volume whole disks
  1 LVM physical volume

I can see that I have disks

  • /dev/sdb
  • /dev/sdc
  • /dev/sdd

Available an unallocated.

Current Physical Volume Group

Use the pvscan command.

    pvscan
  PV /dev/sda2   VG rhel   lvm2 [27.51 GiB / 40.00 MiB free]
  Total: 1 [27.51 GiB] / in use: 1 [27.51 GiB] / in no VG: 0 [0   ]

You can also use the vgdisplay command

 vgdisplay
  --- Volume group ---
  VG Name               rhel
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               27.51 GiB
  PE Size               4.00 MiB
  Total PE              7042
  Alloc PE / Size       7032 / 27.47 GiB
  Free  PE / Size       10 / 40.00 MiB
  VG UUID               S0b2JQ-flWz-2tiX-pRrL-oHCo-doH7-YxQn4y

Create a Volume Group using 3 Physical Devices

We will call this volume Group vgDev

vgcreate vgDev /dev/sdb /dev/sdc /dev/sdd

This returns

vgcreate vgDev /dev/sdb /dev/sdc /dev/sdd

  Physical volume "/dev/sdb" successfully created
  Physical volume "/dev/sdc" successfully created
  Physical volume "/dev/sdd" successfully created
  Volume group "vgDev" successfully created

Volume Group to Logical Group

We have a Volume Group of 3 Gb (as we have 3 1Gb drives).

We now want to make a logical group called lvData1 - of say 800 Mb.

lvcreate -L 800M -n lvData1 vgDev

we get back

lvcreate -L 800M -n lvData1 vgDev
  Logical volume "lvData1" created.

Displaying Logical Volumes

lvscan is the command. I can see my new LogicalVolume.

  lvscan
  ACTIVE            '/dev/vgDev/lvData1' [800.00 MiB] inherit
  ACTIVE            '/dev/rhel/swap' [2.80 GiB] inherit
  ACTIVE            '/dev/rhel/root' [24.67 GiB] inherit

I can also see this using the lvs command.

 lvs
  LV      VG    Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root    rhel  -wi-ao----  24.67g                                                    
  swap    rhel  -wi-ao----   2.80g                                                    
  lvData1 vgDev -wi-a----- 800.00m  

Create a File System

We now need to place a File System on the Logical Volume called LvData1. We will create an ext3 file system on the LogicalVolume.

mkfs.ext3 /dev/vgDev/lvData1

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
51296 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=209715200
7 block groups
32768 blocks per group, 32768 fragments per group
7328 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done

Update the /etc/fstab

We now have created the Drive, so we need to mount it.

But I like using the blockId mechanism. So we get the blockIds - and add that to the /etc/fstab

blkid | grep lvData1

/dev/mapper/vgDev-lvData1: UUID="2bae5b62-f3bd-4c35-b1da-33f7c163b057" SEC_TYPE="ext2" TYPE="ext3" 

Create the Mount Point

 mkdir -p /mnt/Data1

Plase line in Fstab

The blockid output needs a little editing.

    UUID="2bae5b62-f3bd-4c35-b1da-33f7c163b057"  /mnt/Data1 ext3 defaults 0 0

Test It mounts

     mount -a
     df

And we see

     /dev/mapper/vgDev-lvData1    789904       828    748116   1% /mnt/Data1

1 More LogicalVolume

    lvcreate -L 500M -n lvData2 vgDev
    mkfs.ext3 /dev/vgDev/lvData2
    mkdir -p /mnt/Data2

    blkid | grep Data2 >> /etc/fstab
    Edit this line to  UUID="c46221cf-450d-4530-a541-b2b13c0a8313"  /mnt/Data2 ext3 defaults 0 0

Fill Up a Disk

We now want to fill up Disk1 - Why ? Becuase I want to resize the LogicalVolume to add some of the spare space.

Just to recap we have

- 3 Physical Drives
- Each with 1Gb of Space

We created a

  • 3 Gb Phyical Volume

We then Created 2 Logical Volumes

  • 800M Data1
  • 500M Data2

So we should have a spare capacity of 1700 Mb.

Fill up a Disk Quickly.

This is VERY dangerous YOU have been warned.

Lets see how much space on Data1 there is

df | grep Data1
/dev/mapper/vgDev-lvData1    789904       828    748116   1% /mnt/Data1

Only 1% ...

So lets use 700Mb of this drive ....

dd if=/dev/zero of=/mnt/Data1/file.txt count=700 bs=1048576

Now the Df yields.

/dev/mapper/vgDev-lvData1  772M  702M   30M  96% /mnt/Data1

Resize in 1 Go !!

    lvresize --resizefs --size 1200M /dev/vgDev/lvData1

Or Manually

lvextend -L+400M /dev/vgDev/lvData1
resize2fs /dev/vgDev/lvData1