[NFBCS] deploying a virtual machine

Tod Fassl fassl.tod at gmail.com
Tue Feb 9 00:08:00 UTC 2021


If this list allows attachments, the script should be attached to this 
message. I don't know if you can just save it and run it. I mean, I 
wrote it for myself but I also wrote it to be usable by anybody. If you 
have any questions, I guess you can just ask.



On 2/5/21 8:41 AM, Tom Moore via NFBCS wrote:
> Hi,
> I would be interested in a script that will allow for running windows under
> Linux.
>
> Tom
>
> -----Original Message-----
> From: NFBCS <nfbcs-bounces at nfbnet.org> On Behalf Of Tod Fassl via NFBCS
> Sent: Thursday, February 4, 2021 8:36 PM
> To: Amelia Pellicciotti via NFBCS <nfbcs at nfbnet.org>
> Cc: Tod Fassl <fassl.tod at gmail.com>
> Subject: Re: [NFBCS] deploying a virtual machine
>
> I take it you mean you need to run Linux on a virtual machine. If you have
> to create andrun a virtual machine from a Linux distrobution, then you're in
> luck. VirtualBox for Linux might be the most accessible virtual environment
> there is. All configuration of the virtual machine can be done at a command
> prompt with VirtualBox.
>
>
> I can send you a Linux bash script that creates a virtual machine and
> installs Windows 10 on it. You need a Windows 10 installation image and a
> installation key. But it runs on a Linux machine.
>
>
> If that won't do, I suggest you look into using the VirtualBox command line
> for Windows. A quick google search found this page which seems like a good
> place to start:
>
> https://www.ghacks.net/2018/01/02/how-to-change-the-properties-of-virtualbox
> -virtual-machines/
>
>
> I really think that using the vboxmanage command is the way to go here.
> I've had a great deal of success with it in Linux.
>
>
>
> On 2/4/21 7:01 PM, Amelia Pellicciotti via NFBCS wrote:
>> Good evening everyone,
>> I am a cyber security student pursuing the 501 cert, and I am a
>> full-time screen reader user, no magnification. For a lab in my
>> course, I need to mount a virtual machine from a linux distribution,
>> and take a screenshot of its desktop once it is loaded to confirm
>> completion of the assignment. We were encouraged to do this using
>> oracle virtual box, but it has several issues with jaws and NVDA. I
>> have heard that VM ware is accessible. Then there is the matter of
>> selecting a variant  with speech capability once the drive is mounted.
>> Is that correct? Which versions have orca already included? the
>> instructor gave us a link to the Kali Linux distribution.
>> Thank you very much for your feedback, I hope all of you have a nice
>> safe, healthy and enjoyable weekend.
>>
>> _______________________________________________
>> NFBCS mailing list
>> NFBCS at nfbnet.org
>> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
>> To unsubscribe, change your list options or get your account info for
> NFBCS:
>> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/fassl.tod%40gmail.c
>> om
> _______________________________________________
> NFBCS mailing list
> NFBCS at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> To unsubscribe, change your list options or get your account info for NFBCS:
> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/tommym2006%40gmail.com
>
>
> _______________________________________________
> NFBCS mailing list
> NFBCS at nfbnet.org
> http://nfbnet.org/mailman/listinfo/nfbcs_nfbnet.org
> To unsubscribe, change your list options or get your account info for NFBCS:
> http://nfbnet.org/mailman/options/nfbcs_nfbnet.org/fassl.tod%40gmail.com
-------------- next part --------------
#!/bin/bash

function fatal_error
	{
	echo "$1"
	exit $2
	}

### MAIN ###
Self=$(basename $0)


## Set defaults for memory (4Gb), disk size 350Gb, and Mac Address ###
test -z "$Memory" && Memory=4096
test -z "$DiskSize" && DiskSize=400000
 test -z "$MacAddress" && MacAddress=080027D13CED
test -z "$NIC1" && NIC1=$(ip route get 8.8.8.8 | grep ^8.8.8.8 | cut -d' ' -f5)

### Check for the folder where virtual machines live called the "common folder" in the virtualBox docs $###
test -z "$CommonFolder" && CommonFolder="${HOME}/VirtualBox VMs"
if [ ! -d "$CommonFolder" ]; then
	Answer=yes
	if [ -z "$Force" ]; then
		echo -n "Common folder, $CommonFolder does not exist, create it? [default $Default]: "
		read Answer
	fi
	if [ "$Answer" == "Y" -o "$Answer" == "y" -o "$Answer" == "yes" ]; then
		echo "Creating common folder, $CommonFolder"
		mkdir "$CommonFolder"
	fi
fi
test ! -d "$CommonFolder" && fatal_error "Common folder, $CommonFolder, does not exist."
echo "Common folder is $CommonFolder"

### First command line parameter is VMNAME, defaults to script name ###
test -z "$VMNAME" && VMNAME=$1
if [ -z "$VMNAME" ]; then
	Default="$Self"
	if [ -z "$Force" ]; then
		echo -n "Virtual machine name [default $Default]: "
		read VMNAME
	fi
	test -z "$VMNAME" && VMNAME="$Default"
fi	
echo "Virtual machine name is $VMNAME"

### Second command line parameter is location of boot image ###
test ! -z "$2" && BootImage="$2"
if [ -z "$BootImage" ]; then
	Default="${CommonFolder}/Files/${VMNAME}.iso"
	test ! -f "$Default" && Default=none
	if [ -z "$Force" ]; then
		echo -n "Boot image? [default $Default]: "
		read BootImage
	fi
	test -z "$BootImage" && BootImage="$Default"
fi
if [ "$BootImage" == "none" ]; then
	AnswerFile="none"
else
	test ! -f "$BootImage" && fatal_error "Boot image, $BootImage, does not exist."
fi
echo "Boot image is $BootImage"

### Third command line parameter is location of answer file ###
test ! -z "$3" && AnswerFile="$3"
if [ -z "$AnswerFile" ]; then
	Default="${CommonFolder}/Files/${VMNAME}.xml"
	test ! -f "$Default" && Default=none
	if [ -z "$Force" ]; then
		echo -n "Answer file? [default $Default]: "
		read AnswerFile
	fi
	test -z "$AnswerFile" && AnswerFile="$Default"
fi
test "$AnswerFile" != "none" -a ! -f "$AnswerFile" && fatal_error "Answer file, $AnswerFile, does not exist."
echo "Answer file is $AnswerFile"

if [ "$AnswerFile" != "none" ]; then
	DisketteImage="${CommonFolder}/Files/${VMNAME}.flp"
		echo "Creating diskette image as $DisketteImage"

	TempFile="/tmp/${VMNAME}.flp"
	test -f "$TempFile" && rm -f "$TempFile"
	dd if=/dev/zero of="$TempFile" bs=512 count=2880
	mkfs.vfat -n "$VMNAME" "$TempFile"
	MountPoint=/tmp/diskette0
	test ! -d "$MountPoint" && mkdir "$MountPoint"
	sudo mount -o loop "$TempFile" "$MountPoint"
	cp "$AnswerFile" /tmp/junk; sudo cp /tmp/junk "${MountPoint}/autounattend.xml"; rm /tmp/junk
	sudo umount "$MountPoint"
	cp "$TempFile" "$DisketteImage"
fi

### Fourth command line parameter is OS type ###
test ! -z "$4" && OSType="$4"
if [ -z "$OSType" ]; then
	Okay=$(vboxmanage list ostypes | grep -ce "ID:\s*${VMNAME}")
	if [ $Okay -gt  0 ]; then
		Default="$VMNAME"
	else
		Default=None
	fi
	if [ -z "$Force" ]; then
		echo -n "OS type [default $Default]: "
		read OSType
	fi
	test -z "$OSType" && OSType="$Default"
fi
echo "OS type is $OSType"

