If you just added a new Disk to a Linux Box (for example under VMware) you may want to add that one to a LVM to a new Volume Group. Here are the steps quick and easy with a bit of commenting.

You have not yet added the new disk and want to do this hot. Then I refer to this here. How to add a new disk without reboot

fdisk -l       #to show us the available disks

We assume our new disk is /dev/sdb and we will not create a partition on it but use /dev/sdb as it is. This gives us the advantage that if we increase the disksize outside of the OS (for example a vmdk which we just increase or a SAN lun which we just increase in size) we can easily increase the volume under lvm.

pvcreate /dev/sdb
 Writing physical volume data to disk "/dev/sdb"
 Physical volume "/dev/sdb" successfully created

You can check what you have created by using

pvs -v
pvdisplay -v

Now we create a volume group called vg_data

vgcreate vg_data /dev/sdb
 Volume group "vg_data" successfully created

Now we create a volume called lv_data and give it all available free space on the vg_data

You can check what you have created by using

vgs -v
vgdisplay -v
lvcreate -l+100%FREE -n lv_data vg_data
 Logical volume "lv_data" created

Alternative to create only 20GB use:

lvcreate --size 20G -n lv_data vg_data
 Logical volume "lv_data" created

You can check what you have created by using

lvs -v
lvdisplay -v

Create a filesystem on top of the lv_data

mkfs -t ext4 /dev/vg_data/lv_data
 mke2fs 1.42.5 (29-Jul-2012)
 Filesystem label=
 OS type: Linux
 Block size=4096 (log=2)
 Fragment size=4096 (log=2)
 Stride=0 blocks, Stripe width=0 blocks
 52428800 inodes, 209714176 blocks
 10485708 blocks (5.00%) reserved for the super user
 First data block=0
 Maximum filesystem blocks=4294967296
 6400 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, 1605632, 2654208,
 4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,

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

you can now test mount it anywhere to see it working

mount /dev/vg_data/lv_data /mnt
df -h /mnt
 Filesystem Size Used Avail Use% Mounted on
 /dev/mapper/vg_data-lv_data 788G 197M 748G 1% /mnt

or maybe better add it with its final location into the fstab

vi /etc/fstab


/dev/mapper/vg_data-lv_data /whatever ext4 defaults 0 2

Done, you can now mount it by using

mount /whatever
%d bloggers like this: