Tuesday, January 22, 2013

LVM - Create Physical/Logical volume group and adding new physical volumes to the volume group

Create three physical partitions:

/dev/sde
/dev/sdf
/dev/sdg

I have allocated all the space to the sde sdf sdg respectively.

Lets create physical volumes out of the partitions we created.

[root@rajcentos ~]# pvcreate /dev/sde1 /dev/sdf1 /dev/sdg1
  Physical volume "/dev/sde1" successfully created
  Physical volume "/dev/sdf1" successfully created
  Physical volume "/dev/sdg1" successfully created

I have named the volume group as raj_vg

[root@rajcentos ~]# vgcreate raj_vg /dev/sde1 /dev/sdf1 /dev/sdg1
  Volume group "raj_vg" successfully created

If you run pvscan:

[root@rajcentos ~]# pvscan
  PV /dev/sde1   VG raj_vg       lvm2 [48.00 MB / 48.00 MB free]
  PV /dev/sdf1   VG raj_vg       lvm2 [28.00 MB / 28.00 MB free]
  PV /dev/sdg1   VG raj_vg       lvm2 [16.00 MB / 16.00 MB free]
  PV /dev/sda2   VG VolGroup00   lvm2 [7.88 GB / 32.00 MB free]
  Total: 4 [7.96 GB] / in use: 4 [7.96 GB] / in no VG: 0 [0   ]

Here is the vgdisplay output:

[root@rajcentos ~]# vgdisplay
  --- Volume group ---
  VG Name               raj_vg
  System ID
  Format                lvm2
  Metadata Areas        3
  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                3
  Act PV                3
  VG Size               92.00 MB
  PE Size               4.00 MB
  Total PE              23
  Alloc PE / Size       0 / 0
  Free  PE / Size       23 / 92.00 MB
  VG UUID               hinsab-4Ube-dinI-HmsK-TQ19-UWu1-j9h0bF

[root@rajcentos ~]# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup00   1   2   0 wz--n-  7.88G 32.00M
  raj_vg       3   0   0 wz--n- 92.00M 92.00M

[root@rajcentos ~]# pvs
  PV         VG         Fmt  Attr PSize  PFree
  /dev/sda2  VolGroup00 lvm2 a-    7.88G 32.00M
  /dev/sde1  raj_vg     lvm2 a-   48.00M 48.00M
  /dev/sdf1  raj_vg     lvm2 a-   28.00M 28.00M
  /dev/sdg1  raj_vg     lvm2 a-   16.00M 16.00M

Now create logical volume groups from the "raj_vg"

[root@rajcentos ~]# lvcreate -n lv_one --size 20M raj_vg
  Logical volume "lv_one" created
[root@rajcentos ~]# lvcreate -n lv_two --size 20M raj_vg
  Logical volume "lv_two" created
[root@rajcentos ~]# lvcreate -n lv_three --size 20M raj_vg
  Logical volume "lv_three" created

[root@rajcentos ~]# lvs
  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy%
  LogVol00 VolGroup00 -wi-ao   7.34G
  LogVol01 VolGroup00 -wi-ao 512.00M
  lv_one   raj_vg     -wi-a-  20.00M
  lv_three raj_vg     -wi-a-  20.00M
  lv_two   raj_vg     -wi-a-  20.00M

[root@rajcentos ~]# vgs
  VG         #PV #LV #SN Attr   VSize  VFree
  VolGroup00   1   2   0 wz--n-  7.88G 32.00M
  raj_vg       3   3   0 wz--n- 92.00M 32.00M

Lets format the filesystem:

[root@rajcentos ~]# mkfs -t ext3 /dev/mapper/raj_vg-lv_one
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
5136 inodes, 20480 blocks
1024 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=20971520
3 block groups
8192 blocks per group, 8192 fragments per group
1712 inodes per group
Superblock backups stored on blocks:
        8193

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

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

[root@rajcentos ~]# mkfs -t ext3 /dev/mapper/raj_vg-lv_two
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
5136 inodes, 20480 blocks
1024 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=20971520
3 block groups
8192 blocks per group, 8192 fragments per group
1712 inodes per group
Superblock backups stored on blocks:
        8193

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

This filesystem will be automatically checked every 35 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@rajcentos ~]# mkfs -t ext3 /dev/mapper/raj_vg-lv_three
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
5136 inodes, 20480 blocks
1024 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=20971520
3 block groups
8192 blocks per group, 8192 fragments per group
1712 inodes per group
Superblock backups stored on blocks:
        8193

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

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

run lvs now:

[root@rajcentos ~]# lvs
  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy%
  LogVol00 VolGroup00 -wi-ao   7.34G
  LogVol01 VolGroup00 -wi-ao 512.00M
  lv_one   raj_vg     -wi-a-  20.00M
  lv_three raj_vg     -wi-a-  20.00M
  lv_two   raj_vg     -wi-a-  20.00M

Creating the directories so that the newly created volumes can be mounted:

[root@rajcentos ~]# mkdir /apps
[root@rajcentos ~]# mkdir /vontu
[root@rajcentos ~]# mkdir /ppm

To mount the volumes refer to the path:

[root@rajcentos ~]# mount /dev/mapper/raj_vg-lv_one /apps

