Skip to content

Resizing lvm volume

wordpress meta

title: 'Resizing a LVM Volume'
date: '2013-06-24T07:46:21-05:00'
status: draft
permalink: /resizing-lvm-volume
author: admin
excerpt: ''
type: post
id: 278
category:
    - Uncategorized
tag: []
post_format: []

• Delete Existing partition
• Create a new Partition and select all defaults
• Write Partition Table to disk and reboot the machine
• Do pvresize
• Do vgscan
• Turn the swap off
• remove swap
• Extend the original partition to 90GB
• Recreate SWAP at the end for the rest of space
• Switch on Swap again
• Resize the file system

[root@ovm1057 ~]# fdisk /dev/xvda

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/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0005ba81

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 6528 51915776 8e Linux LVM

Delete 2nd partition:

Command (m for help): d
Partition number (1-4): 2

Command (m for help): p

Disk /dev/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0005ba81

Create a new Partition and select all defaults:

Command (m for help): n
Command action
e extended
p primary partition (1-4)

Partition number (1-4): 2
First cylinder (64-13054, default 64):
Using default value 64
Last cylinder, +cylinders or +size{K,M,G} (64-13054, default 13054):
Using default value 13054

Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)

Command (m for help): p

Disk /dev/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0005ba81

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 13054 104343231 8e Linux LVM

Write Partition Table to disk and reboot the machine:

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@ovm1057 ~]# reboot -n

[root@ovm1057 ~]# fdisk -l

Disk /dev/xvda: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 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: 0x0005ba81

Device Boot Start End Blocks Id System
/dev/xvda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2 64 13054 104343231 8e Linux LVM

Disk /dev/mapper/vg_system-lv_root: 44.8 GB, 44770000896 bytes
255 heads, 63 sectors/track, 5442 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: 0x00000000

Disk /dev/mapper/vg_system-lv_swap: 8388 MB, 8388608000 bytes
255 heads, 63 sectors/track, 1019 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: 0x00000000

Do pvresize

[root@ovm1057 ~]# pvresize /dev/xvda2
Physical volume "/dev/xvda2" changed
1 physical volume(s) resized / 0 physical volume(s) not resized

Do vgscan

[root@ovm1057 ~]# vgscan
Reading all physical volumes. This may take a while...
Found volume group "vg_system" using metadata type lvm2
[root@ovm1057 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
vg_system 1 2 0 wz--n- 99.51g 50.00g

[root@ovm1057 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-lv_root
42G 2.5G 37G 7% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/xvda1 485M 98M 362M 22% /boot
carter.keste.com:/CNL10003
22T 5.7T 17T 27% /u01/downloads
[root@ovm1057 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_system -wi-ao--- 41.70g
lv_swap vg_system -wi-ao--- 7.81g
[root@ovm1057 ~]#

[root@ovm1057 ~]# free
total used free shared buffers cached
Mem: 3791860 170448 3621412 0 14340 46648
-/+ buffers/cache: 109460 3682400
Swap: 8191996 0 8191996

Turn the swap off

[root@ovm1057 ~]# swapoff -a
[root@ovm1057 ~]# free
total used free shared buffers cached
Mem: 3791860 164892 3626968 0 14336 46664
-/+ buffers/cache: 103892 3687968
Swap: 0 0 0

remove swap

[root@ovm1057 ~]# lvremove vg_system lv_swap
Logical volume vg_system/lv_root contains a filesystem in use.
Do you really want to remove active logical volume lv_swap? [y/n]: y
Logical volume "lv_swap" successfully removed
Volume group "lv_swap" not found

Extend the original partition to 90GB

[root@ovm1057 ~]# lvextend -L90G /dev/vg_system/lv_root
Extending logical volume lv_root to 90.00 GiB
Logical volume lv_root successfully resized
[root@ovm1057 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_system -wi-ao--- 90.00g
[root@ovm1057 ~]#

Recreate SWAP at the end for the rest of space

[root@ovm1057 ~]# lvcreate -l 100%FREE -n lv_swap vg_system
Logical volume "lv_swap" created
[root@ovm1057 ~]# lvs
LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert
lv_root vg_system -wi-ao--- 90.00g
lv_swap vg_system -wi-a---- 9.51g

[root@ovm1057 ~]# mkswap /dev/vg_system/lv_swap
mkswap: /dev/vg_system/lv_swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 9969660 KiB
no label, UUID=c6fed245-629e-4c1c-944b-da4dc4ca37d8
[root@ovm1057 ~]# free
total used free shared buffers cached
Mem: 3791860 164768 3627092 0 14508 46876
-/+ buffers/cache: 103384 3688476
Swap: 0 0 0

Switch on Swap again

[root@ovm1057 ~]# swapon -a
[root@ovm1057 ~]# free
total used free shared buffers cached
Mem: 3791860 172076 3619784 0 14512 46876
-/+ buffers/cache: 110688 3681172
Swap: 9969660 0 9969660

Resize the file system

[root@ovm1057 ~]# resize2fs /dev/mapper/vg_system-lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_system-lv_root is mounted on /; on-line resizing required
old desc_blocks = 3, new_desc_blocks = 6
Performing an on-line resize of /dev/mapper/vg_system-lv_root to 23592960 (4k) blocks.
The filesystem on /dev/mapper/vg_system-lv_root is now 23592960 blocks long.

[root@ovm1057 ~]#

[root@ovm1057 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_system-lv_root
89G 2.5G 82G 3% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/xvda1 485M 98M 362M 22% /boot
carter.keste.com:/CNL10003
22T 5.7T 17T 27% /u01/downloads