Vmware-url
Contents
- 1 what I frequently use
- 2 snapshots
- 3 ESXi 5.0
- 4 Ruby vSphere Console (RVC)
- 5 ESXi 4.1
- 5.1 command line
- 5.1.1 data stores
- 5.1.2 Get a list of all VMs on the Hypervisor
- 5.1.3 Check which Physical NICS are up
- 5.1.4 Creating a quick network connection
- 5.1.5 Create a new vmdk and add to existing VM
- 5.1.6 Check/Toggle VM power stat
- 5.1.7 Add the Physical USB Device to a VM
- 5.1.8 Register a VM to the Hypervisor
- 5.1.9 Enable SSH from the command line
- 5.1.10 Add the license to the ESXi 4.1 hypervisor
- 5.1.11 Writing output to main console
- 5.1.12 shut down esx server
- 5.1.13 reboot esx server
- 5.1.14 clone an existing vm
- 5.2 command line mixed with GUI
- 5.3 on laptop
- 5.4 some more links
- 5.1 command line
what I frequently use
vim-cmd vmsvc/getallvms
mkdir /vmfs/volumes/RAID10/yocto-bone-2
vmkfstools -i /vmfs/volumes/RAID10/yocto-bone-1/yocto-bone-1.vmdk -d thin /vmfs/volumes/RAID10/yocto-bone-2/yocto-bone-2.vmdk
Note: you need to do this against the vmname.vmdk NOT the vmname-flat.vmdk. Be forwarned.
vim-cmd vmsvc/power.getstat <number> vim-cmd vmsvc/power.on <number> vim-cmd vmsvc/power.off <number>
ft-stats -lv
snapshots
check if there are snapshots
vim-cmd vmsvc/snapshot.get $VM_ID
find number of snapshots in vm
VM_ID=17
vim-cmd vmsvc/snapshot.get $VM_ID | egrep -- '--\|-CHILD|^\|-ROOT' | wc -l
create a snapshot
vim-cmd vmsvc/snapshot.create [VmId] [snapshotName] [snapshotDescription] [includeMemory] [quiesced]
e.g.
vim-cmd vmsvc/snapshot.create $VM_ID rber-snapshot1 "renamed machine" 0 0
remove last snapshot
VM_ID=17
SNAPSHOT_COUNT=`vim-cmd vmsvc/snapshot.get $VM_ID | egrep -- '--\|-CHILD|^\|-ROOT' | wc -l`
vim-cmd vmsvc/snapshot.remove $VM_ID false $(($SNAPSHOT_COUNT-1)) 0
remove specific snapshot
VM_ID=17
vim-cmd vmsvc/snapshot.remove $VM_ID <snapshot id>
restore a snapshot
VM_ID=17 vim-cmd vmsvc/snapshot.revert $VM_ID <snapshot id> 0
BTW you can always do something like this as well:
ssh root@YOUR_VMWARE_HOST vim-cmd vmsvc/snapshot.revert VM_ID SNAPSHOT_ID 0
ESXi 5.0
add old vm
From VSphere client:
<ip address of vm> Configuration tab Storage (right click) - browse Datastore choose the disc from where you want to add the old vm browse and choose the vmx file (right click) and add to Inventory
Ruby vSphere Console (RVC)
from here
install
Do not install Ruby from apt-get it will not work and if you have already installed it the remove it:
sudo bash
apt-get --purge remove ruby-rvm
RVM is an application to manage multiple Ruby versions on a single machine. It is a helpful piece of software if you are managing multiple applications that may require different Ruby versions. Installation is fairly straight-forward and is well-documented on the RVM website. The instructions to perform a multi-user RVM install are included here.
Before starting the RVM install, you may need to install CURL if it is not already installed on the machine, do so with:
apt-get install curl
some more dependencies
apt-get install zlib1g-dev libtool curl libxslt-dev libxml2-dev sudo apt-get install libreadline-dev
Install RVM, be sure to use the command for the Multi-User Install, which is performed as follows:
curl -L get.rvm.io | bash -s stable –auto
This will install RVM to /usr/local/rvm instead of a hidden folder in your home directory, which is what occurs during a Single-User install.
The installation of RVM will create an rvm group, you should add yourself and any users that need Ruby access on the machine to this group with
sudo adduser [username] rvm
source /etc/profile
Also, you will need to add to .bashrc:
vim ~/.bashrc
and add the following line to the end
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
After you have added users, you need to log out and log back in since group memberships are only evaluated at login time.
RVM should be automatically configured for every user on the system.
To make sure everything worked, upon logging in again type the following:
type rvm | head -n1
You should see the following output:
rvm is a function
If you have access to another user account log in with that account and try the same command to ensure that all users have access to RVM.
You can also type:
rvm notes
to ensure that the rvm function is working.
If it doesn't work, you may want to attempt to source your bashrc with the following:
source .bashrc
and then perform the checks for RVM again.
Before installing Ruby through RVM, install the following packages through the package manager:
sudo apt-get install libruby1.8 libruby1.9 zlib1g-dev libssl-dev libreadline-dev build-essential libghc6-zlib-dev
Find the requirements (follow any instructions that are given):
rvm requirements
Note that whenever you upgrade RVM, always run rvm notes and rvm requirements to obtain additional details on changes to RVM.
You can list all the available Rubies for installation by typing
rvm list
Install Ruby 1.9.x (the current version is 1.9.3). This may take awhile:
rvm install ruby-1.9.3
Once installed, set this version of ruby as the default for the entire machine with
rvm use 1.9.3 --default
You can confirm this worked by typing
ruby --version
gem install rvc
gem install ffi
add rvc to your path:
vim ~/.profile
add to it:
# add path to rvc PATH="/usr/local/rvm/gems/ruby-1.9.3-p327/bin:$PATH"
If you run it now you get the following error:
root@main-1-X61s-64-bit:~# rvc /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- readline (LoadError) from /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rvc-1.7.0/lib/rvc/completion.rb:21:in `<top (required)>' from /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rvc-1.7.0/lib/rvc.rb:30:in `<top (required)>' from /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /usr/local/rvm/rubies/ruby-1.9.3-p327/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:36:in `require' from /usr/local/rvm/gems/ruby-1.9.3-p327/gems/rvc-1.7.0/bin/rvc:21:in `<top (required)>' from /usr/local/rvm/gems/ruby-1.9.3-p327/bin/rvc:19:in `load' from /usr/local/rvm/gems/ruby-1.9.3-p327/bin/rvc:19:in `<main>' from /usr/local/rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `eval' from /usr/local/rvm/gems/ruby-1.9.3-p327/bin/ruby_noexec_wrapper:14:in `<main>'
You may need to install libreadline. Once installed, you will also have to reinstall your Ruby through rvm. The process is simple, but may take awhile since you have to reinstall Ruby. Perform the following at the command line:
apt-get install libreadline-dev rvm remove 1.9.3 rvm install 1.9.3 rvm use 1.9.3 --default gem install 'rb-readline'
exit the root shell
exit
use it
rber@main-1-X61s-64-bit:~$ sudo bash [sudo] password for rber: root@main-1-X61s-64-bit:~# source /etc/profile root@main-1-X61s-64-bit:~# source ~/.bashrc root@main-1-X61s-64-bit:~# rvc Host to connect to (user@host): root@<ip-addr> password: Welcome to RVC. Try the 'help' command. VMRC is not installed. You will be unable to view virtual machine consoles. Use the vmrc.install command to install it. 0 / 1 <ip-addr>/
0 / 1 <ip-addr>/ > cd 1 /<ip-addr>> ls 0 ha-datacenter (datacenter) /<ip-addr>> ls 0/vms 0 Windows 7 Ult 64-bit: poweredOn 1 ub-12.04-i386-srv-Jenkins-master: poweredOff 2 ub-12.04-i386-srv-Jenkins-slave1: poweredOff 3 ub-12.04-i386-srv-eldk-armv5te: poweredOff 4 ub-12.04-amd64-desk-lf331: poweredOff 5 ub-12.04-i386-srv-gateone: poweredOn 6 CentOS63-64-HP: poweredOff 7 Eclipse-Ubuntu-10.10: poweredOff 8 Yocto-1.1-ARM-Ubuntu-10.10: poweredOff 9 Yocto-Ubuntu-10.10: poweredOff 10 ub-12.04-i386-srv-eldk-armv7a: poweredOff 11 ub-12.04-i386-srv-yocto-armv7a: poweredOff 12 ub-12.04-i386-desk-eldk-armv7a: poweredOn /<ip-addr> i 0 path: /<ip-addr>/ha-datacenter/vms/Windows 7 Ult 64-bit name: Windows 7 Ult 64-bit note: username/password vcenter/vcenter host: ha-datacenter/host/esxi-server-1.localdomain/esxi-server-1.localdomain tools: guestToolsRunning hostname: vcenter-PC (192.168.44.21) VC UUID: 5274983424-e842-9257-63abd-9732898173578094 power: poweredOn cpus: 1 memory: 2048 MB nics: ethernet-0: "VM Network" connected 00:0a:25:43:dd:e7 <ip-addr-1> storage: RAID10: committed=21.58 GB uncommitted=2.10 GB unshared=21.58 GB /192.168.44.20>
/192.168.44.20/ha-datacenter/datastores/RAID10/vms> vm.on 0 PowerOnVM Windows 7 Ult 64-bit: success
ESXi 4.1
command line
from: ESXi 4.1 command line awesomeness
data stores
cd /vmfs/volumes
Get a list of all VMs on the Hypervisor
~ # vim-cmd vmsvc/getallvms Vmid Name File Guest OS Version Annotation 16 Yocto-ARM-Ubuntu-10.10 [datastore1] Yocto-Ubuntu-10.10/Yocto-Ubuntu-10.10.vmx ubuntuGuest vmx-07 32 Yocto-RouterStationPro-Ubuntu-10.10 [datastore1] Yocto-RouterStationPro-Ubuntu-10/Yocto-RouterStationPro-Ubuntu-10.vmx ubuntuGuest vmx-07 48 Yocto-1.1-ARM-Ubuntu-10.10 [datastore1] Yocto-1.1-ARM-Ubuntu-10.10/Yocto-1.1-ARM-Ubuntu-10.10.vmx ubuntuGuest vmx-07 64 Eclipse-Ubuntu-10.10 [datastore1] Eclipse-Ubuntu-10.10/Eclipse-Ubuntu-10.10.vmx ubuntuGuest vmx-07 80 LF_CENTOS60_32 [datastore1] LF_CENTOS60_32/LF_CENTOS60_32.vmx rhel6Guest vmx-07 ~ #
Notice the vmid. That vmid is used in many commands that follow when you want to perform actions on individual VMs.
Check which Physical NICS are up
There are a few commands in the esxcfg-* family that are used to configure the hypervisor network. For example, if you want to see which NICs have network connections, you can use:
~ # esxcfg-nics -l Name PCI Driver Link Speed Duplex MAC Address MTU Description vmnic0 0000:02:00.00 bnx2x Up 1000Mbps Full d8:d3:85:da:f8:30 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic1 0000:02:00.01 bnx2x Down 0Mbps Half d8:d3:85:da:f8:34 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic2 0000:02:00.02 bnx2x Up 9000Mbps Full d8:d3:85:da:f8:31 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic3 0000:02:00.03 bnx2x Down 0Mbps Half d8:d3:85:da:f8:35 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic4 0000:02:00.04 bnx2x Down 0Mbps Half d8:d3:85:da:f8:32 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic5 0000:02:00.05 bnx2x Down 0Mbps Half d8:d3:85:da:f8:36 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic6 0000:02:00.06 bnx2x Down 0Mbps Half d8:d3:85:da:f8:33 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet vmnic7 0000:02:00.07 bnx2x Down 0Mbps Half d8:d3:85:da:f8:37 1500 Broadcom Corporation NetXtreme II 57711E/NC532i 10Gigabit Ethernet
Notice that only vmnic0 and vmnic2 are up. This mostly has to do with the way I configured my blades with the Flex-10 Virtual connect. (A feature of HP Blades). If I am now to configure the network, its best that I do only vmnic0 and vmnic2 since they’re the only ones that have a link. For you Linux masters out there, there’s no ‘service network status’ nor restart that you can do. It just always seems to be on.
Creating a quick network connection
Since we know vmnic2 is up, let’s make a connection to it so that we can SSH into it, or at least ping out of it:
# add vSwitch1 esxcfg-vswitch-a vSwitch1 # link vSwitch1 to vmnic2 as an uplink esxcfg-vswitch -L vmnic2 vSwitch1 # add the DATA portgroup to this switch esxcfg-vswitch -A DATA vSwtich1 # uplink DATA to vmnic2 esxcfg-vswitch -M vmnic2 -p DATA vSwitch1 # put DATA on VLAN70 esxcfg-vswitch -v 70 -p DATA vSwitch1
Create a new vmdk and add to existing VM
Here we have a VM (vmid 32 ) that we want to add a 60GB vmdk to. We run:
# create the 60GB hard drive in foo's directory vmkfstools -c 60G /vmfs/volumes/datastore1/foo/newfoo.vmdk # add the disk to foo's inventory. (The 0 and 1 is the scsi ID numbers vim-cmd vmsvc/device.diskaddexisting 32 /vmfs/volumes/datastore1/foo/newfoo.vmdk 0 1
Check/Toggle VM power stat
You can turn nodes off and on and check power status. You need to know the vmid as shown above.
get power stat:
~ # vim-cmd vmsvc/power.getstat 16 Retrieved runtime info Powered off
turn on:
~ # vim-cmd vmsvc/power.on 16 Powering on VM:
~ # vim-cmd vmsvc/power.getstat 16 Retrieved runtime info Powered on
turn off:
~ # vim-cmd vmsvc/power.off 16 Powering off VM:
~ # vim-cmd vmsvc/power.getstat 16 Retrieved runtime info Powered off
Add the Physical USB Device to a VM
If you want to add the USB device that’s plugged into the physical machine to the virtual machine with vmid 16 you can do this:
#make sure usbarbitrator is started /etc/init.d/usbarbitrator start # add to vmid 16 vim-cmd vmsvc/device.connusbdev 16 "path:1/0/0 autoclean:1"
Note that the VM should be powered off when you do this for best results.
Register a VM to the Hypervisor
If you copied all the vmx and vmdk files to an ESXi 4.1 hypervisor you can simply register them with that hypervisor and turn them on:
vim-cmd solo/registervm /vmfs/volumes/datastore1/foo/foo.vmx # then turn it on using the stuff in tip ''Check/Toggle VM power stat''!
Enable SSH from the command line
This is an easy one:
/etc/init.d/TSM-SSH start
Add the license to the ESXi 4.1 hypervisor
This came up in a few places and I already documented it in this blog, but figured I’d do it again. If you have a license and you want to add it to your hypervisor because its about to expire in 1 day you can log in and just run:
vim-cmd vimsvc/license --set XXXXX-XXXXX-XXXXX-XXXXX-XXX11
Writing output to main console
In your kickstart files, you may want to redirect output to the main console that people watch as an installation takes place. This is /dev/tty2. Therefore, if in your kickstart file you are cloning a vmdk using vmdkfstools, you can let people see how the progress is going by just piping it out. Here’s an example:
vmkfstools -i $DATASTOREREMOTE/stage/stage.vmdk -d zeroedthick $DATASTOREOTHER/new/new.vmdk | tee -a /dev/tty2
This is cool in that you’ll see the percentage points pop up as you go along. The thing to remember is that you’ll have to send some carriage return escape sequences a la echo -e “\r\n” to line things up better.
shut down esx server
When virtual machines are running, ESX/ESXi might not clear the RAID controller's cache if you shut down or reboot ESX/ESXi host.
halt
reboot esx server
When virtual machines are running, ESX/ESXi might not clear the RAID controller's cache if you shut down or reboot ESX/ESXi host
reboot -f
clone an existing vm
The vm you want to clone needs to be shut down.
mkdir /vmfs/volumes/RAID10/ub-12.04-i386-srv-Jenkins-slave2
vmkfstools -i /vmfs/volumes/RAID10/ub-12.04-i386-srv-Jenkins-slave1/ub-12.04-i386-srv-Jenkins-slave1.vmdk /vmfs/volumes/RAID10/ub-12.04-i386-srv-Jenkins-slave2/ub-12.04-i386-srv-Jenkins-slave2.vmdk
You should see:
Destination disk format: VMFS zeroedthick Cloning disk '/vmfs/volumes/RAID10/ub-12.04-i386-srv-Jenkins-slave1/ub-12.04-i386-srv-Jenkins-slave1.vmdk'... Clone: 100% done.
command line mixed with GUI
install a new vmware image
copy over a tarball:
scp Ubuntu-11-10-64.tar.gz root@192.168.42.101:/vmfs/volumes/4d1af7b7-24fc54d4-e347-1cc1de804514
unpack the tarball on ESXi server:
tar xzvf Ubuntu-11-10-64.tar.gz
fix permissions on ESXi server:
chown -R root:root Ubuntu-11-10-64
you need to clone it on ESXi server otherwise it does not seem to work:
mkdir LF-Ubuntu-11-10-64 vmkfstools -i Ubuntu-11-10-64/Ubuntu-11-10-64.vmdk LF-Ubuntu-11-10-64/LF-Ubuntu-11-10-64.vmdk
Now from VSphere just create a Virtual Machine (custom settings) and when the wizard gets to the step for hard drive(s), just say "use existing" instead of "create new", and point to the vmdk file you have in /LF-Ubuntu-11-10-64.