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:

[root@webserver 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.
[root@webserver 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)

[root@webserver ~]# 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
[root@webserver ~]# lvextend -l +100%FREE /dev/vg_webserver/lv_root 
  Extending logical volume lv_root to 150.00 GiB
  Logical volume lv_root successfully resized
[root@webserver ~]# 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.

Similar Posts

  • Real IP from Amazon Load Balancers

    If you are running an EC2 instance behind an Amazon Elastic Load Balancer (ELB), you’ll find that the visitors’ IPs are hided behind the load balancer, so your application cannot get the clients’ real IPs. In fact, visitors’ original IPs are passed via a X-Forwarded-For information in the header (http://docs.aws.amazon.com/ElasticLoadBalancing/latest/DeveloperGuide/x-forwarded-headers.html), so we can easily get…

  • OwnCloud with NginX and PostgreSQL

    This quick tutorial will help you run the OwnCloud with NginX and PostgreSQL on Ubuntu 14.04. Add the necessary repo to /etc/apt/sources.list: [bash]# nginx stable deb http://nginx.org/packages/ubuntu/ trusty nginx deb-src http://nginx.org/packages/ubuntu/ trusty nginx # nginx mainline deb http://nginx.org/packages/mainline/ubuntu/ trusty nginx deb-src http://nginx.org/packages/mainline/ubuntu/ trusty nginx[/bash] Update system: [bash]apt-get update apt-get dist-upgrade[/bash] Install nginx: [bash]apt-get install nginx[/bash] Install dependencies for…

  • |

    Setting up Nginx, HHVM, and Percona for Laravel

    HHVM is an open-source virtual machine designed for executing programs written in Hack and PHP. HHVM uses a just-in-time (JIT) compilation approach to achieve superior performance while maintaining the development flexibility that PHP provides. This tutorial guides how to set up Nginx, HHVM, and Percona for Laravel Projects on Ubuntu. First, we need to update system and install essentials (and remove…

  • Install PHP 5.5 with OpCache and Google PageSpeed

    This tutorial guides step-by-step on how to install most recent/most updated versions of a regular PHP stack. This comprises PHP 5.5 with OpCache, Percona 5.6 server and Google PageSpeed for Apache HTTPD Import needed repo for PHP 5.5:[bash]rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm [/bash] Install PHP 5.5 and related softwares:[bash]yum –enablerepo=remi,remi-php55 install httpd php php-common…

Leave a Reply

Your email address will not be published. Required fields are marked *