In diesem Artikel wird ein Skript vorgestellt, dass das automatische Konvertieren von VMware-Images zu für XEN lesbare Images ermöglicht.
#!/bin/bash # Copyright by Michael Mayer # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation, either version 3 of the License, or # (at your option) any later version. # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. if [ $# -ne 2 ]; then echo "Fehler! Falsche Parameteranzahl" echo " vmdk2xen.sh <vmdk-file> <img-file>" exit 0 fi if [ ! -e $1 ]; then echo "ABBRUCH! Das VM-Ware Image konnte nicht gefunden werden." exit 1 fi rawFILE=vmdk2raw.raw echo "Konvertiere VM-Ware-Image in virtuelles Laufwerk für XEN" echo " Erstelle RAW-Datei ..." if [ -e $rawFILE ]; then echo "Temporäre Datei vmdk2raw.raw existiert bereits!" echo -n "Soll die vorhandene Datei überschreiben werden? (j/n) " read answere if [ ! $answere = j ]; then echo "Konvertierung abgebrochen!" exit 0 fi fi # erstelle .raw-Image qemu-img convert $1 $rawFILE # Disk-Informationen auslesen: fdisk -lu $rawFILE 2> /dev/null | grep ^$rawFILE > /tmp/vmdk2xen # Partition aus dem Image auswählen: echo echo " Welche Partition soll für XEN konvertiert werden? " cat -b /tmp/vmdk2xen echo echo -n " Bitte eine Nummer angeben: " read partID # Blockgrenzen der Partition feststellen: bootable=`awk ' NR == "'"$partID"'" { print $2 } ' /tmp/vmdk2xen` if [ "$bootable" = '*' ]; then partSTART=`awk ' NR == "'"$partID"'" { print $3 }' /tmp/vmdk2xen` partEND=`awk ' NR == "'"$partID"'" { print $4 }' /tmp/vmdk2xen` else partSTART=`awk ' NR == "'"$partID"'" { print $2 }' /tmp/vmdk2xen` partEND=`awk ' NR == "'"$partID"'" { print $3 }' /tmp/vmdk2xen` fi rm /tmp/vmdk2xen let partCOUNT=$partEND-$partSTART+1 # Kopiere Partition in .img-Datei: echo " Erstelle IMG-Datei ..." dd if=$rawFILE of=$2 bs=512 skip=$partSTART count=$partCOUNT rm $rawFILE # Überprüfen der IMG-Datei: mount -o loop $2 /mnt if [ $? -eq 0 ]; then echo "Die Erstellung des XEN-Images war erfolgreich!" umount /mnt else echo "FEHLER! Beim einbinden des XEN-Images ist ein Fehler aufgetreten." fi
Diskussion