lvm

LVM

[root@LVM ~]# rpm -qa | grep lvm
lvm2-libs-2.02.118-2.el6.x86_64
lvm2-2.02.118-2.el6.x86_64
mesa-private-llvm-3.4-3.el6.x86_64

——————————————————————————–
[root@LVM ~]# fdisk /dev/sda

WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
switch off the mode (command ‘c’) and change display units to
sectors (command ‘u’).

Command (m for help): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x0007152d

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda3             549        7833    58510336   83  Linux

Command (m for help): n
Command action
e   extended
p   primary partition (1-4)
Partition number (1-4):
Value out of range.
Partition number (1-4): 4
First cylinder (39-7832, default 39):
Using default value 39
Last cylinder, +cylinders or +size{K,M,G} (39-548, default 548):
Using default value 548

Command (m for help): p

Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x0007152d

Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda3             549        7833    58510336   83  Linux
/dev/sda4              39         548     4093586    5  Extended

Partition table entries are not in disk order

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@LVM ~]# partprobe 
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.
———————————————————————————-

[root@LVM ~]# fdisk /dev/sda
WARNING: DOS-compatible mode is deprecated. It’s strongly recommended to
         switch off the mode (command ‘c’) and change display units to
         sectors (command ‘u’).
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (39-548, default 39):
Using default value 39
Last cylinder, +cylinders or +size{K,M,G} (39-548, default 548): +100M
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (53-548, default 53):
Using default value 53
Last cylinder, +cylinders or +size{K,M,G} (53-548, default 548): +100M
Command (m for help): n
Command action
   l   logical (5 or over)
   p   primary partition (1-4)
l
First cylinder (67-548, default 67):
Using default value 67
Last cylinder, +cylinders or +size{K,M,G} (67-548, default 548): +100M
Command (m for help): p
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x0007152d
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda3             549        7833    58510336   83  Linux
/dev/sda4              39         548     4093586    5  Extended
/dev/sda5              39          52      109434+  83  Linux
/dev/sda6              53          66      112423+  83  Linux
/dev/sda7              67          80      112423+  83  Linux
Partition table entries are not in disk order
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@LVM ~]# partprobe 
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.
—————————————————————————————–
[root@LVM ~]# fdisk -l
Disk /dev/sda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x0007152d
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          39      307200   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda3             549        7833    58510336   83  Linux
/dev/sda4              39         548     4093586    5  Extended
/dev/sda5              39          52      109434+  83  Linux
/dev/sda6              53          66      112423+  83  Linux
/dev/sda7              67          80      112423+  83  Linux
Partition table entries are not in disk order
————————————————————————————————
[root@LVM ~]# pvs
 
[root@LVM ~]# pvdisplay 
 
[root@LVM ~]# pvcreate /dev/sda5 /dev/sda6 /dev/sda7
  Device /dev/sda5 not found (or ignored by filtering).
  Device /dev/sda6 not found (or ignored by filtering).
  Device /dev/sda7 not found (or ignored by filtering).
[root@LVM ~]# reboot 
Broadcast message from root@LVM
(/dev/pts/1) at 18:04 …
The system is going down for reboot NOW!
[root@LVM ~]# Connection to 172.16.28.145 closed by remote host.
Connection to 172.16.28.145 closed.
mohammedrafi@NOC-RAFI:~$ ssh root@172.16.28.145
root@172.16.28.145’s password:
Last login: Sun Feb 21 17:51:27 2016 from 172.16.28.1
[root@LVM ~]# pvcreate /dev/sda5 /dev/sda6 /dev/sda7
  Physical volume “/dev/sda5” successfully created
  Physical volume “/dev/sda6” successfully created
  Physical volume “/dev/sda7” successfully created
