This page is READ-ONLY. It is generated from the old site.
All timestamps are relative to 2013 (when this page is generated).
If you are looking for TeX support, please go to VietTUG.org

restore VirtualBox.xml

Vbox... stupid :D
Added by icy almost 2 years ago  »  Votes: 1/1

My VirtualBox.xml was just empty :) It was deleted as by accident: The system account vboxweb tried to get a list of known VirtualBox guests, but it got an empty list (not sure why), then it wrote this list to the old file "VirtualBox.xml" :) Immediately after I had recognized the that file was modified, I saw that there were still some running guests. I turned them off, and restarted Virtualbox service (/etc/rc.d/vboxdrv stop), then my list of guests was really empty :)

As I noted in (blog) Virtualbox: nhân bản một máy ảo, the file "VirtualBox.xml" can be modified manually after you stop all VirtualBox modules. I get a sample file on my laptop, which contents are simple.

 1 <?xml version="1.0"?>
 2 <VirtualBox xmlns="http://www.innotek.de/VirtualBox-settings" version="1.7-linux">
 3   <Global>
 4     <MachineRegistry>
 5       <MachineEntry uuid="{68ed202d-c309-4605-aa80-892e12e74eb0}" 
 6                     src="Machines/vnmik/vnmik.xml"/>
 7     </MachineRegistry>
 8      <MediaRegistry>
 9       <HardDisks>
10         <HardDisk uuid="{e5bca669-02f1-4b6e-b002-d04d6df4b515}" 
11                   location="/home/pi/.VirtualBox/HardDisks/vnmik.vdi" 
12                   format="VDI" type="Normal"/>        
13       </HardDisks>
14       ...
15     </MediaRegistry>
16     ...
17   </Global>
18 </VirtualBox>

So... it would be really simple. All I have to do is to add new entries <MachineEntry and <HardDisk. These information can be fetched by VBoxMange from existing disk files and machine files. So I wrote two jifty scripts to do that. The first one prints out the list of machine entry, from machines' data (in XML format). The last one prints list of disks

 1 $ find /mnt/virtualbox/vmdata/Machines/ \
 2     | grep xml \
 3     | grep -v prev \
 4     | while read XML; do \
 5         ID=$(cat $XML | grep Machine | grep uuid | awk -Fuuid '{print $2}' | awk -F'"' '{print $2}'); \
 6         echo "<MachineEntry uuid=\"$ID\" src=\"$XML\" />"; \
 7       done
 8 
 9 <MachineEntry uuid="{d244c850-e1aa-4f60-9c06-ba0ef8fb1a3b}" 
10   src="/mnt/virtualbox/vmdata/Machines/web0/web0.xml" />
11 ...
 1 $ cd /mnt/virtualbox/vmdisks \
 2   && for f in *.vdi *.vmdk; do \
 3        VBoxManage showhdinfo $f > /tmp/$f.txt; \
 4        id="$(cat /tmp/$f.txt|grep ^UUID | awk '{print $2}')"; \
 5        format=$(cat /tmp/$f.txt | grep 'Storage format' | awk '{print $3}'); \
 6        echo "<HardDisk uuid=\"{$id}\" location=\"/mnt/virtualbox/vmdisks/$f\" type=\"Normal\" format=\"$format\" />"; \
 7      done
 8 
 9 <HardDisk uuid="{866eaff6-82a7-4fcc-afaf-801361c6349a}" 
10   location="/mnt/virtualbox/vmdisks/arch001.vmdk" type="Normal" format="VMDK" />
11 ...

The remained task was so simple: copy, past, reload VirtualBox modules and enjoy new VirtualBox.xml :)


Comments