Thursday, February 6, 2014

change the size of hard disk of a virtual machine on virtualbox

The virtualbox is installed on windows and the virtual machine is centos4.

In windows:
##################################################################
#VBoxManage.exe is in the directory where the virtualbox is installed
alex@alex-PC /cygdrive/c/Program Files/Oracle/VirtualBox
$ ./VBoxManage.exe modifyhd "D:\vmachine\centos4.vdi" --resize 200000
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
##################################################################

In Linux:
##################################################################
#1) use fdisk to create a new partition
[root@rcs03 sbin]# /sbin/fdisk /dev/sda
Command (m for help): p

Disk /dev/sda: 209.7 GB, 209715200000 bytes
255 heads, 63 sectors/track, 25496 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        2610    20860402+  8e  Linux LVM

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-25496, default 2611):
Using default value 2611
Last cylinder or +size or +sizeM or +sizeK (2611-25496, default 25496):
Using default value 25496

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 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.
Syncing disks.

#create the physical volume for the newly created partition
[root@rcs03 sbin]# /usr/sbin/pvcreate /dev/sda3
  Physical volume "/dev/sda3" successfully created
#add the physical volume to the logical volumen
[root@rcs03 sbin]# /usr/sbin/vgextend VolGroup00 /dev/sda3
  /dev/cdrom: open failed: Read-only file system
  /dev/cdrom: open failed: Read-only file system
  Attempt to close device '/dev/cdrom' which is not open.
  Volume group "VolGroup00" successfully extended

[root@rcs03 sbin]# df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       19G   13G  5.4G  70% /
#increase the size of the logical volume
[root@rcs03 sbin]# /usr/sbin/lvresize -L +100GB /dev/mapper/VolGroup00-LogVol00
  Extending logical volume LogVol00 to 118.88 GB
  Logical volume LogVol00 successfully resized
[root@rcs03 sbin]# df -h .
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                       19G   13G  5.4G  70% /
#need to update the logical volume size on the fly, but as the logical volume is mounted, its size cannot be updated with the cmd resize2fs.
#so need to use cmd ext2online to do this
[root@rcs03 sbin]# /sbin/resize2fs /dev/VolGroup00/LogVol00 100G
resize2fs 1.35 (28-Feb-2004)
/dev/VolGroup00/LogVol00 is mounted; can't resize a mounted filesystem!
[root@rcs03 sbin]# /usr/sbin/ext2online /dev/VolGroup00/LogVol00
ext2online v1.1.18 - 2001/03/18 for EXT2FS 0.5b
##################################################################


No comments:

Post a Comment