Increase the size of a Linux LVM by expanding the virtual machine disk
Many time we need additional space on Linux OS which is created on VMBox so “How to Increase the size of a Linux LVM by expanding the virtual machine disk” , this article will definitely help you out if you have getting error for space.
Note : This is for “Fixed” sized VDI created in VMBox.
Step 1: Goto path where you have installed VMBox here my path is “C:\Program Files\Oracle\VirtualBox\VirtualBox-4.3.22-98236-Win” and clone (or we can say take backup) present VDI.
Command:
C:\Program Files\Oracle\VirtualBox>vBoxManage clonehd "C:\Users\kaatchi\VirtualBox VMs\12C\12C.vhd" "C:\Users\kaatchi\VirtualBox VMs\12C\12C_clone.vhd" -format VDI -variant Standard
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone medium created in format 'VDI'. UUID: df77ed6b-5d2c-4569-badb-5968ce6d636c
Note: Above command will take some time to complete.
Step 2: You have to now modify the cloned VDI to different size from below image you
can see that I have made my Hardisk VDI to 50GB which was before 30GB.
can see that I have made my Hardisk VDI to 50GB which was before 30GB.
Command:
C:\Program Files\Oracle\VirtualBox>vBoxManage modifyhd "C:\Users\kaatchi\VirtualBox VMs\12C\12C_clone.vhd" --resize 51200
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Step 3: Now again clone the modified VDI as below.
Command:
C:\Program Files\Oracle\VirtualBox>vBoxManage clonehd "C:\Users\kaatchi\VirtualBox VMs\12C\12C_clone.vhd" "C:\Users\kaatchi\VirtualBox VMs\12C\12C1.vhd" -format VDI -
variant Fixed
variant Fixed
Attached the new VDI to VMBox and start the VMBox, mine is node1.vdi so I have attached this.
Congratulations, you have Increased the size of hardisk VDI on VMBox, you can check it in VMBox machine settings as below:
Step 4: This is not the end , the question remain the same “how to increase the size of a Linux LVM”, for this login to Linux OS by root user and you to increase the size by fdisk command as below:
[root@rac1 ~]# fdisk -l
Disk /dev/sda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 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: 0x00058335
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 2611 20458496 8e Linux LVM
/dev/sda3 2611 3916 10483750 8e Linux LVM
/dev/sda4 3917 5221 10482412+ 8e Linux LVM
Disk /dev/sdb: 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: 0xc0e1c9cb
Device Boot Start End Blocks Id System
/dev/sdb1 1 1305 10482381 83 Linux
Disk /dev/sdc: 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: 0x3357c574
Device Boot Start End Blocks Id System
/dev/sdc1 1 1305 10482381 83 Linux
Disk /dev/sdd: 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: 0x63ef4291
Device Boot Start End Blocks Id System
/dev/sdd1 1 1305 10482381 83 Linux
Disk /dev/mapper/vg_rac1-lv_root: 29.5 GB, 29532094464 bytes
255 heads, 63 sectors/track, 3590 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_rac1-lv_swap: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 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
From above fdisk -l output /dev/sda4 is listed as “Linux LVM” and it has the ID of 8e, this is hex code which tells that it is a Linux LVM.
Note: Below /dev/mapper/vg_rac1-lv_root is the volume made for /dev/sda4 and this is what we will be expanding.
[root@rac1 oracle]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rac1-lv_root 27G 20G 6.6G 75% / tmpfs 2.3G 72K 2.3G 1% /dev/shm /dev/sda1 477M 85M 363M 19% /boot Softwares 373G 331G 42G 89% /media/sf_Softwares
Now, start following below steps for adding partition:
[root@rac1 ~]#
[root@rac1 ~]# 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
e extended
p primary partition (1-4)
p
Selected partition 4
First cylinder (3917-5221, default 3917):
Using default value 3917
Last cylinder, +cylinders or +size{K,M,G} (3917-5221, default 5221):
Using default value 5221
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.
Now we have to create a physical volume which later use by the logical volume manager (LVM)
[root@rac1 ~]# pvcreate /dev/sda4 Device /dev/sda4 not found (or ignored by filtering).
Above is showing error to create , so as a solution you have to reboot the system.
[root@rac1 ~]# [root@rac1 ~]# reboot [root@rac1 ~]# Broadcast message from root@rac1.localdomain (/dev/pts/0) at 14:47 ... The system is going down for reboot NOW! login as: root root@192.168.56.71's password: Last login: Tue Jun 6 14:45:09 2017 from 192.168.56.1 [root@rac1 ~]# [root@rac1 ~]#
After reboot again execute the command.
[root@rac1 ~]# pvcreate /dev/sda4 Physical volume "/dev/sda4" successfully created
Next we have to check the name of the current volume group using the vgdisplay command. The name will be different on your system here the name is “vg_rac1” for me.
[root@rac1 ~]# vgdisplay
--- Volume group ---
VG Name vg_rac1
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 5
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 29.50 GiB
PE Size 4.00 MiB
Total PE 7553
Alloc PE / Size 7553 / 29.50 GiB
Free PE / Size 0 / 0
VG UUID rV6Zxc-W8xS-vVOK-M6iV-WniH-leB1-RCTi59
Now extent the size as below:
[root@rac1 ~]# vgextend vg_rac1 /dev/sda4 Volume group "vg_rac1" successfully extended
Next execute pvscan command which has to scan all disks for physical volumes, this should display new added /dev/sda4
[root@rac1 ~]#
[root@rac1 ~]# pvscan
PV /dev/sda2 VG vg_rac1 lvm2 [19.51 GiB / 0 free]
PV /dev/sda3 VG vg_rac1 lvm2 [10.00 GiB / 0 free]
PV /dev/sda4 VG vg_rac1 lvm2 [9.99 GiB / 9.99 GiB free]
Total: 3 [39.50 GiB] / in use: 3 [39.50 GiB] / in no VG: 0 [0 ]
Now check the path of the logical volume using lvdisplay:
[root@rac1 ~]# lvdisplay
--- Logical volume ---
LV Path /dev/vg_rac1/lv_root
LV Name lv_root
VG Name vg_rac1
LV UUID e2eZMR-lFDh-eCB0-i84w-SMlJ-X59Z-hWfljC
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-05-10 04:25:50 +0530
LV Status available
# open 1
LV Size 27.50 GiB
Current LE 7041
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:0
--- Logical volume ---
LV Path /dev/vg_rac1/lv_swap
LV Name lv_swap
VG Name vg_rac1
LV UUID Z4cghb-HLNX-wkp2-0tIM-20dO-M52K-f1mwdJ
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-05-10 04:25:54 +0530
LV Status available
# open 2
LV Size 2.00 GiB
Current LE 512
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 252:1
Now extend it:
[root@rac1 ~]# lvextend /dev/vg_rac1/lv_root /dev/sda4 Extending logical volume lv_root to 37.50 GiB Logical volume lv_root successfully resized
Finally but very important executed below command which is to resize the file system:
[root@rac1 ~]# resize2fs /dev/vg_rac1/lv_root resize2fs 1.43-WIP (20-Jun-2013) Filesystem at /dev/vg_rac1/lv_root is mounted on /; on-line resizing required old_desc_blocks = 2, new_desc_blocks = 3 The filesystem on /dev/vg_rac1/lv_root is now 9829376 blocks long.
Congratualations, Your added space is ready it has increased to 16GB now
[root@rac1 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_rac1-lv_root 37G 20G 16G 55% / tmpfs 2.3G 138M 2.2G 6% /dev/shm /dev/sda1 477M 85M 363M 19% /boot Softwares 373G 331G 42G 89% /media/sf_Softwares
No comments:
Post a Comment