Friday, April 2, 2010

How to extend LVM on VMWare Guest running Linux

Recently I found my one of virtual Linux machine which running on VMWare ESX server have run out of disk space. And after I googled the Internet, I think it's quite simple as my virtual Linux machine is running on LVM.

And I also found the following solution will also apply to any VMWare virtual machine which running Linux OS with LVM.

Expand the disk

Turn off the virtual machine that you wish to extend disk space.


You can expand the virtual disk size by entering ESX server hidden console mode or using VMware Infrastructure Client to remote manage your ESX Server. I will introduce both way here.

  1. Method One:

    Since the GUI mode is easy. Click Your VMWare Guest Machine in your remote management console from VMware Infrastructure Client. Then click "Edit Virtual Machine Settings" from "Getting Started" which is in the Right Panel. Select Hardware -> Hard Disk 1 -> Capacity - New Size (at Right Side), and then expand the Capacity to whatever size that you need. In our case, I expanded from 100GB to 200GB. Then press "OK".


  2. Method Two:

    For ESXi Server, using the following command to enter ESXi hidden console mode after press "Alt"+"F1":

    unsupported



    Then press "Enter", now enter your ESXi server root password. You should be able to successfully log into the hidden ESXi Server console.

    For ESX Server, If you press Alt-F1, you can get access to the Linux login prompt of the ESX service console and login to a command prompt.


Now enter the following command to expand the VM Disk:

vmkfstools -X 200G "Your VMDK file here"


To extend an existing Virtual Disk to 200GB.

Note:

If you are running VMware workstation product, then you can expand the virtual disk to expand the virtual disk on your Windows machine by running this command:

vmware-vdiskmanager -x 200G "My harddisk.vmdk"


After above steps, you finished preparing the extra virtual disk space. Now we can start your VMware virtual machine and open a terminal session to continue expanding your LVM.

Issue the df -k command which shows us that the logical volume is at 100% usage. We need to create a partition on /dev/sda. Type ls -al /dev/sda* which lists the existing partitions. Our new partition will be /dev/sda3.

# ls -al /dev/sda*
brw-r----- 1 root disk 8, 0 Apr 2 19:26 /dev/sda
brw-r----- 1 root disk 8, 1 Apr 2 19:26 /dev/sda1
brw-r----- 1 root disk 8, 2 Apr 2 19:26 /dev/sda2


Type fdisk /dev/sda then type n for new partition. Enter p and 3 for the partition number (in this instance, obviously enter the partition number that matches your environment.) Also accept the default First and Last cylinders. Finally type w to write table to disk and exit.

If prompted to reboot then do so to ensure that the new partition table is written. After a restart, type ls -al /dev/sda* to verify whether the new partition was created successfully.

# ls -al /dev/sda*
brw-r----- 1 root disk 8, 0 Apr 2 19:26 /dev/sda
brw-r----- 1 root disk 8, 1 Apr 2 19:26 /dev/sda1
brw-r----- 1 root disk 8, 2 Apr 2 19:26 /dev/sda2
brw-r----- 1 root disk 8, 3 Apr 2 19:26 /dev/sda3


After verification of new partition, we need to create a physical volume and add it to the volume group.

Type pvcreate /dev/sda3

[root@rhel5 ~]# pvcreate /dev/sda3
Physical volume "/dev/sda3" successfully created


Type vgextend VolGroup00 /dev/sda3

# vgextend VolGroup00 /dev/sda3
Volume group "VolGroup00" successfully extended


We need to extend the logical volume. Type vgdisplay:

# vgdisplay
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
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 99.84 GB
PE Size 32.00 MB
Total PE 3345
Alloc PE / Size 2868 / 99.88 GB
Free PE / Size 2870 / 99.97 GB
VG UUID MkluWy-e5PA-QTGN-fF7k-ZxO3-6bC7-qxfCii


Which shows that there is 99.97GB free that we can add to the volume group. To extend the volume type lvextend -L +99.97G /dev/VolGroup00/LogVol00. If you got an error message that stated that there was "Insufficient free space: 2871 extends needed but only 2870 evailable". After a quick google: Insufficient Free Extents for a Logical Volume. It seems that we needed to select a lightly smaller size. So we changed to 99GB rather than 99.97GB which solved this problem.

# lvextend -L+99G /dev/VolGroup00/LogVol00
Rounding up size to full physical extent 99 GB
Extending logical volume LogVol00 to 198 GB
Logical volume LogVol00 successfully resized


Finally we need to resize the file system by typing resize2fs /dev/VolGroup00/LogVol00.

resize2fs /dev/VolGroup00/LogVol00
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/VolGroup00/LogVol00 is mounted on /; on-line resizing required
Performing an on-line resize of /dev/VolGroup00/LogVol00 to 20101888 (4k) blocks.
The filesystem on /dev/VolGroup00/LogVol00 is now 20101888 blocks long.


Type df -k to see if the new space is available to the logical volume.

df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
1713916000 82428400 88250280 48% /
/dev/sda1 101086 24538 71329 26% /boot
tmpfs 1037744 0 1037744 0% /dev/shm


The logical volume has now been resized and now has used space of just 48%!

Thursday, April 1, 2010

How to upgrade Ubuntu Server 9.04 to 9.10 (to 10.04)

The upgrade of Ubuntu Server 9.04 to 9.10 is not as easy as I thought. I tried the a few different methods which I found from the Internet. But none of them are useful. And finally I found a way to solve the issue by myself. If you had same trouble as mine. You should read though this article.


Basically here are the steps which most peoples would refer to:

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install update-manager-core

$ sudo do-release-upgrade


But I can tell you these steps doesn't help in my case. I still got the message when I did the last step:
Checking for a new ubuntu release
No new release found


I also tried the following step:

$ sudo apt-get dist-update


Still same thing, when I typed command:
$ cat /etc/lsb-release


It still shows me, it's Jaunty version 9.04 which is not what I want:
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.04
DISTRIB_CODENAME=Jaunty
DISTRIB_DESCRIPTION="Ubuntu 9.04"


Finally I got the idea from Ubuntu Repositories. Basically you need to edit the file /etc/apt/sources.list, and change all "Jaunty" to "Karmic". Then do the following steps again:

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get dist-upgrade


After reboot, you will see your Ubuntu version is changed to Karmic version 9.10.

$ cat /etc/lsb-release


DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=9.10
DISTRIB_CODENAME=Karmic
DISTRIB_DESCRIPTION="Ubuntu 9.10"


Hope this guide will help you to upgrade your Ubuntu Server from 9.04 to 9.10 successfully.

Tips:

Using VI editor tool to replace Text "Jaunty" to "Karmic" at once:
$ vi /etc/apt/source.list

Then type the following command at the bottom of the VI editor:
:%s/karmic/lucid/g

You will see the following message:
18 substitutions on 18 lines

Now save and quit.
:wq!


Done!

Update on 2-Apr-2010:

Just checked Ubuntu Web Site, Ubuntu release Lucid (10.04) beta version is ready. So I modified the file /etc/apt/sources.list again, and replaced all "Karmic" with "Lucid". Then do the following steps:

$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get dist-upgrade


After reboot, you will see your Ubuntu version is changed to Karmic version 9.10.

$ cat /etc/lsb-release


DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=10.04
DISTRIB_CODENAME=Lucid
DISTRIB_DESCRIPTION="Ubuntu 10.04"


Comments System

Disqus Shortname