Resizing an Image

From CSLabsWiki
Revision as of 15:34, 12 August 2009 by Mccarrms (talk | contribs)


This How To covers the process of resizing an image created using the steps in Creating an image and exporting it over AoE.

Preparation

  • Shutdown the current image
    • xm shutdown IMAGENAME (on the Dom0)
  • Create Backup Copy
    • cp /mnt/raidB/xenlib/images/IMAGENAME.disk /mnt/raidB/xenlib/temp/ (on Animal)
  • Turn Image back on (to minimize downtime)
    • xm create IMAGENAME (on the Dom0)

Resizing the Image

  • Create image of new size
    • dd if=/dev/zero of=/mnt/raidB/xenlib/temp/new_IMAGENAME.disk bs=1024k count=1 seek=NEW_SIZE_IN_MB (on Animal)
  • Partition the new image, mount the images, and copy the files, preserving permissions
    • losetup -f to get next open loopback device. (the following commands assume it’s loopX)
    • losetup /dev/loopX /mnt/raidB/xenlib/temp/new_IMAGENAME.disk
    • losetup -f to get next open loopback device. (the following commands assume it’s loopY)
    • losetup /dev/loopY /mnt/raidB/xenlib/temp/IMAGENAME.disk
    • fdisk /dev/loopX (Create swap and root partitions. The actual commands are beyond the scope of this How To)
    • kpartx -av /dev/loopX
    • kpartx -av /dev/loopY
    • mkswap /dev/mapper/loopXp1 (assumes swap partition is 1)
    • mkfs.ext3 /dev/mapper/loopXp2 (assumes root partition is 2)
    • mkdir /mnt/{old,new}
    • mount /dev/mapper/loopXp2 /mnt/new (assumes root partition is 2)
    • mount /dev/mapper/loopYp2 /mnt/old (assumes root partition is 2)
    • cp -pr /mnt/old/* /mnt/new
    • umount /mnt/new
    • umount /mnt/old
    • kpartx -d /dev/loopX
    • kpartx -d /dev/loopY
    • losetup -d /dev/loopX
    • losetup -d /dev/loopY

Put the new image in place

  • Shutdown the current image
    • xm shutdown IMAGENAME (on the Dom0)
  • Shutdown the vblade export
    • ps -Af | grep IMAGENAME to determine process id (on Animal)
    • kill PROCESS_ID to kill the process (on Animal)
    • ps -Af | grep IMAGENAME to make sure it's done (on Animal)
  • Move the new image into place
    • mv /mnt/raidB/xenlib/images/{,old_}IMAGENAME.disk (on Animal)
    • mv /mnt/raidB/xenlib/{temp/new_,images/}imagename.disk (on Animal)
  • Start the vblade export
    • vbladed SHELF SLOT eth0 /mnt/raidB/xenlib/images/IMAGENAME.disk (on Animal)
  • Start the image
    • xm create /xen/IMAGENAME (on the Dom0)

Cleanup

  • If everything works, clean up after yourself
    • rm -rf /mnt/raidB/xenlib/temp
    • rm /mnt/raidB/xenlib/images/old_IMAGENAME.disk

Notes

If you run into any issues trying to create the image after putting the new .disk in place, make sure that the AoE export has updated.