Wednesday, May 14, 2014

Lvm extend on Linux

Below is a flow of sequence 

[root@pc-DOC ~]# 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: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM

Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (39163-52216, default 39163): 
Using default value 39163
Last cylinder, +cylinders or +size{K,M,G} (39163-52216, default 52216): 
Using default value 52216

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM
/dev/sda4 39163 52216 104852220 5 Extended

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): t
Partition number (1-5): 4
Hex code (type L to list codes): 8e
You cannot change a partition into an extended one or vice versa
Delete it first.

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM
/dev/sda4 39163 52216 104852220 5 Extended

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM
/dev/sda4 39163 52216 104852220 5 Extended

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): d
Partition number (1-5): 4

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM

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

Command (m for help): p

Disk /dev/sda: 429.5 GB, 429496729600 bytes
255 heads, 63 sectors/track, 52216 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: 0x00005b0f

Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 13055 104344576 8e Linux LVM
/dev/sda3 13055 39163 209715200 8e Linux LVM
/dev/sda4 39163 52216 104852220 83 Linux

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


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@pc-Doc ~]# ls /dev/sda
sda sda1 sda2 sda3 sda4 

Last login: Thu Jan 23 23:39:15 2014 from 10.253.11.14
[root@pc-Doc ~]# ls /dev/sda
sda sda1 sda2 sda3 sda4 
[root@pc-Doc ~]# ls /dev/sda
sda sda1 sda2 sda3 sda4 
[root@pc-Doc ~]# ls /dev/sda4
/dev/sda4
[root@pc-Doc ~]# pvdisplay 
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_pc-Doc
PV Size 99.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25474
Free PE 0
Allocated PE 25474
PV UUID 2kMDWt-8cjq-WJKd-ThqQ-rzLF-2CC2-UwnYID

--- Physical volume ---
PV Name /dev/sda3
VG Name vg_pc-Doc
PV Size 200.00 GiB / not usable 4.00 MiB
Allocatable yes 
PE Size 4.00 MiB
Total PE 51199
Free PE 321
Allocated PE 50878
PV UUID 8a2FHr-MHsf-x1vu-sbcg-iBX0-chWA-NE9f7X

[root@pc-Doc ~]# pvcreate -f /dev/sda
sda sda1 sda2 sda3 sda4 
[root@pc-Doc ~]# pvcreate -f /dev/sda
sda sda1 sda2 sda3 sda4 
[root@pc-Doc ~]# pvcreate -f /dev/sda4
Physical volume "/dev/sda4" successfully created
[root@pc-Doc ~]# pvdisplay 
--- Physical volume ---
PV Name /dev/sda2
VG Name vg_pc-Doc
PV Size 99.51 GiB / not usable 3.00 MiB
Allocatable yes (but full)
PE Size 4.00 MiB
Total PE 25474
Free PE 0
Allocated PE 25474
PV UUID 2kMDWt-8cjq-WJKd-ThqQ-rzLF-2CC2-UwnYID

--- Physical volume ---
PV Name /dev/sda3
VG Name vg_pc-Doc
PV Size 200.00 GiB / not usable 4.00 MiB
Allocatable yes 
PE Size 4.00 MiB
Total PE 51199
Free PE 321
Allocated PE 50878
PV UUID 8a2FHr-MHsf-x1vu-sbcg-iBX0-chWA-NE9f7X

"/dev/sda4" is a new physical volume of "99.99 GiB"
--- NEW Physical volume ---
PV Name /dev/sda4
VG Name 
PV Size 99.99 GiB
Allocatable NO
PE Size 0 
Total PE 0
Free PE 0
Allocated PE 0
PV UUID uuAtBs-gAVd-WHv0-7stJ-C3Ed-LVwK-HEc2zM

[root@pc-Doc ~]# vgdisplay 
--- Volume group ---
VG Name vg_pc-Doc
System ID 
Format lvm2
Metadata Areas 2
Metadata Sequence No 10
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 2
Act PV 2
VG Size 299.50 GiB
PE Size 4.00 MiB
Total PE 76673
Alloc PE / Size 76352 / 298.25 GiB
Free PE / Size 321 / 1.25 GiB
VG UUID AQ59Um-Lsse-N0xS-gfoc-cHCR-AL0r-1HSgia

