Archive for May, 2011

  1. Resizing ext3 or ext4 partition for virtual image

    Note: please backup and make sure that you have a copy of your data and virtual images, this can go wrong and I won’t be held responsible. This worked for me, and might not work for you. For ext4 please use the latest GParted.

    As I migrated from raw or qcow images, some of the partition sizes that I have to work with are not as big as they could be. So I need to resize.

    I generally give some of my hosts a 24Gb LVM virtual group each. But the image files can be as small as 2Gb – A lot of wasted space which the filesystem on the image might as well have. These instructions assume that there are only two partitions, a main partition, and a second Linux swap partition (either on an extended partition or a primary).

    First taken the image offline, then get the name of image that you wish to resize, then the disk storage items:

    ls /etc/vm/
    lvdisplay

    In my case it was “/dev/vdisk05/vm-102-disk-1″. Then you can check to see how large the volume group is set to (vgdisplay) resize:

    lvresize -L 23G /dev/vdisk05/vm-102-disk-1

    Next I mount a SystemRescueCD on the CDRom, and make sure its the first item in the boot sequence. Then boot into the system, go for the first choice in SystemRescueCD, and it will give you a rootprompt (I am VNC’ing into the system so that I can access the console as if using a physical machine):

    #Change the passwd so that you can ssh in if you need to.
    passwd
    #Start the GUI so you can run Gparted (First choice again).
    wizard

    From a command prompt do (check file system, repair, remove journal):

    1. fsck -n /dev/sda1
    2. e2fsck -f /dev/sda1
    3. tune2fs -O ^has_journal /dev/sda1

    Then do the following in the GUI:

    1. Choose CD > System > GParted
    2. Delete the swap partition as it will be the last
    3. Resize partition, leaving some space for a new swap partition
    4. Create a swap (type Linux-swap) partition twice the size of the amount of RAM you allocate to the image
    5. Click Edit > Apply all operations
    6. Close GParted

    Back on the command prompt do (repair, check file system, journal, shutdown):

    1. e2fsck -f /dev/sda1
    2. fsck -n /dev/sda1
    3. tune2fs -j /dev/sda1
    4. shutdown -h now

    Remove the CDRom device, and change the boot order back then start the Virtual machine. Issue a df -h to see if the partition has changed. It should have done!

    By timc3 on the
    May 2nd, 2011
  2. Virtual host QCow convert to LVM

    Sometimes its better to have your virtual images running directly of LVM instead of using raw or QCow formatted files. So how do we convert? Basically you have to make sure that you have a volume group, of the right size or bigger and then dd the file into a LV on that volume group:

    This should in the directory where you have the image:

    # Get the filesize of the raw image in Kilobytes.
    ls -lk
    #Create lv on vdisk05 (the VG)
    lvcreate -L 5242880K -n vm-102-disk-1 vdisk05
    #Convert from QCow to Raw
    qemu-img convert bld-ubuntu-1004-2.qcow2 -O raw bld-ubuntu-1004-2.raw
    #Copy the image into the lv:
    dd if=bld-ubuntu-1004-2.raw of=/dev/vdisk05/vm-102-disk-1

    Then change the configuration of your QEMU or whatever you are using on your virtualisation platform.

    Sorry for the briefness of the instructions, its mainly for my own benefit and if you are doing this you should really know about LVM, dd and ls.

    By timc3 on the
    May 1st, 2011