[root@rajcentos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.3G  1.2G  5.7G  18% /
/dev/sda1              99M   13M   81M  14% /boot
none                  125M     0  125M   0% /dev/shm
/dev/mapper/raj_vg-lv_one
                       20M  1.2M   18M   7% /apps

[root@rajcentos ~]# mount /dev/mapper/raj_vg-lv_two /vontu

[root@rajcentos ~]# mount /dev/mapper/raj_vg-lv_three /ppm

[root@rajcentos ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.3G  1.2G  5.7G  18% /
/dev/sda1              99M   13M   81M  14% /boot
none                  125M     0  125M   0% /dev/shm
/dev/mapper/raj_vg-lv_one
                       20M  1.2M   18M   7% /apps
/dev/mapper/raj_vg-lv_two
                       20M  1.2M   18M   7% /vontu
/dev/mapper/raj_vg-lv_three
                       20M  1.2M   18M   7% /ppm


[root@rajcentos ~]# pvscan
  PV /dev/sde1   VG raj_vg       lvm2 [48.00 MB / 8.00 MB free]
  PV /dev/sdf1   VG raj_vg       lvm2 [28.00 MB / 8.00 MB free]
  PV /dev/sdg1   VG raj_vg       lvm2 [16.00 MB / 16.00 MB free]
  PV /dev/sda2   VG VolGroup00   lvm2 [7.88 GB / 32.00 MB free]
  Total: 4 [7.96 GB] / in use: 4 [7.96 GB] / in no VG: 0 [0   ]
[root@rajcentos ~]# df
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       7579576   1254184   5940368  18% /
/dev/sda1               101086     13240     82627  14% /boot
none                    127364         0    127364   0% /dev/shm
/dev/mapper/raj_vg-lv_one
                         19827      1202     17601   7% /apps
/dev/mapper/raj_vg-lv_two
                         19827      1202     17601   7% /vontu
/dev/mapper/raj_vg-lv_three
                         19827      1202     17601   7% /ppm


Adding a new physical volume to the volume group. You can use vgextend:
/dev/sdb1 and 2 I have created saperately so that those could be added to the
existing raj_vg.

[root@rajcentos ~]# lvs
  LV       VG         Attr   LSize   Origin Snap%  Move Log Copy%
  LogVol00 VolGroup00 -wi-ao   7.34G
  LogVol01 VolGroup00 -wi-ao 512.00M
  lv_one   raj_vg     -wi-a-  20.00M
  lv_three raj_vg     -wi-a-  20.00M
  lv_two   raj_vg     -wi-a-  20.00M

[root@rajcentos ~]# vgextend raj_vg /dev/sdb1

  Volume group "raj_vg" successfully extended
[root@rajcentos ~]# vgs
  VG         #PV #LV #SN Attr   VSize   VFree
  VolGroup00   1   2   0 wz--n-   7.88G  32.00M
  raj_vg       4   3   0 wz--n- 404.00M 344.00M
[root@rajcentos ~]# vgextend raj_vg /dev/sdb2
  Volume group "raj_vg" successfully extended

Now see the change in the size of raj_vg

[root@rajcentos ~]# vgs
  VG         #PV #LV #SN Attr   VSize   VFree
  VolGroup00   1   2   0 wz--n-   7.88G  32.00M
  raj_vg       5   3   0 wz--n- 500.00M 440.00M






Add 50 MB partition Linux

[root@rajcentos ~]# fdisk /dev/sde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-51, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-51, default 51):
Using default value 51

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@rajcentos ~]# mkfs -t ext3 /dev/sde1
mke2fs 1.35 (28-Feb-2004)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
13104 inodes, 52208 blocks
2610 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=53477376
7 block groups
8192 blocks per group, 8192 fragments per group
1872 inodes per group
Superblock backups stored on blocks:
        8193, 24577, 40961

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

This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[root@rajcentos ~]# fdisk -l /dev/sde1

Disk /dev/sde1: 53 MB, 53460992 bytes
64 heads, 32 sectors/track, 50 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

Add Virtual disk to VMware and create a partion with fdisk in Linux.

This is about How to add the new VM disk to the existing VMware player.
Make sure that the M is powed off else you will not be able to make changes.
Below are the screen shots and the CLI commands run:





Click Add.




Select Create a New Virtual Disk à Click Next


Accept Recommended à Click Next 



Allocate the size – I have selected Store virtual disk as a single file.

Click Next.




Click Finish.

Now go to the command line via putty.

And run the fdisk utility as follows.

[root@rajcentos dev]# fdisk -l
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1044     8281507+  8e  Linux LVM
Disk /dev/sdb: 536 MB, 536870912 bytes
64 heads, 32 sectors/track, 512 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1               1         512      524272   83  Linux
Disk /dev/sdc: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk /dev/sdc doesn't contain a valid partition table
Disk /dev/sdd: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
Disk /dev/sdd doesn't contain a valid partition table

[root@rajcentos dev]# fdisk /dev/sdc
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-204, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-204, default 204):
Using default value 204
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@rajcentos dev]# fdisk -l /dev/sdc
Disk /dev/sdc: 213 MB, 213909504 bytes
64 heads, 32 sectors/track, 204 cylinders
Units = cylinders of 2048 * 512 = 1048576 bytes
   Device Boot      Start         End      Blocks   Id  System
/dev/sdc1               1         204      208880   83  Linux

[root@rajcentos dev]# mkdir /backupcenter
[root@rajcentos dev]# mount /dev/sdc1 /backupcenter/
[root@rajcentos dev]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      7.3G  1.2G  5.7G  18% /
/dev/sda1              99M   13M   81M  14% /boot
none                  125M     0  125M   0% /dev/shm
/dev/sdb1             496M   11M  460M   3% /remotebackup
/dev/sdc1             198M  5.8M  182M   4% /backupcenter
 

Thats it!