Increase partition size in Linux after increasing VM disk space

lvm-linuxThis tutorial show how to increase partition size in Linux after increasing the disk space in VM with Citrix XenServer. Basically, there are some steps that we must do some steps in Linux to let Linux “aware” of this change. Scripts:

[[email protected] search]# 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): d
Partition number (1-4): 2

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

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): 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.
[[email protected] search]# reboot

Or if you want to create a new partition based on the free space before extend, we can use fdisk -l to see which is the free one (e.g. /dev/sda3), and then we can use pvcreate (let say the vg name is vg_quickstart):

[bash]pvcreate /dev/sda3
pvs
vgextend vg_quickstart /dev/sda3
[/bash]

After the system is rebooted: (pay attention to the volume group name in the pvresize to use in later steps)

[[email protected] ~]# pvresize -v /dev/xvda2
    Using physical volume(s) on command line
    Archiving volume group "vg_webserver" metadata (seqno 4).
    Resizing volume "/dev/xvda2" to 208689152 sectors.
    Resizing physical volume /dev/xvda2 from 0 to 51073 extents.
    Updating physical volume "/dev/xvda2"
    Creating volume group backup "/etc/lvm/backup/vg_webserver" (seqno 5).
  Physical volume "/dev/xvda2" changed
  1 physical volume(s) resized / 0 physical volume(s) not resized
[[email protected] ~]# lvextend -l +100%FREE /dev/vg_webserver/lv_root 
  Extending logical volume lv_root to 150.00 GiB
  Logical volume lv_root successfully resized
[[email protected] ~]# resize2fs /dev/vg_webserver/lv_root 
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/vg_webserver/lv_root is mounted on /; on-line resizing required
old desc_blocks = 4, new_desc_blocks = 10
Performing an on-line resize of /dev/vg_webserver/lv_root to 39320576 (4k) blocks.
The filesystem on /dev/vg_webserver/lv_root is now 39320576 blocks long.

Yeah, It’s all. Check the result with df -h.

Leave a Reply