Difference between revisions of "Resizing an Image"

From CSLabsWiki
m
m (rewrote to apply to new setup - steps need to be verified)
Line 1: Line 1:
{{ rewrite }}
+
{{ draft }}
   
This How To covers the process of resizing an image created using the steps in [[Creating an image and exporting it over AoE]].
+
This How To covers the process of resizing an image created using the steps in [[Create a New VM]].
  +
  +
All of these steps are performed on the dom0 that the VM is currently running on.
   
 
==Preparation==
 
==Preparation==
 
* Shutdown the current image
 
* Shutdown the current image
**<code>xm shutdown IMAGENAME</code> (on the Dom0)
+
**<code>xm shutdown IMAGENAME</code>
 
* Create Backup Copy
 
* Create Backup Copy
**<code>cp /mnt/raidB/xenlib/images/IMAGENAME.disk /mnt/raidB/xenlib/temp/</code> (on Animal)
+
**<code>mkdir /xen/temp</code>
  +
**<code>cp /xen/images/IMAGENAME.disk /xen/temp/</code>
* Turn Image back on (to minimize downtime)
 
**<code>xm create IMAGENAME</code> (on the Dom0)
 
   
 
==Resizing the Image==
 
==Resizing the Image==
 
* Create image of new size
 
* Create image of new size
**<code>dd if=/dev/zero of=/mnt/raidB/xenlib/temp/new_IMAGENAME.disk bs=1024k count=1 seek=NEW_SIZE_IN_MB</code> (on Animal)
+
**<code>dd if=/dev/zero of=/xen/temp/new_IMAGENAME.disk bs=1024k count=1 seek=NEW_SIZE_IN_MB</code>
 
* Partition the new image, mount the images, and copy the files, preserving permissions
 
* Partition the new image, mount the images, and copy the files, preserving permissions
 
**<code>losetup -f</code> to get next open loopback device. (the following commands assume it’s loopX)
 
**<code>losetup -f</code> to get next open loopback device. (the following commands assume it’s loopX)
**<code>losetup /dev/loopX /mnt/raidB/xenlib/temp/new_IMAGENAME.disk</code>
+
**<code>losetup /dev/loopX /xen/temp/new_IMAGENAME.disk</code>
 
**<code>losetup -f</code> to get next open loopback device. (the following commands assume it’s loopY)
 
**<code>losetup -f</code> to get next open loopback device. (the following commands assume it’s loopY)
**<code>losetup /dev/loopY /mnt/raidB/xenlib/temp/IMAGENAME.disk</code>
+
**<code>losetup /dev/loopY /xen/temp/IMAGENAME.disk</code>
**<code>fdisk /dev/loopX</code> (Create swap and root partitions. The actual commands are beyond the scope of this How To)
+
**<code>fdisk /dev/loopX</code> (Create swap and root partitions. The actual commands are beyond the scope of this How-To)
 
**<code>kpartx -av /dev/loopX</code>
 
**<code>kpartx -av /dev/loopX</code>
 
**<code>kpartx -av /dev/loopY</code>
 
**<code>kpartx -av /dev/loopY</code>
Line 36: Line 37:
   
 
==Put the new image in place==
 
==Put the new image in place==
* Shutdown the current image
 
**<code>xm shutdown IMAGENAME</code> (on the Dom0)
 
* Shutdown the vblade export
 
**<code>ps -Af | grep IMAGENAME</code> to determine process id (on Animal)
 
**<code>kill PROCESS_ID</code> to kill the process (on Animal)
 
**<code>ps -Af | grep IMAGENAME</code> to make sure it's done (on Animal)
 
 
* Move the new image into place
 
* Move the new image into place
**<code>mv /mnt/raidB/xenlib/images/{,old_}IMAGENAME.disk </code> (on Animal)
+
**<code>mv /xen/images/{,old_}IMAGENAME.disk</code>
**<code>mv /mnt/raidB/xenlib/{temp/new_,images/}imagename.disk</code> (on Animal)
+
**<code>mv /xen/{temp/new_,images/}imagename.disk</code>
* Start the vblade export
 
**<code>vbladed SHELF SLOT eth0 /mnt/raidB/xenlib/images/IMAGENAME.disk</code> (on Animal)
 
 
* Start the image
 
* Start the image
**<code>xm create /xen/IMAGENAME</code> (on the Dom0)
+
**<code>xm create /xen/confs/IMAGENAME</code>
   
 
==Cleanup==
 
==Cleanup==
 
* '''If everything works''', clean up after yourself
 
* '''If everything works''', clean up after yourself
**<code>rm -rf /mnt/raidB/xenlib/temp</code>
+
**<code>rm -rf /xen/temp</code>
**<code>rm /mnt/raidB/xenlib/images/old_IMAGENAME.disk</code>
+
**<code>rmdir /mnt/new</code>
  +
**<code>rmdir /mnt/old</code>
  +
**<code>rm /xen/images/old_IMAGENAME.disk</code>
   
==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.
 
 
[[Category:Internal How-Tos]]
 
[[Category:Internal How-Tos]]

Revision as of 13:12, 1 September 2009


This How To covers the process of resizing an image created using the steps in Create a New VM.

All of these steps are performed on the dom0 that the VM is currently running on.

Preparation

  • Shutdown the current image
    • xm shutdown IMAGENAME
  • Create Backup Copy
    • mkdir /xen/temp
    • cp /xen/images/IMAGENAME.disk /xen/temp/

Resizing the Image

  • Create image of new size
    • dd if=/dev/zero of=/xen/temp/new_IMAGENAME.disk bs=1024k count=1 seek=NEW_SIZE_IN_MB
  • 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 /xen/temp/new_IMAGENAME.disk
    • losetup -f to get next open loopback device. (the following commands assume it’s loopY)
    • losetup /dev/loopY /xen/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

  • Move the new image into place
    • mv /xen/images/{,old_}IMAGENAME.disk
    • mv /xen/{temp/new_,images/}imagename.disk
  • Start the image
    • xm create /xen/confs/IMAGENAME

Cleanup

  • If everything works, clean up after yourself
    • rm -rf /xen/temp
    • rmdir /mnt/new
    • rmdir /mnt/old
    • rm /xen/images/old_IMAGENAME.disk