Thursday, March 19, 2015

renaming a kvm image after it's been installed

I needed to rename a  KVM vm-image and qcow2 name file. So here what I did. This quick steps can be done in less than 5mins depending if you copy the  original images or make backups.

1:  You need to shutdown the vm image in  question

virsh shutdown vmimageoldname

 Ensure it's shutdown before continuing




2A:  Now copy the actual qcow2 image file to a safe spot ( optional )

cp vm-mai.qcow2  ~kfelix/mybackup.qcow2

2B: Copy or rename the  original qcow2 image to it's new

cp vm-oldimagename.qcow2  vm-newimagename.qcow2 


3: Run the unix  md5sum on original and copy

md5sum  oldimage  newimage

4: The dump the  xml data for the oldimage

virsh dumpxml old_named > ~kfelix/myold.xml ( as seen from virsh list -all )

Now here's what it get's to be fun, you create a copy of the xml file  and undefine the old

5: cp  ~kfelix/myold.xml ~kfelix/mynew.xml

6:  You also need to undefine the old image virsh undefine old_named

7: edit the new xml ( make all changes and double check the changes name/description/uuid/image type )

8: You can now define the image using the newly crafted and edit xml file  virsh define ~kfelix/new_named.xml

9: And now finally  start the new_named image

 virsh start  newimage_name


If you try to undefine a vm with snapshots you will get this error messages. Delete all snapshots before deletion of the old image





 tip if you want to keep the old kvm vmimage around for awhile, and do not want to undefine or delete, make sure to mark it's autostart  state as disable  virsh autostart --disable vm-oldname

Ken Felix
NSE ( Network Security Expert) and Route/Switching Engineer.
kfelix  -----a----t---- socpuppets ---dot---com

    ^     ^
=(  @  0 )=
        o 
      /   \


No comments:

Post a Comment