Resizing the disk space on Ubuntu Server VMs running on VMware ESXi 5

Resizing the disk space on Ubuntu Server VMs running on VMware ESXi 5

We generally do both dedicated and VPS hosting for our websites, apps and some premium projects we run for others.When we choose to have VPS servers (aka virtual machines or VMs for short) instead of dedicated servers, we usually opt for VMware‘s free ESXi 5 and install Ubuntu Server as the OS for the VPSs we create on top of ESXi 5. It may not be as friendly as some VPS providers like Amazon, Rackspace etc. but you got more control and it’s on YOUR hardware (pretty important actually!)…

Now, when you build a VPS on VMware, you start with say 40GBs of hard disk space. You install the OS, setup the server, move the sites on this new server and you’re on. But what happens when there’s no more room on the server for your site or sites and you need to add more disk space?

The process is quite simple:

a) Connect to the VMware ESXi 5 server using the vShpere Client. Edit the VM’s properties to increase the hard disk size (VM has to be off) – I won’t get into details on that, if you have the experience on managing ESXi you know what to do… I’m assuming the process is the same for ESXi 4. Now restart the VM.

b) Login via SSH to the VM and follow this process.
– First list all partitions:
$ ls -al /dev/sda*

– Create new partition using fdisk:
$ fdisk /dev/sda
Then:
type p – to list all your partitions
type n – to create a new partition
type l – for “logical”
then give it a number (e.g. if you got 2 partitions listed as /dev/sda1 & /dev/sda2, for the new partition simply type “3” to create /dev/sda3)
type t – to change the partition type to “Linux LVM”
provide the partition number you previously created
type 8e – for the “Linux LVM” type
type p – to list the new partition table
type w – to write changes and exit

– Reboot server:
$ reboot

– Assuming you created partition /dev/sda3, let’s now create the physical volume in that partition:
$ pvcreate /dev/sda3

– Now let’s extend the server’s Volume Group to that physical volume.
$ vgdisplay
This will give you the info on your current Volume Group. Note down the entry next to “VG Name”. That’s your Volume Group name.
$ vgextend EnterVolumeGroupNameHere /dev/sda3

Keep in mind
If you get a message saying /dev/sda3 could not be added to your Volume Group, you need to remove the physical volume and recreate it. Metadata might have gotten corrupt and thus the volume cannot be added to your Volume Group. So just do:
$ pvremove /dev/sda3
And then again:
$ pvcreate /dev/sda3

– Since we’re (essentially) extending the main logical volume, let’s get the name of that:
$ lvdisplay
and note down the entry next to “LV Name”. This is your logical volume’s name (e.g. /dev/srv/root), which you’ll now extend to the newly added partition/physical volume.

– Extend the logical volume by X GBs:
$ lvextend -L +XG yourLogicalVolumeName
Make sure you replace X above with the actual number of GBs you’ve added in your VM’s settings. So if you increased your VM by 20GBs, the command becomes:
$ lvextend -L +20G yourLogicalVolumeName

– Finally, let’s resize the file system to the new allocated space:
$ resize2fs yourLogicalVolumeName
(this may take some time depending on number of GBs added to the file system.

– Check the new file system sizes:
$ df -hT
You should now see an increased disk space for your primary logical volume.

Advertisements

Installing VMware Tools in an Ubuntu virtual machine with only a command line interface

Ubuntu Server with only a command line interface

  1. Go to Virtual Machine > Install VMware Tools (or VM > Install VMware Tools).Note: If you are running the light version of Fusion, or a version of Workstation without VMware Tools, or VMware Player, you are prompted to download the Tools before they can be installed. Click Download Now to begin the download.
  2. In the Ubuntu guest, run these commands:
    1. Run this command to create a directory to mount the CD-ROM:sudo mkdir /mnt/cdrom

      When prompted for a password, enter your Ubuntu admin user password.

      Note: For security reasons, the typed password is not displayed. You do not need to enter your password again for the next five minutes.

    2. Run this command to mount the CD-ROM:sudo mount /dev/cdrom /mnt/cdrom or sudo mount /dev/sr0 /mnt/cdrom
    3. The file name of the VMware Tools bundle varies depending on your version of the VMware product. Run this command to find the exact name:ls /mnt/cdrom
    4. Run this command to extract the contents of the VMware Tools bundle:tar xzvf /mnt/cdrom/VMwareTools-x.x.x-xxxx.tar.gz -C /tmp/

      Note: x.x.x-xxxx is the version discovered in the previous step.

    5. Run this command to change directories into the VMware Tools distribution:cd /tmp/vmware-tools-distrib/
    6. Run this command to install VMware Tools:sudo ./vmware-install.pl -d

      Note: The -d switch assumes that you want to accept the defaults. If you do not use -d, press Return to accept each default or supply your own answers.

  3. Run this command to reboot the virtual machine after the installation completes:sudo reboot

Taken from: https://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1022525