[root@pc-Doc ~]# vgextend vg_pc-Doc /dev/sda4
Volume group "vg_pc-Doc" successfully extended
[root@pc-Doc ~]# vgdisplay 
--- Volume group ---
VG Name vg_pc-Doc
System ID 
Format lvm2
Metadata Areas 3
Metadata Sequence No 11
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 3
Act PV 3
VG Size 399.50 GiB
PE Size 4.00 MiB
Total PE 102271
Alloc PE / Size 76352 / 298.25 GiB
Free PE / Size 25919 / 101.25 GiB
VG UUID AQ59Um-Lsse-N0xS-gfoc-cHCR-AL0r-1HSgia

[root@pc-Doc ~]# lvdisplay 
--- Logical volume ---
LV Path /dev/vg_pc-Doc/lv_root
LV Name lv_root
VG Name vg_pc-Doc
LV UUID so0YcW-rveL-SDsI-ipVF-JhrR-eUG4-d9yB1g
LV Write Access read/write
LV Creation host, time pc-Doc, 2013-08-24 17:04:26 -0500
LV Status available
# open 1
LV Size 290.20 GiB
Current LE 74290
Segments 3
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Path /dev/vg_pc-Doc/lv_swap
LV Name lv_swap
VG Name vg_pc-Doc
LV UUID hmD6Yj-m4qE-a422-rGLG-qk3l-TCdk-bOQnAk
LV Write Access read/write
LV Creation host, time pc-Doc, 2013-08-24 17:04:47 -0500
LV Status available
# open 1
LV Size 8.05 GiB
Current LE 2062
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

[root@pc-Doc ~]# lvextend -L +100G /dev/vg_pc-Doc/lv_root
Extending logical volume lv_root to 390.20 GiB
Logical volume lv_root successfully resized
[root@pc-Doc ~]# lvdisplay 
--- Logical volume ---
LV Path /dev/vg_pc-Doc/lv_root
LV Name lv_root
VG Name vg_pc-Doc
LV UUID so0YcW-rveL-SDsI-ipVF-JhrR-eUG4-d9yB1g
LV Write Access read/write
LV Creation host, time pc-Doc, 2013-08-24 17:04:26 -0500
LV Status available
# open 1
LV Size 390.20 GiB
Current LE 99890
Segments 4
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Path /dev/vg_pc-Doc/lv_swap
LV Name lv_swap
VG Name vg_pc-Doc
LV UUID hmD6Yj-m4qE-a422-rGLG-qk3l-TCdk-bOQnAk
LV Write Access read/write
LV Creation host, time pc-Doc, 2013-08-24 17:04:47 -0500
LV Status available
# open 1
LV Size 8.05 GiB
Current LE 2062
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

[root@pc-Doc ~]# resize2fs /dev/vg_pc-Doc/lv_root^C
[root@pc-Doc ~]# df -hT /dev/vg_pc-Doc/lv_root
Filesystem Type Size Used Avail Use% Mounted on
- - 7.8G 172K 7.8G 1% /dev
[root@pc-Doc ~]# df -hT / 
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_pc-Doc-lv_root
ext4 286G 201G 71G 75% /
[root@pc-Doc ~]# resize2fs /dev/vg_pc-Doc/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_pc-Doc/lv_root is mounted on /; on-line resizing required
old desc_blocks = 19, new_desc_blocks = 25
Performing an on-line resize of /dev/vg_pc-Doc/lv_root to 102287360 (4k) blocks.
The filesystem on /dev/vg_pc-Doc/lv_root is now 102287360 blocks long.

[root@pc-Doc ~]# df -hT
Filesystem Type Size Used Avail Use% Mounted on
/dev/mapper/vg_pc-Doc-lv_root
ext4 385G 201G 164G 56% /
tmpfs tmpfs 7.8G 0 7.8G 0% /dev/shm
/dev/sda1 ext4 485M 64M 396M 14% /boot
[root@pc-Doc ~]#

No comments:

Post a Comment