[root@LVM ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda5       lvm2 —  106.87m 106.87m
  /dev/sda6       lvm2 —  109.79m 109.79m
  /dev/sda7       lvm2 —  109.79m 109.79m
[root@LVM ~]# pvdisplay 
  “/dev/sda5” is a new physical volume of “106.87 MiB”
  — NEW Physical volume —
  PV Name               /dev/sda5
  VG Name
  PV Size               106.87 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               eE7Ylp-a9FM-OUJ5-QLQT-G2Mo-HREA-MGM8JK
  “/dev/sda6” is a new physical volume of “109.79 MiB”
  — NEW Physical volume —
  PV Name               /dev/sda6
  VG Name
  PV Size               109.79 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               0FIRlw-30hM-ZKY7-ilfk-3obM-T9xi-C7i2l6
  “/dev/sda7” is a new physical volume of “109.79 MiB”
  — NEW Physical volume —
  PV Name               /dev/sda7
  VG Name
  PV Size               109.79 MiB
  Allocatable           NO
  PE Size               0
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               TLXDQH-m5c1-TeH9-5Io3-Lu9y-sdpQ-97rm0i
———————————————————————————————-
[root@LVM ~]# vgs
[root@LVM ~]# vgdisplay 
[root@LVM ~]# vgcreate volumegroup-name /dev/sda5 /dev/sda6 /dev/sda7
  Volume group “volumegroup-name” successfully created
[root@LVM ~]# vgs
  VG               #PV #LV #SN Attr   VSize   VFree
  volumegroup-name   3   0   0 wz–n- 320.00m 320.00m
[root@LVM ~]# vgdisplay 
  — Volume group —
  VG Name               volumegroup-name
  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               320.00 MiB
  PE Size               4.00 MiB
  Total PE              80
  Alloc PE / Size       0 / 0
  Free  PE / Size       80 / 320.00 MiB
  VG UUID               Chs0rl-ZfV0-D2WQ-4D2X-Jnt0-UUaJ-2vjBpD
—————————————————————————————
             Creating Logical Volumes using MB Size’s
[root@LVM ~]# lvs
[root@LVM ~]# lvdisplay 
[root@LVM ~]# lvcreate -L 200M volumegroup-name -n logicalvolume-name
  Logical volume “logicalvolume-name” created.
[root@LVM ~]# lvs
  LV                 VG               Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  logicalvolume-name volumegroup-name -wi-a—– 200.00m
[root@LVM ~]# lvdisplay 
  — Logical volume —
  LV Path                /dev/volumegroup-name/logicalvolume-name
  LV Name                logicalvolume-name
  VG Name                volumegroup-name
  LV UUID                H2CqM4-9mLm-i5d5-20Im-ZZj5-fWR0-ZMJHVQ
  LV Write Access        read/write
  LV Creation host, time LVM, 2016-02-21 18:15:16 -0800
  LV Status              available
  # open                 0
  LV Size                200.00 MiB
  Current LE             50
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
——————————————————————————————————
[root@LVM ~]# mkfs.ext4 /dev/volumegroup-name/logicalvolume-name
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=1024 (log=0)
Fragment size=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
51200 inodes, 204800 blocks
10240 blocks (5.00%) reserved for the super user
First data block=1
Maximum filesystem blocks=67371008
25 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193, 24577, 40961, 57345, 73729
Writing inode tables: done
Creating journal (4096 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.
——————————————————————————————————–
[root@LVM ~]# mkdir /lvmdata

[root@LVM ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)

[root@LVM ~]# ls -l /lvmdata/
total 0

[root@LVM ~]# mount /dev/volumegroup-name/logicalvolume-name /lvmdata/

[root@LVM ~]# ls -l /lvmdata/
total 12
drwx——. 2 root root 12288 Feb 21 18:17 lost+found

[root@LVM ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/mapper/volumegroup–name-logicalvolume–name on /lvmdata type ext4 (rw)

[root@LVM ~]# df -hT
Filesystem           Type   Size  Used Avail Use% Mounted on
/dev/sda3            ext4    55G  5.5G   47G  11% /
tmpfs                tmpfs  358M   72K  358M   1% /dev/shm
/dev/sda1            ext4   283M   41M  228M  16% /boot
/dev/mapper/volumegroup–name-logicalvolume–name
                     ext4   190M  1.6M  179M   1% /lvmdata
————————————————————————————————————-


[root@LVM ~]# vim /etc/fstab 
#
# /etc/fstab
# Created by anaconda on Thu Dec 24 00:47:10 2015
#
# Accessible filesystems, by reference, are maintained under ‘/dev/disk’
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=cbc3eda3-9a23-4943-a8c4-3990addeb161 /                       ext4    defaults        1 1
UUID=d5b88247-f67f-4b40-9862-16826e250b78 /boot                   ext4    defaults        1 2
UUID=af69d0e5-b600-49a0-9228-d4195936bdd2 swap                    swap    defaults        0 0
tmpfs                   /dev/shm                tmpfs   defaults        0 0
devpts                  /dev/pts                devpts  gid=5,mode=620  0 0
sysfs                   /sys                    sysfs   defaults        0 0
proc                    /proc                   proc    defaults        0 0

/dev/mapper/volumegroup–name-logicalvolume–name  /lvmdata  ext4 defaults 0 0
———————————————————————————————————–
[root@LVM ~]# reboot

[root@LVM ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext=”system_u:object_r:tmpfs_t:s0″)
/dev/sda1 on /boot type ext4 (rw)
/dev/mapper/volumegroup–name-logicalvolume–name on /lvmdata type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
——————————————————————————————
[root@LVM ~]# lvdisplay 
— Logical volume —
LV Path                /dev/volumegroup-name/logicalvolume-name
LV Name                logicalvolume-name
VG Name                volumegroup-name
LV UUID                H2CqM4-9mLm-i5d5-20Im-ZZj5-fWR0-ZMJHVQ
LV Write Access        read/write
LV Creation host, time LVM, 2016-02-21 18:15:16 -0800
LV Status              available
# open                 1
LV Size                200.00 MiB
Current LE             50
Segments               2
Allocation             inherit
Read ahead sectors     auto
– currently set to     256
Block device           253:0

[root@LVM ~]# lvextend –size 300M /dev/volumegroup-name/logicalvolume-name
Size of logical volume volumegroup-name/logicalvolume-name changed from 200.00 MiB (50 extents) to 300.00 MiB (75 extents).
Logical volume logicalvolume-name successfully resized

[root@LVM ~]# lvdisplay 
— Logical volume —
LV Path                /dev/volumegroup-name/logicalvolume-name
LV Name                logicalvolume-name
VG Name                volumegroup-name
LV UUID                H2CqM4-9mLm-i5d5-20Im-ZZj5-fWR0-ZMJHVQ
LV Write Access        read/write
LV Creation host, time LVM, 2016-02-21 18:15:16 -0800
LV Status              available
# open                 1
LV Size                300.00 MiB
Current LE             75
Segments               3
Allocation             inherit
Read ahead sectors     auto
– currently set to     256
Block device           253:0

——————————————————————————————–
[root@LVM ~]# lvresize –size 100M /dev/volumegroup-name/logicalvolume-name
  WARNING: Reducing active and open logical volume to 100.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce logicalvolume-name? [y/n]: y
  Size of logical volume volumegroup-name/logicalvolume-name changed from 300.00 MiB (75 extents) to 100.00 MiB (25 extents).
  Logical volume logicalvolume-name successfully resized
[root@LVM ~]# lvdisplay
  — Logical volume —
  LV Path                /dev/volumegroup-name/logicalvolume-name
  LV Name                logicalvolume-name
  VG Name                volumegroup-name
  LV UUID                H2CqM4-9mLm-i5d5-20Im-ZZj5-fWR0-ZMJHVQ
  LV Write Access        read/write
  LV Creation host, time LVM, 2016-02-21 18:15:16 -0800
  LV Status              available
  # open                 1
  LV Size                100.00 MiB
  Current LE             25
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
   ———————————————————————————————-
[root@LVM ~]# lvresize –size +100M /dev/volumegroup-name/logicalvolume-name
  Size of logical volume volumegroup-name/logicalvolume-name changed from 100.00 MiB (25 extents) to 200.00 MiB (50 extents).
  Logical volume logicalvolume-name successfully resized
[root@LVM ~]# lvdisplay 
  — Logical volume —
  LV Path                /dev/volumegroup-name/logicalvolume-name
  LV Name                logicalvolume-name
  VG Name                volumegroup-name
  LV UUID                H2CqM4-9mLm-i5d5-20Im-ZZj5-fWR0-ZMJHVQ
  LV Write Access        read/write
  LV Creation host, time LVM, 2016-02-21 18:15:16 -0800
  LV Status              available
  # open                 1
  LV Size                200.00 MiB
  Current LE             50
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
————————————————————————————-
[root@LVM ~]# lvremove /dev/mapper/volumegroup–name-logicalvolume–name
Logical volume volumegroup-name/logicalvolume-name contains a filesystem in use.

[root@LVM ~]# umount /lvmdata/

[root@LVM ~]# lvremove /dev/mapper/volumegroup–name-logicalvolume–name
Do you really want to remove active logical volume logicalvolume-name? [y/n]: y
Logical volume “logicalvolume-name” successfully removed

[root@LVM ~]# lvdisplay
[root@LVM ~]#
—————————————————————————————————
[root@LVM ~]# vgdisplay
— Volume group —
VG Name               volumegroup-name
System ID
Format                lvm2
  Metadata Areas        3
Metadata Sequence No  6
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               320.00 MiB
PE Size               4.00 MiB
Total PE              80
Alloc PE / Size       0 / 0
Free  PE / Size       80 / 320.00 MiB
VG UUID               Chs0rl-ZfV0-D2WQ-4D2X-Jnt0-UUaJ-2vjBpD
———————————

[root@LVM ~]# vgreduce volumegroup-name /dev/sda7
Removed “/dev/sda7” from volume group “volumegroup-name”

[root@LVM ~]# vgdisplay
— Volume group —
VG Name               volumegroup-name
System ID
Format                lvm2
  Metadata Areas        2
Metadata Sequence No  7
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               212.00 MiB
PE Size               4.00 MiB
Total PE              53
Alloc PE / Size       0 / 0
Free  PE / Size       53 / 212.00 MiB
VG UUID               Chs0rl-ZfV0-D2WQ-4D2X-Jnt0-UUaJ-2vjBpD

[root@LVM ~]# vgremove volumegroup-name
  Volume group “volumegroup-name” successfully removed
[root@LVM ~]# vgdisplay
[root@LVM ~]# vgextend volumegroup-name /dev/sda8
———————————————————————————–
[root@LVM ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda5       lvm2 —  106.87m 106.87m
  /dev/sda6       lvm2 —  109.79m 109.79m
  /dev/sda7       lvm2 —  109.79m 109.79m
[root@LVM ~]# pvremove /dev/sda7
  Labels on physical volume “/dev/sda7” successfully wiped
You have new mail in /var/spool/mail/root
[root@LVM ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda5       lvm2 —  106.87m 106.87m
  /dev/sda6       lvm2 —  109.79m 109.79m
—————————————————————————————–
[root@LVM ~]# vgextend volumegroup-name /dev/sda8

Creating Logical Volumes using PE Size’s

[root@LVM ~]# vgcreate -s 32M volumegroup /dev/sda5 /dev/sda6 /dev/sda7
  Volume group “volumegroup” successfully created
[root@LVM ~]# vgdisplay
  — Volume group —
  VG Name               volumegroup
  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               288.00 MiB
  PE Size               32.00 MiB
  Total PE              9
  Alloc PE / Size       0 / 0
  Free  PE / Size       9 / 288.00 MiB
  VG UUID               1iQRqT-WUVu-Mwm8-J0TE-KQaw-qdBt-5jxd3B
——————————————————————————————————————-
[root@LVM ~]# bc
bc 1.06.95
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty’.
9/3
3
3*32
96
^C
(interrupt) Exiting bc.
—————————————————————————————————-
[root@LVM ~]# lvcreate -l 5 -n lv-name volumegroup
  Logical volume “lv-name” created.
[root@LVM ~]# lvdisplay
  — Logical volume —
  LV Path                /dev/volumegroup/lv-name
  LV Name                lv-name
  VG Name                volumegroup
  LV UUID                F43nSs-KNVU-SKOT-U338-uLDC-22xG-KoYqeL
  LV Write Access        read/write
  LV Creation host, time LVM, 2016-02-21 20:17:44 -0800
  LV Status              available
  # open                 0
  LV Size                160.00 MiB
  Current LE             5
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  – currently set to     256
  Block device           253:0
————————————————————————–
Advertisements
Posted in: lvm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s