SWAT Blog

Logical Volume Management Linux (LVM)

February 11th, 2013 by Bhagwan Dass

To View All Existing Disk Partitions:-

[root@localhost ~]#fdisk -l

Disk /dev/sda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006e148

Device Boot Start End Blocks Id System
/dev/sda1 * 1 77 614400 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 77 6451 51200000 83 Linux
/dev/sda3 6451 6834 3072000 82 Linux swap / Solaris

Note:- In this disk I have 20 GB disk space left as unallocated
Now Create a New Disk Partition with Specific Size:-

[root@localhost ~]#fdisk /dev/sda

Command (m for help): n
First cylinder (6834-8139, default 6834):
Using default value 6834
Last cylinder, +cylinders or +size{K,M,G} (6834-8139, default 8139): +10G

Note:-If you want to use up all available space after the initial sector, just press Enter.

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.

Repeate above Steps for second partition.
Two partition of 10GB, 10GB is created, format it using the mkfs command

[root@localhost ~]#partprobe /dev/sda (Run Partprobe or Reboot the system)

Warning: WARNING: the kernel failed to re-read the partition table on /dev/sda (Device or resource busy). As a result, it may not reflect all of your changes until after reboot.

Formate the partitions /dev/sda5 and /dev/sda6 one by one:-

[root@localhost ~]#mkfs.ext4 /dev/sda5

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
305824 inodes, 1222602 blocks
61130 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1254096896
38 block groups
32768 blocks per group, 32768 fragments per group
8048 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 32 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Create Physical Volume by pvcreate command:-

[root@localhost ~]#pvcreate /dev/sda5 /dev/sda6

Writing physical volume data to disk “/dev/sda5″
Physical volume “/dev/sda5″ successfully created
Writing physical volume data to disk “/dev/sda6″
Physical volume “/dev/sda6″ successfully created

Create Volume Group by vgcreate command:-


[root@localhost ~]#vgcreate vg0 /dev/sda5 /dev/sda6

Volume group “vg0″ successfully created

[root@localhost ~]#vgdisplay

(Display Volume Group)
— Volume group —
VG Name vg0
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 1
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 0
Open LV 0
Max PV 0
Cur PV 2
Act PV 2
VG Size 18.64 GiB
PE Size 4.00 MiB
Total PE 4772
Alloc PE / Size 0 / 0
Free PE / Size 4772 / 18.64 GiB
VG UUID uKm3bZ-2uHb-0DJe-hur5-vbm3-pI8O-L2kL10

Create Logical Volume by lvcreate command:-

[root@localhost ~]#lvcreate -L 1024MB -n /dev/vg0/lv0

Logical volume “lv0″ created

[root@localhost ~]#lvdisplay    (Display Logical Volume)

— Logical volume —
LV Path /dev/vg0/lv0
LV Name lv0
VG Name vg0
LV UUID 5oGJ4c-In6O-gJsl-2bT1-QLNV-f5sw-wHwswe
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2013-02-11 14:14:00 +0530
LV Status available
# open 0
LV Size 1.00 GiB
Current LE 256
Segments 1
Allocation inherit
Read ahead sectors auto
– currently set to 256
Block device 253:0

Formate the Logical Volume by mkfs command:-

[root@localhost ~]#mkfs.ext4 /dev/vg0/lv0

mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
65536 inodes, 262144 blocks
13107 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=268435456
8 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 29 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.

Create a Directory and mount the LVM Partiotion:-

[root@localhost ~]#mkdir /lvm-disk
[root@localhost ~]#mount /dev/vg0/lv0 /lvm-disk

Enter fstab entry for permanent mount:-

[root@localhost ~]#vi /etc/fstab

/dev/vg0/lv0 /lvm-disk ext4 defaults 0 0

[root@localhost ~]#df -h

Filesystem Size Used Avail Use% Mounted on
/dev/sda2 49G 2.7G 45G 6% /
tmpfs 939M 88K 939M 1% /dev/shm
/dev/sda1 591M 90M 472M 16% /boot
/dev/mapper/vg0-lv0 1008M 34M 924M 4% /lvm-disk

Leave a Reply

  • © 2004-2015 Special Work & Technology Limited