Gnome Boxes is gui wrapper for qemu-kvm.
Create, Resize, Rename, Backup and Recover
How to create a gnome box
Last updated 2019-09-24
- You need to install gnome_boxes.
- . Bring up gnome boxes. Click on “new”. You will need the iso for the OS you are going to install. Gnome-boxes has built-in links for some of the more popular distributions.
- Download the iso if it is not listed and save it.
- Do you have enough disk space for the new gnome-box? Keep in mind that you will want to back it up.
- Start the install, make sure the new machine has enough disk space. When it is done.close the VM.
- In gnome_boxes, right click on the properties and type over the name to rename the gnome box so you have a XML file with the short name and gnome-boxes displays the correct fqdn.
- In a terminal: cd .local/share/gnome-boxes/images
- virsh dumpxml whatever_the_current_box_name >Name.xml
- For example: ls and you see a file windows 10-2 Your new windows box was named windows 10-2. This will be hard to work with. Renaming requires a few steps.
- You type virsh dumpxml ‘windows 10-2’ > windows_10-2.xml (Notice I am dropping the space in the file name when creating the xml to make it easier to work with)
- You now have:
“.local/share/gnome-boxes/images/windows 10-2” (this is the virtual machine)
.local/share/gnome-boxes/images/windows_10-2.xml (This is the descriptors for the virtual machine)
12. cp whatever_the_current_box_name >fqdn
For example:
cp “.local/share/gnome-boxes/images/windows 10-2” .local/share/gnome-boxes/images/crashy.williamperry.com
(Hey the above command is supposed to be on one line.)
13. Now the actual image has the fully qualified domain name.
14. Use your editor to change Name.xml contents. Change all occurance of the current box name to fqdn.
For example: cp .local/share/gnome-boxes/images/windows_10-2.xml .local/share/gnome-boxes/images/crashy.xml
emacs .local/share/gnome-boxes/images/crashy.xml
change all windows 10-2 to crashy.williamperry.com
save changes and read the xml.
15. In gnome boxes delete the box. (This deletes the image and deletes the box name from gnome-boxes.
16. Finally, in a command window, type
17 virsh define name.xml
For example:
virsh define crashy.xml
18. cd .local/share/gnome-boxes/images/
delete any windows 10-2 or windows_10-2.xml
How to resize a gnome box
list the directory where gnome images are kept and find the path and name of the image. Make sure gnome-boxes is stopped and closed.
ls ~/.local/share/gnome-boxes/images
Lets say you want to add 20 gigabytes to a box whose image name is crashy-5. Now issue the following command in a terminal window:
qemu-img resize ~/.local/share/gnome-boxes/images/crashy-5 +20G
done.
How to clone a gnome box
To clone my box called crashy, I bring up gnome-boxes, Then I right click on the box name, left click on clone. It takes a few minutes, but that is all. The new box will be named crashy-2.
How to rename a gnome box
Backup the box first. (see below). This is done in two parts.
1. Rename the box i n gnome-boxes so that the name displayed to you is the one you want. Lets rename crashy-2 to mswindow10.
open gnome-boxes
right click on crashy-2
scroll to properties, left click
enter name mswindow10 in the box. This changes the display name in gnome-boxes. Use the fully qualfied domain name here.
close gnome boxes
2. To change the name of the image, you must do the following (with gnome-boxes stopped and closed.)
cd ~/.local/share/gnome-boxes/images
cp crashy-2.domain mswindow10.domain
If you do not have an xml file, create one now. Seeabove “How to create a gnome box”
cp crashy-2.xml mswindow10xml
Open gnome boxes, right click on the old crashy-2 box and then click delete.
rm crashy-2.domain (gnome boxes should have already deleted it.)
rm crashy-2.xml
edit mswindow10.xml and change all locations where crashy-2 exists to mswindow10. Check the xml file for errors, parameters, number of cpu’s etc.
virsh define mswindow10.xml
At the end of the above command, your gnome-box will be up and running under the new name.
How to backup a gnome box
create a file in your bin directory named backup-boxes.sh
#!/bin/bash
#=====================================================
#backup a gnome boxes machine (aka domain)
#
Author William Perry
# -mtime +6 mean more than 7 days ago
# -mtime -6 means less than 7 days ago
# I use -mtime -0 file updated in last 24 hrs
add the following lines:
#=====================================================
date
echo –start —
cd /home/wlperry/.local/share/gnome-boxes/images
find . -name “*com” -type f -mtime -0 > /home/wlperry/tmp/tbd.txt
sed -r ‘s:.\/::g’ /home/wlperry/tmp/tbd.txt > /home/wlperry/tmp/tbd2.txt
for item in cat /home/wlperry/tmp/tbd2.txt
do
# /home/wlperry/bin/backup-a-box.sh $item
rsync -avzr /home/wlperry/.local/share/gnome-boxes/images/$item /home/wlperry/.backup_8/
done
date
echo End of backup
chmod +x bin/backup-boxes.sh
Now create the backup-a-box.sh
!/bin/bash
#===============================================
# backup a gnome box (virsh-qemu)
#Author William Perry
#==============================================
echo BACKUP A BOX $1
cd /home/wlperry/.backup_8/
nice split -d -a 3 -b 5G /home/wlperry/.local/share/gnome-boxes/images/$1 $1_
cat $1_* >$1
rm $1_*
echo Reconstructed backed up gnome_box $1
Add a line to your normal nightly backup script for each box. /home/wlperry/bin/backup-boxes.sh crashy.williamperry.com $NOW
Make sure that all gnome-boxes are stopped and gnome-boxes is closed.
This will create a backup of crashy in the dir /home/wlperry/Boxes/
How to recover a gnome box from backup
copy both the xml and box image to:
~/.local/share/gnome-boxes/images/
virsh define <box name>.xml
ie.,
cd ~/.local/share/gnome-boxes/images/
virsh define crash-2.xml