VMware Disk Wrangling

Disks in a VM are far more easily created and replaced on a VM than on a real machine, of course. When one is working with an SLC4 machine as a VM, however, one has to work with them in the Linux way. They are not automatically detected, mounted, or otherwise handled by Linux, and the OS will not start correctly while unknown and unconfigured disks are present.

VM disks, when created, have a maximum extent defined, but are minimally sized to preserve disk space on the host computer. When files are added, the disk expands in a way that is not easy to reverse, even when the files that expanded the disk are deleted. While VMware provides a disk resizing method inside of Linux, the process is very slow and quite inefficient - the resized disk can retain several gigabytes of extra space. This is a serious problem when packaging a VM for download.

The following is a guide for adding (and by extension, copying and removing) Linux VM disks. The principal application for this is to allow the user to add more capacity to a VM, or to shrink an existing disk by creating a new one and duplicating its contents over.

Creating a new VMware Disk

In the Settings window of the VMware VM, simply click the + and Add Hard Disk... while the VM is shut down (rather than suspended). The disk should be named something clear and useful - it is hard to sort out a series of nearly identical auto-generated HD names. Give yourself a lot of room. Not too much - 300 GB will create a 270 MB disk image even when empty - but a reasonable amount for your application.

Start the VM. During the text portion of boot, when the system is looking for hardware, it may note the lack of some disks it wants, and will stop boot to allow you to do disk configuration. If not, you need to follow these steps while logged into the VM as root.

The first step is to look for the "disks" that need formatting. Execute

ls /dev/sd*

and look for the entries (like sda, sdb, etc) that have no corresponding partition(s) - like sda1, sdb1, etc. Let's say that you have a disk entry called sdf with no partitions created. Step 1 is to create one (or more) partitions. To do so,

fdisk /dev/sdf

To see the options that fdisk allows, enter m. You will see a number of options, of which we will use three. Enter n to create a partition. For a single partition, you'll choose the defaults - when you see

Command action
    e    extended
    p    primary partition (1-4)

You'll want to enter p, and tell it to create partition 1. Hit Enter twice to choose the defaults, filling the whole disk with the partition, and the partition will be created. Now, we need to assign the system ID of the partition - enter t. Enter the code 83 - it corresponds to a linux partition. 85 is also acceptable.

Finally, we write all the changes to disk. This will format the disk, so double-check be sure you're working with the right disk! Enter w, and the changes will be committed and fdisk will end. Repeat this for all disks you have added.

Now to format the disk using the ext3 filesystem. Simply enter the command

/sbin/mkfs -t ext3 /dev/sdf1

Then to label the disk (very helpful for later addition of this disk to the /etc/fstab file), enter the following to name it (as an example) Data, to be mounted as /Data in your linux VM:

 /sbin/e2label /dev/sdf1 /Data 

If no /Data directory exists on your system, enter

mkdir /Data

Then add the following line to your /etc/fstab file:

LABEL=/data     /data     ext3    defaults     1 2

If the VM asked you to fix the disks during boot, you can now press Control-d to exit, and the system will complete boot, with the new disks mounted. If you are doing this process from a regular root login, use the command

mount -a

to mount the disks and ready them for use.

Once you have added an empty disk, you can move the data from an overexpanded disk into it, relabel the new disk, and delete the old one.

-- AldenStradling - 20 Apr 2008

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | WYSIWYG | More topic actions
Topic revision: r3 - 2008-10-08 - AnyesTaffard
 
    • Cern Search Icon Cern Search
    • TWiki Search Icon TWiki Search
    • Google Search Icon Google Search

    Main All webs login

This site is powered by the TWiki collaboration platform Powered by PerlCopyright & 2008-2019 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback