Logical Volume Manager

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 14

Logical Volume Manager:

Create a logical volume:


[root@alok ~]# fdisk /dev/sdb 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): m Command action a toggle a bootable flag b edit bsd disklabel c toggle the dos compatibility flag d delete a partition l list known partition types m print this menu n add a new partition o create a new empty DOS partition table p print the partition table q quit without saving changes s create a new empty Sun disklabel t change a partition's system id u change display/entry units v verify the partition table

w write table to disk and exit x extra functionality (experts only)

Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 First cylinder (1-522, default 1): 1 Last cylinder, +cylinders or +size{K,M,G} (1-522, default 522): +2G

Command (m for help): p

Disk /dev/sdb: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 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: 0x85a2b20b

Device Boot /dev/sdb1

Start 1

End 262

Blocks Id System 2104483+ 83 Linux

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table. Syncing disks. [root@alok ~]# fdisk -cl Disk /dev/sdb: 4294 MB, 4294967296 bytes 255 heads, 63 sectors/track, 522 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: 0x85a2b20b

Device Boot /dev/sdb1

Start 1

End 262

Blocks Id System 2104483+ 83 Linux

Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x000228c6

Device Boot /dev/sda1 * /dev/sda2

Start 1 39

End 39 794

Blocks Id System 307200 83 Linux 6068224 83 Linux

/dev/sda3

794

1306

4109312 82 Linux swap / Solaris

