summaryrefslogtreecommitdiffstats
path: root/os-plugins/plugins/virtualbox
diff options
context:
space:
mode:
authorMichael Janczyk2010-03-25 18:33:20 +0100
committerMichael Janczyk2010-03-25 18:33:20 +0100
commit05d263fe3e313bde1c3da2fa67237df894971d43 (patch)
treece66520706d9b0c4362a308788d418bca62c139c /os-plugins/plugins/virtualbox
parentnew run-virt.include for xen plugin. qemukvm modules now loaded via runlevels... (diff)
downloadcore-05d263fe3e313bde1c3da2fa67237df894971d43.tar.gz
core-05d263fe3e313bde1c3da2fa67237df894971d43.tar.xz
core-05d263fe3e313bde1c3da2fa67237df894971d43.zip
added support for rw disks and netboot
Diffstat (limited to 'os-plugins/plugins/virtualbox')
-rw-r--r--os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm2
-rw-r--r--os-plugins/plugins/virtualbox/XX_virtualbox.sh30
-rw-r--r--os-plugins/plugins/virtualbox/files/machine.include4
-rw-r--r--os-plugins/plugins/virtualbox/files/run-virt.include86
-rw-r--r--os-plugins/plugins/virtualbox/files/rwimg.vdi.gzbin0 -> 268 bytes
5 files changed, 95 insertions, 27 deletions
diff --git a/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm b/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm
index 26a2d926..be7f2cb5 100644
--- a/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm
+++ b/os-plugins/plugins/virtualbox/OpenSLX/OSPlugin/virtualbox.pm
@@ -132,7 +132,7 @@ sub installationPhase
my $pluginBasePath =
"$self->{openslxBasePath}/lib/plugins/$pluginName/files";
foreach my $file ( qw( run-virt.include virtualbox.include machine.include
- empty-diff*.vdi.gz ) ) {
+ empty-diff.vdi.gz rwimg.vdi.gz ) ) {
copyFile("$pluginBasePath/$file", "$self->{pluginRepositoryPath}/");
chmod 0755, "$self->{pluginRepositoryPath}/$file";
}
diff --git a/os-plugins/plugins/virtualbox/XX_virtualbox.sh b/os-plugins/plugins/virtualbox/XX_virtualbox.sh
index 998dabd7..4599b197 100644
--- a/os-plugins/plugins/virtualbox/XX_virtualbox.sh
+++ b/os-plugins/plugins/virtualbox/XX_virtualbox.sh
@@ -18,7 +18,6 @@ CONFFILE=/initramfs/plugin-conf/virtualbox.conf
PLUGINCONFDIR=/mnt/${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualbox
PLUGINDIR=/mnt/${OPENSLX_DEFAULT_DIR}/plugin-repo/virtualbox
VIRTDIR=/mnt/${OPENSLX_DEFAULT_VIRTDIR}/virtualbox
-LOGDIR=/mnt/${OPENSLX_DEFAULT_LOGDIR}
# check if the configuration file is available
if [ -e ${CONFFILE} ]; then
@@ -46,14 +45,39 @@ if [ -e ${CONFFILE} ]; then
# mount the virtualbox image source readonly (ro)
fsmount ${vbimgprot} ${vbimgserv} ${vbimgpath} ${mnttarget} ro
else
- [ $DEBUGLEVEL -gt 1 ] && error " * Incomplete information in variable \
-${virtualbox_imagesrc}." nonfatal
+ [ $DEBUGLEVEL -gt 1 ] && \
+ error " * Incomplete information in variable ${virtualbox_imagesrc}." \
+ nonfatal
fi
+
# copy virtualization include files to config dir
testmkd ${PLUGINCONFDIR}
cp ${PLUGINDIR}/*.include ${PLUGINCONFDIR}
# copy ${CONFFILE} to ${PLUGINCONFDIR} just in case
cp ${CONFFILE} ${PLUGINCONFDIR}
+
+# # TODO: create rawdisk if requested
+# # create raw disk
+# for part in $(grep -qE " 44 | 45 " /etc/disk.partition); do
+# case "${part}" in
+# * 45 *)
+# id4x=$(grep " 45 " /etc/disk.partition | grep -E " 44 | 45 " \
+# | awk '{print $1}' | cut -c -8)
+# break
+# ;;
+# * 44 *)
+# id4x=$(grep " 44 " /etc/disk.partition | grep -E " 44 | 45 " \
+# | awk '{print $1}' | cut -c -8)
+# break
+# ;;
+# esac
+# if [ -n "${id4x}" ]; then
+# mount --bind /dev /mnt/dev
+# chroot /mnt VBoxManage -q internalcommands createrawvmdk -filename \
+# ${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualbox/raw.vmdk -rawdisk ${id4x}
+# chmod 777 ${OPENSLX_DEFAULT_CONFDIR}/plugins/virtualbox/raw.vmdk
+# umount -f /mnt/dev 2>/dev/null
+# fi
# copy and activate init file
cp ${PLUGINDIR}/vbox-slx /mnt/etc/init.d/
diff --git a/os-plugins/plugins/virtualbox/files/machine.include b/os-plugins/plugins/virtualbox/files/machine.include
index 6496b616..e11f95c5 100644
--- a/os-plugins/plugins/virtualbox/files/machine.include
+++ b/os-plugins/plugins/virtualbox/files/machine.include
@@ -22,7 +22,7 @@ cat <<EOF
</CPU>
<Memory RAMSize="${mem}"/>
<Boot>
- <Order position="1" device="HardDisk"/> <!-- DVD, Network, Floppy -->
+ <Order position="1" device="${boot}"/> <!-- HardDisk, DVD, Network, Floppy -->
<Order position="2" device="None"/>
<Order position="3" device="None"/>
<Order position="4" device="None"/>
@@ -61,7 +61,7 @@ cat <<EOF
</LPT>
<AudioAdapter controller="AC97" driver="Alsa" enabled="true"/> <!-- OSS, Alsa, Pulse (HANGS!) -->
<SharedFolders>
- <SharedFolder name="home" hostPath="/home/${USER}" writable="true"/>
+ <SharedFolder name="${sharename}" hostPath="${sharepath}" writable="true"/>
</SharedFolders>
<Clipboard mode="Bidirectional"/>
<Guest memoryBalloonSize="0" statisticsUpdateInterval="0"/>
diff --git a/os-plugins/plugins/virtualbox/files/run-virt.include b/os-plugins/plugins/virtualbox/files/run-virt.include
index e3650ebd..11f8d0eb 100644
--- a/os-plugins/plugins/virtualbox/files/run-virt.include
+++ b/os-plugins/plugins/virtualbox/files/run-virt.include
@@ -32,21 +32,35 @@ fi
PLUGINCONFVIRTUALBOX="${PLUGINCONFROOT}/${self}"
# create TMPDIR for all users
-mkdir -m 1777 /tmp/${self} 2>/dev/null
+TMPDIR=/tmp/${self}
+mkdir -m 1777 ${TMPDIR} 2>/dev/null
# dir for configs
confdir="/tmp/${self}/${USER}/${VM_ID}"
# use alternate configuration directory instead of $HOME/.VirtualBox
export VBOX_USER_HOME=${confdir}
# define dirs and files which can be removed after exit, be carefull!
-RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc" 2>/dev/null
+RMDIRS="${snapshotdir} ${confdir} /tmp/.vbox-${USER}-ipc"
rm -rf ${RMDIRS} 2>/dev/null
-machfolder="${VBOX_USER_HOME}/Machines"
+machfolder="${confdir}/Machines"
# use vm_shortname for VM name since vm_name can be very long
machconfig="${machfolder}/${vm_shortname}/${vm_shortname}.xml"
-diskfolder="${VBOX_USER_HOME}/HardDisks"
+diskfolder="${confdir}/HardDisks"
snapshotdir=${machfolder}/${vm_shortname}/Snapshots
-diskfile="${diskfolder}/${imgname}"
mkdir -p ${diskfolder} ${snapshotdir} 2>/dev/null
+
+# configure rwimg
+if [ "${imgmode}" = "rwimg" ] && ! [ -e "${vmpath}" ]; then
+ # what is our rwimg called?
+ imgname="${imgname}.vdi"
+ vmpath=${imgpath}/${imgname}
+ cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/rwimg.vdi.gz \
+ | gunzip > "${vmpath}"
+ # static rw share image uuid
+ #rwimguuid="ab20cb01-2d08-4d73-a33c-5594c5d0b8cb"
+fi
+
+# link to image
+diskfile="${diskfolder}/${imgname}"
ln -sf ${vmpath} ${diskfile}
# check the file type
@@ -91,9 +105,9 @@ macaddr=$(echo ${macaddr} | sed 's/://g')
machineuuid="00000000-0000-0000-0000-${macaddr}"
# cosmetical, since UUID in lower case
machineuuid=$(echo ${machineuuid} | tr [A-Z] [a-z])
-# get UUID of VBox image
-diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID | \
- awk '{print $2}')
+# get UUID of VBox image, only if rwimg.vdi not used
+diskuuid=$(VBoxManage -q showvdiinfo ${diskfile} | grep UUID \
+ | awk '{print $2}')
# snapshot UUID is static
snapshotuuid="88bc8b6d-f248-468a-95fe-318084904f8b"
@@ -188,6 +202,21 @@ cdrom1=${cdtest:-"FALSE"}
ide="TRUE"
hddrv="ide"
+# translate boot, use if set else set to HardDisk
+if [ -n "${boot}" ]; then
+ case ${boot} in
+ n*) # usually support for a,c,d,n, stands for Floppy, HD, CD-ROM, Network
+ boot="Network"
+ ;;
+ # later maybe c|disk|hd*|sd*) for HD and d|cd*) for CD-ROM
+ *)
+ boot="HardDisk"
+ ;;
+ esac
+else
+ boot="HardDisk"
+fi
+
writelog "\tSnapshots dir:\t\t$snapshotdir"
writelog "Diskimage:"
writelog "\tDisk type:\t\t$imgtype"
@@ -203,13 +232,15 @@ writelog "\tGuest RAM:\t\t${mem} MB"
writelog "\tMAC address:\t\t$macaddr"
writelog "\tNetwork card:\t\t${vb_network_card}"
writelog "\tNetwork kind:\t\t${network_kind}"
+writelog "\tBooting from:\t\t${boot}"
# TODO: server start activate via xml, etc...
#writelog "\tGuest VRDP port:\t${vrdpport}"
#writelog "\tCD-ROM1:\t${cdrom0}"
#writelog "\tCD-ROM2:\t${cdrom1}"
#writelog "\tFloppy_A:\t${floppy0}"
#writelog "\tFloppy_B:\t${floppy1}"
-writelog "\tShared Folders 'home':\t/home/${USER}"
+# defined in run-virt.sh and run-vmgrid.sh
+writelog "\tShared Folders '${sharename}':\t${sharepath}"
################################################################################
### Pepare and configure virtual machine and disk image
@@ -217,20 +248,33 @@ writelog "\tShared Folders 'home':\t/home/${USER}"
# TODO: date wichtig?
#date="$(date +%Y-%m-%dT%H:%M:%SZ)"
-. ${PLUGINCONFVIRTUALBOX}/virtualbox.include >"${VBOX_USER_HOME}/VirtualBox.xml"
+. ${PLUGINCONFVIRTUALBOX}/virtualbox.include > "${confdir}/VirtualBox.xml"
+
+# remove disk and add rwimg if set
+if echo "${imgmode}" | grep -q rw; then
+ if [ -e "${vmpath}.lock" ]; then
+ writelog "This rw image is already in use: ${vmpath}, exiting!"
+ writelog "Remove lock if you are shure that this is not the case"
+ exit 1
+ fi
+ # add lock
+ touch "${vmpath}.lock"
+ # remove lock after VM stopped
+ RMDIRS="${RMDIRS} ${vmpath}.lock"
+ rwimghd="<HardDisk uuid=\"{${diskuuid}}\" location=\"${diskfile}\""
+ rwimghd="${rwimghd} format=\"VDI\" type=\"Normal\"/>"
+ sed -i "/<HardDisk uuid/d;s,</HardDisk>,${rwimghd}," \
+ "${confdir}/VirtualBox.xml"
+ # replace image uuid in machine config
+ snapshotuuid=${diskuuid}
+fi
+
+# TODO: add rawdisk if requested
+#"raw.vmdk" format="VMDK" type="Writethrough"/>
# shortened date YYYY-MM-DD
#date=${date%T*}
-. ${PLUGINCONFVIRTUALBOX}/machine.include >"${machconfig}"
-
-# add rw share to vm, if existing
-if [ -n "${rwshare}" ]; then
- sharedf='<SharedFolder name="share"'
- sharedf="${sharedf} hostPath=\"${rwshare}\" writable=\"true\"/>"
- sed -i "s,</SharedFolders>, ${sharedf}\n </SharedFolders>," \
- "${machconfig}"
- writelog "\tShared Folders 'share':\t${rwshare}"
-fi
+. ${PLUGINCONFVIRTUALBOX}/machine.include > "${machconfig}"
# add ssh port if linux and NAT
if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
@@ -247,7 +291,7 @@ if [ "${vmostype}" = "Linux26" ] && [ "${network_kind}" = "NAT" ]; then
writelog "\tGuest SSH port:\t\t${vmsshport}"
fi
-cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/virtualbox/empty-diff.vdi.gz | \
+cat ${OPENSLX_DEFAULT_DIR}/plugin-repo/${self}/empty-diff.vdi.gz | \
gunzip > "${snapshotdir}/{${snapshotuuid}}.vdi"
################################################################################
diff --git a/os-plugins/plugins/virtualbox/files/rwimg.vdi.gz b/os-plugins/plugins/virtualbox/files/rwimg.vdi.gz
new file mode 100644
index 00000000..e2133d6d
--- /dev/null
+++ b/os-plugins/plugins/virtualbox/files/rwimg.vdi.gz
Binary files differ