zoukankan      html  css  js  c++  java
  • (OK) Creating VMs from an existing VDI file —— in OS X


    http://rustyisageek.blogspot.com/2011/11/creating-vms-from-existing-vdi-file.html


    Creating VMs from an existing VDI file

    We recently had a request to install VirtualBox and a custom VDI for a course. Students with little technical backgrounds needed to be able to launch and create a individual instance of an Ubuntu virtual machine.
    We did some experimentation on configuring the virtual machine with a shared VDI file and using VirtualBox snapshots, as well as shadow disk images, for saving changes. We decided the best course was to drop a copy of the entire VDI to the students Desktop and use VirtualBox's command line tool to configure them a VM.
    We stored the VDI inside a disk image and delivered it to the /Users/Shared folder of each Mac. We then had VirtualBox installed. UsingPlatypus we wrapped a script that will copy the VDI, create the VM, and start it.
    If the VDI already exists on the desktop, the VM is created and launched. If the VM is already created, then it's launched right away.
    This provides students and faculty with a simple way to launch and use the virtual machine provided to them.
    Here is the script that we use: https://github.com/rustymyers/scripts/blob/master/shell/createVBoxVM.sh

    After writing this, I got a lot of comments that we should check out Vagrant. http://vagrantup.com/
    Do your self a favor and always google what you want to do before writing something from scratch to do it!


    createVBoxVM.sh

    #!/bin/bash
    
    # Written by Rusty Myers
    # 20111108
    
    # Setup and Configure VirtualBox machine
    
    # Variables
    
    # Name of Virtual Machine to use
    VMName="BIO230WLinux"
    # Name of Disk Image that contains a VDI file.
    # In this case we have a VDI with Ubuntu pre-installed.
    VMDMGPath="/Users/Shared/2011_SEA_Linux_VM.dmg"
    # Path to install VDI to
    VDIInstall="$HOME/Desktop/"
    
    #Functions
    
    StartVM () {
    
    # $1 = Name of VM
    
    # Start the VM
    
    # Open the VirtualBox Application, Disabled
    # open /Applications/VirtualBox.app 
    
    # VBoxManage startvm gui "$1" # gui not necessary
    
    /usr/bin/VBoxManage startvm "$1"
    }
    
    GenerateVM () {
    
    # $1 = Name of VM Machine
    # $2 = Path of Disk Image with VDI
    
    # Open DMG with VM and copy to the Desktop
    
    # Mount disk image with full path
    /usr/bin/hdiutil mount -nobrowse "$2"
    
    # Set Name of Volume
    VolumeName=`/usr/bin/basename $2|/usr/bin/awk -F. '{print $1}'`
    # Set mount path of the volume
    VolumeMount=`/sbin/mount|grep 2011_SEA_Linux_VM|/usr/bin/awk '{print $3}'`
    # Set name of VDI from dmg
    VDIName=`/bin/ls $VolumeMount`
    
    # Copy VDI from disk image to Desktop if it's not there
    if [[ ! -e "$VDIInstall/$VDIName" ]]; then
    	/bin/echo "Copying system image. Please be patient..."
    	/bin/cp "$VolumeMount/$VDIName" "$VDIInstall"
    	/bin/echo "Almost done..."
    	/bin/sleep 2
    else
    	echo "VDI "$VDIName" already exists"
    fi
    # Unmount the Volume
    /usr/bin/hdiutil unmount "$VolumeMount"
    
    # Configure VBox with new Machine and Hard Disk
    
    /usr/bin/VBoxManage createvm --name "$VMName" --ostype Ubuntu --register
    
    /usr/bin/VBoxManage modifyvm "$VMName" --memory 2048 --vram 16 --usb on --audio coreaudio --acpi on --boot1 dvd --nic1 nat
    
    /usr/bin/VBoxManage storagectl "$VMName" --name "SATA Controller" --add sata
    
    /usr/bin/VBoxManage storageattach "$VMName" --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium "$VDIInstall/$VDIName"
    
    }
    
    CheckVM () {
    
    # $1 = Name of VM Machine
    
    # Check for existing VM
    if [[ `VBoxManage list vms|grep $1` ]]; then
    	# VM exists
    	StartVM "$VMName"
    else
    	# No VM here
    	GenerateVM "$VMName" "$VMDMGPath"
    	StartVM "$VMName"
    fi
    }
    
    CheckVM "$VMName"
    
    exit 0


  • 相关阅读:
    导线截面积与导线直径及其载流量之间的关系
    quartus II 自动生成testbench
    几乎每个文件里面都有 #ifdef __cplusplus extern "C" { #endif 可我没找到程序里那个地方定义了__cplusplus 啊?这又是怎么回事呢?
    jni集成第3方third party动态库libwebrtc_audio_preprocessing.so时android.mk的编写
    升级svn 到1.7
    FFmpeg编码详细流程
    FFmpeg解码详细流程
    centos 在CentOS下编译FFmpeg
    centos编译 Compiling FFmpeg on CentOS RHEL Fedora
    C语言的面向对象设计之 X264,FFMPEG 架构探讨
  • 原文地址:https://www.cnblogs.com/ztguang/p/12646252.html
Copyright © 2011-2022 走看看