MachineFolder="${CommonFolder}/${VMNAME}"
if [ -d "$MachineFolder" ]; then
	echo "Machine folder exists"
	Default=yes
	if [ -z "$Force" ]; then
		echo -n "Unregister existing vm? [default $Default]: "
		read Answer
	fi
	test -z "$Answer" && Answer="$Default"
	if [ "$Answer" == "Y" -o "$Answer" == "y" -o "$Answer" == "yes" ]; then
		vboxmanage unregistervm $VMNAME --delete
		rm -rf "$MachineFolder"
	fi
fi

# Create the vm
vboxmanage createvm --name "$VMNAME" --ostype "$OSType" --register
test ! -d "$MachineFolder" && fatal_error "Failed to create virtual machine, $VMNAME."

#Create a dynamic disk.
cd "$MachineFolder"
vboxmanage createhd --filename $VMNAME.vdi --size "$DiskSize"

# Add a SATA controller with the dynamic disk attached.
vboxmanage storagectl $VMNAME --name "SATA Controller" --add sata  --controller IntelAHCI
vboxmanage storageattach $VMNAME --storagectl "SATA Controller" --port 0 --device 0 --type hdd --medium $VMNAME.vdi

# Add an IDE controller anda DVD drive
vboxmanage storagectl $VMNAME --name "IDE Controller" --add ide
vboxmanage storageattach $VMNAME --storagectl "IDE Controller" --port 0 --device 0 --type dvddrive --medium "$BootImage"

# If a  diskette image with the answer file has been specified, add a floppy drive and insert the diskette
if [ ! -z "$DisketteImage" ]; then
	vboxmanage storagectl $VMNAME --name "Floppy Controller" --add floppy
	vboxmanage storageattach $VMNAME --storagectl "Floppy Controller" --port 0 --device 0 --type fdd --medium "$DisketteImage"
fi

# Misc system settings.
vboxmanage modifyvm $VMNAME --ioapic on
vboxmanage modifyvm $VMNAME --hwvirtex on
vboxmanage modifyvm $VMNAME --usb on

vboxmanage modifyvm $VMNAME --boot1 dvd --boot2 disk --boot3 net --boot4 none
vboxmanage modifyvm $VMNAME --memory "$Memory" --vram 256
vboxmanage modifyvm $VMNAME --nic1 bridged --bridgeadapter1 "$NIC1"
test ! -z "$MacAddress" && vboxmanage modifyvm $VMNAME --macaddress1 "$MacAddress"

### Add a sound card. Seems as if these setting change with ever virtualBox and/or Windows version.
#vboxmanage modifyvm $VMNAME --audiocontroller sb16 --audiocodec sb16
#vboxmanage modifyvm $VMNAME --audio pulse --audiocontroller sb16 --audiocodec sb16
#vboxmanage modifyvm $VMNAME --audio alsa --audiocontroller ac97
vboxmanage modifyvm $VMNAME --audio pulse --audiocontroller hda
vboxmanage modifyvm $VMNAME --audioout on
vboxmanage modifyvm $VMNAME --audioin on

# Boot it up! If you’ve done this on a remote machine, you can RDP to the console via vboxhost:3389.
vboxmanage startvm $VMNAME
### Some useful commands
# VBoxHeadless -s $VMNAME
# vboxmanage showvminfo $VMNAME
#vboxmanage getextradata global GUI/Input/HostKeyCombination
# vboxmanage setextradata global GUI/Input/HostKeyCombination 65300
#vboxmanage snapshot $VMNAME take snapshot`date +"%F"` --description "Snapshot, "`date`
# ###
# To mount the virtual disk:
# sudo modprobe nbd max_part=8
#sudo qemu-nbd -c /dev/nbd0 "/staff/jheim/VirtualBox VMs/$VMNAME/$VMNAME.vdi"
# sudo mount /dev/nbd0p2 /mnt/vdi
# ###
# EOF


More information about the NFBCS mailing list