[root@alok ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created [root@alok ~]# pvs PV VG Fmt Attr PSize PFree lvm2 a- 4.00g 4.00g lvm2 a- 2.01g 2.01g

/dev/sdb /dev/sdb1

[root@alok ~]# pvdisplay "/dev/sdb1" is a new physical volume of "2.01 GiB" --- NEW Physical volume --PV Name VG Name PV Size Allocatable PE Size Total PE Free PE Allocated PE PV UUID 0 0 0 0 LyyyIf-vt26-2D3q-l22r-J7A6-9ULZ-rTYWZC 2.01 GiB NO /dev/sdb1

[root@alok ~]# vgcreate vg_vol01 /dev/sdb1 Volume group "vg_vol01" successfully created [root@alok ~]# vgs VG #PV #LV #SN Attr VSize VFree

vg_vol01 1 0 0 wz--n- 2.00g 2.00g

[root@alok ~]# vgdisplay --- Volume group --VG Name System ID Format Metadata Areas lvm2 1 vg_vol01

Metadata Sequence No 1 VG Access VG Status MAX LV Cur LV Open LV Max PV Cur PV Act PV VG Size PE Size Total PE Alloc PE / Size Free PE / Size VG UUID 0 0 0 1 1 2.00 GiB 4.00 MiB 513 0/0 513 / 2.00 GiB Dwq712-Gahr-AL1O-6ANa-xrVQ-HNqd-gr8XkT read/write resizable 0

[root@alok ~]# lvs [root@alok ~]# lvcreate -n lv_vol01 -L 1G vg_vol01 Logical volume "lv_vol01" created

[root@alok ~]# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert

lv_vol01 vg_vol01 -wi-a- 1.00g [root@alok ~]# lvdisplay --- Logical volume --LV Name VG Name LV UUID LV Write Access LV Status # open LV Size Current LE Segments Allocation /dev/vg_vol01/lv_vol01 vg_vol01 ZpGoN2-Y3tl-X6XN-U1MD-z7ky-bcjW-pADj4f read/write available 0 1.00 GiB 256 1 inherit auto

Read ahead sectors - currently set to Block device

256 253:0

Adding logical volume to startup for auto-mount


[root@alok ~]# blkid /dev/vg_vol01/lv_vol01 /dev/vg_vol01/lv_vol01: UUID="c8d556f5-39bd-496b-b487-b963dc7882f7" TYPE="ext4" [root@alok ~]#

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

# # /etc/fstab # Created by anaconda on Sat Oct 5 08:20:46 2013 # # 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=b9dfc225-6932-4ec4-ab68-d323957b1917 / UUID=7977244e-2879-4538-844a-04eeffeb5823 /boot UUID=16923984-9e4b-44d0-89a5-3717278cfcd6 swap UUID=c8d556f5-39bd-496b-b487-b963dc7882f7 /alok tmpfs devpts sysfs proc /dev/shm /dev/pts /sys /proc tmpfs defaults 00 ext4 defaults ext4 defaults swap defaults ext4 defaults 11 12 00 12

devpts gid=5,mode=620 0 0 sysfs defaults proc defaults 00 00

Extending Logical Volume:


[root@alok ~]# df -h Filesystem /dev/sda2 tmpfs /dev/sda1 Size Used Avail Use% Mounted on 5.7G 2.2G 3.3G 40% / 764M 264K 764M 1% /dev/shm 291M 30M 247M 11% /boot

/dev/mapper/vg_vol01-lv_vol01 1008M 34M 924M 4% /alok .host:/ 30G 24G 5.9G 81% /mnt/hgfs

[root@alok ~]# lvextend -L +100M /dev/vg_vol01/lv_vol01 Extending logical volume lv_vol01 to 1.10 GiB Logical volume lv_vol01 successfully resized

[root@alok ~]# df -h Filesystem /dev/sda2 tmpfs /dev/sda1 Size Used Avail Use% Mounted on 5.7G 2.2G 3.3G 40% / 764M 264K 764M 1% /dev/shm 291M 30M 247M 11% /boot

/dev/mapper/vg_vol01-lv_vol01 1008M 34M 924M 4% /alok .host:/ 30G 24G 5.9G 81% /mnt/hgfs

[root@alok ~]# resize2fs -p /dev/mapper/vg_vol01-lv_vol01 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/vg_vol01-lv_vol01 is mounted on /alok; on-line resizing required

old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/mapper/vg_vol01-lv_vol01 to 287744 (4k) blocks. The filesystem on /dev/mapper/vg_vol01-lv_vol01 is now 287744 blocks long.

[root@alok ~]# df -h Filesystem /dev/sda2 tmpfs /dev/sda1 Size Used Avail Use% Mounted on 5.7G 2.2G 3.3G 40% / 764M 264K 764M 1% /dev/shm 291M 30M 247M 11% /boot

/dev/mapper/vg_vol01-lv_vol01 1.1G 34M 1017M 4% /alok .host:/ [root@alok ~]# 30G 24G 5.9G 81% /mnt/hgfs

Reducing the size of logical volume:


[root@alok ~]# umount /alok [root@alok ~]# df -h Filesystem /dev/sda2 tmpfs /dev/sda1 .host:/ Size Used Avail Use% Mounted on 5.7G 2.2G 3.3G 40% / 764M 264K 764M 1% /dev/shm 291M 30M 247M 11% /boot 30G 24G 5.9G 81% /mnt/hgfs

[root@alok ~]# fsck -f /dev/mapper/vg_vol01-lv_vol01 fsck from util-linux-ng 2.17.2 e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/mapper/vg_vol01-lv_vol01: 11/73728 files (0.0% non-contiguous), 13149/287744 blocks [root@alok ~]# resize2fs -p /dev/mapper/vg_vol01-lv_vol01 resize2fs 1.41.12 (17-May-2010) The filesystem is already 287744 blocks long. Nothing to do!

[root@alok ~]# resize2fs -p /dev/mapper/vg_vol01-lv_vol01 1008M resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/mapper/vg_vol01-lv_vol01 to 258048 (4k) blocks. Begin pass 3 (max = 9)

Scanning inode table

XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

The filesystem on /dev/mapper/vg_vol01-lv_vol01 is now 258048 blocks long.

[root@alok ~]# lvreduce -L 1008M /dev/mapper/vg_vol01-lv_vol01 WARNING: Reducing active logical volume to 1008.00 MiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_vol01? [y/n]: y Reducing logical volume lv_vol01 to 1008.00 MiB Logical volume lv_vol01 successfully resized [root@alok ~]# mount -a [root@alok ~]# df -h Filesystem /dev/sda2 tmpfs /dev/sda1 .host:/ Size Used Avail Use% Mounted on 5.7G 2.2G 3.3G 40% / 764M 264K 764M 1% /dev/shm 291M 30M 247M 11% /boot 30G 24G 5.9G 81% /mnt/hgfs

/dev/mapper/vg_vol01-lv_vol01 992M 34M 909M 4% /alok

Volume Group Extending and Reducing:


[root@alok ~]# pvs PV VG Fmt Attr PSize PFree

/dev/sdb1 vg_vol01 lvm2 a- 2.00g 1.02g /dev/sdc1 lvm2 a- 3.01g 3.01g

[root@alok ~]# vgextend vg_vol01 /dev/sdc1 Volume group "vg_vol01" successfully extended [root@alok ~]# vgdisplay --- Volume group --VG Name System ID Format Metadata Areas lvm2 2 vg_vol01

Metadata Sequence No 5 VG Access VG Status MAX LV Cur LV Open LV Max PV Cur PV Act PV VG Size PE Size Total PE 1 1 0 2 2 5.01 GiB 4.00 MiB 1283 read/write resizable 0

Alloc PE / Size Free PE / Size VG UUID

252 / 1008.00 MiB 1031 / 4.03 GiB Dwq712-Gahr-AL1O-6ANa-xrVQ-HNqd-gr8XkT

[root@alok ~]# pvmove /dev/sdc1 No data to move for vg_vol01 [root@alok ~]# vgreduce vg_vol01 /dev/sdc1 Removed "/dev/sdc1" from volume group "vg_vol01" [root@alok ~]# vgdisplay --- Volume group --VG Name System ID Format Metadata Areas lvm2 1 vg_vol01

Metadata Sequence No 6 VG Access VG Status MAX LV Cur LV Open LV Max PV Cur PV Act PV VG Size PE Size 1 1 0 1 1 2.00 GiB 4.00 MiB read/write resizable 0

Total PE Alloc PE / Size Free PE / Size VG UUID

513 252 / 1008.00 MiB 261 / 1.02 GiB Dwq712-Gahr-AL1O-6ANa-xrVQ-HNqd-gr8XkT

You might also like