{"id":266,"date":"2010-09-28T10:34:24","date_gmt":"2010-09-28T16:34:24","guid":{"rendered":"http:\/\/benincosa.com\/blog\/?p=266"},"modified":"2014-11-19T11:25:59","modified_gmt":"2014-11-19T17:25:59","slug":"esxi-4-1-command-line-awesomeness","status":"publish","type":"post","link":"https:\/\/benincosa.com\/?p=266","title":{"rendered":"ESXi 4.1 command line awesomeness"},"content":{"rendered":"<p>I spend a lot of time on the command line of ESXi 4.1 due to my development duties at Sumavi.\u00a0 There are quite a few things you can do on the command line that make it pretty cool to work with.\u00a0 As such, in many instances I don&#8217;t install vSphere Server nor vSphere client.\u00a0 I just log in and do my duties.\u00a0 Notice that everything I post below you can do without vSphere Server nor vSphere client.\u00a0 Let me know if these are useful to you!<\/p>\n<h2>1.\u00a0 Get a list of all VMs on the Hypervisor:<\/h2>\n<pre># vim-cmd vmsvc\/getallvms\r\nVmid\u00a0\u00a0\u00a0\u00a0 Name\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 File\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Guest OS\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Version\u00a0\u00a0 Annotation\r\n16\u00a0\u00a0\u00a0\u00a0 Vcenter1\u00a0\u00a0 [Storage1-ESX01] Vcenter1\/Vcenter1.vmx\u00a0\u00a0 windows7Server64Guest\u00a0\u00a0 vmx-07\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\n32\u00a0\u00a0\u00a0\u00a0 Vcenter\u00a0\u00a0\u00a0 [Storage1-ESX01] Vcenter\/Vcenter.vmx\u00a0\u00a0\u00a0\u00a0 winLonghorn64Guest\u00a0\u00a0\u00a0\u00a0\u00a0 vmx-07<\/pre>\n<p>Notice the vmid.\u00a0 That vmid is used in many commands that follow when you want to perform actions on individual VMs.<\/p>\n<h2>2.\u00a0 Check which Physical NICS are up<\/h2>\n<p>There are a few commands in the esxcfg-* family that are used to configure the hypervisor network.\u00a0 For example, if you want to see which NICs have network connections, you can use:<\/p>\n<pre>~ # esxcfg-nics -l\r\nName\u00a0\u00a0\u00a0 PCI\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Driver\u00a0\u00a0\u00a0\u00a0\u00a0 Link Speed\u00a0\u00a0\u00a0\u00a0 Duplex MAC Address\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 MTU\u00a0\u00a0\u00a0 Description\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \u00a0\r\nvmnic0\u00a0 0000:02:00.00 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Up\u00a0\u00a0 1000Mbps\u00a0 Full\u00a0\u00a0 d8:d3:85:da:f8:30 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic1\u00a0 0000:02:00.01 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:34 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic2\u00a0 0000:02:00.02 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Up\u00a0\u00a0 9000Mbps\u00a0 Full\u00a0\u00a0 d8:d3:85:da:f8:31 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic3\u00a0 0000:02:00.03 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:35 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic4\u00a0 0000:02:00.04 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:32 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic5\u00a0 0000:02:00.05 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:36 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic6\u00a0 0000:02:00.06 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:33 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet\r\nvmnic7\u00a0 0000:02:00.07 bnx2x\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 Down 0Mbps\u00a0\u00a0\u00a0\u00a0 Half\u00a0\u00a0 d8:d3:85:da:f8:37 1500\u00a0\u00a0 Broadcom Corporation NetXtreme II 57711E\/NC532i 10Gigabit Ethernet<\/pre>\n<p>Notice that only vmnic0 and vmnic2 are up.\u00a0 This mostly has to do with the way I configured my blades with the Flex-10 Virtual connect.\u00a0 (A feature of HP Blades).\u00a0 If I am now to configure the network, its best that I do only vmnic0 and vmnic2 since they&#8217;re the only ones that have a link.\u00a0 For you Linux masters out there, there&#8217;s no &#8216;service network status&#8217; nor restart that you can do.\u00a0 It just always seems to be on.<\/p>\n<h2>3.\u00a0 Creating a quick network connection<\/h2>\n<p>Since we know vmnic2 is up, let&#8217;s make a connection to it so that we can SSH into it, or at least ping out of it:<\/p>\n<pre># add vSwitch1\r\nesxcfg-vswitch-a vSwitch1\r\n# link vSwitch1 to vmnic2 as an uplink\r\nesxcfg-vswitch -L vmnic2 vSwitch1\r\n# add the DATA portgroup to this switch\r\nesxcfg-vswitch -A DATA vSwtich1\r\n# uplink DATA to vmnic2\r\nesxcfg-vswitch -M vmnic2 -p DATA vSwitch1\r\n# put DATA on VLAN70\r\nesxcfg-vswitch -v 70 -p DATA vSwitch1<\/pre>\n<h2>4.\u00a0 Create a new vmdk and add to existing VM<\/h2>\n<p>Here we have a VM (vmid 32 ) that we want to add a 60GB vmdk to.\u00a0 We run:<\/p>\n<pre># create the 60GB hard drive in foo's directory\r\nvmkfstools -c 60G \/vmfs\/volumes\/datastore1\/foo\/newfoo.vmdk\r\n# add the disk to foo's inventory. (The 0 and 1 is the scsi ID numbers\r\nvim-cmd vmsvc\/device.diskaddexisting 32 \/vmfs\/volumes\/datastore1\/foo\/newfoo.vmdk 0 1<\/pre>\n<h2>5.\u00a0 Check\/Toggle VM power stat<\/h2>\n<p>You can turn nodes off and on and check power status.\u00a0 You need to know the vmid as shown in #1 above:<\/p>\n<pre># get power stat\r\nvim-cmd vmsvc\/power.getstat 16\r\n# turn off\r\nvim-cmd vmsvc\/power.off 16\r\n# turn on\r\nvim-cmd vmsvc\/power.on 16<\/pre>\n<h2>6.\u00a0 Add the Physical USB Device to a VM<\/h2>\n<p>If you want to add the USB device that&#8217;s plugged into the physical machine to the virtual machine with vmid 16 you can do this:<\/p>\n<pre>#make sure usbarbitrator is started\r\n\/etc\/init.d\/usbarbitrator start\r\n# add to vmid 16\r\nvim-cmd vmsvc\/device.connusbdev 16 \"path:1\/0\/0 autoclean:1\"<\/pre>\n<p>Note that the VM should be powered off when you do this for best results.<\/p>\n<h2>7.\u00a0 Register a VM to the Hypervisor<\/h2>\n<p>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:<\/p>\n<pre>vim-cmd solo\/registervm \/vmfs\/volumes\/datastore1\/foo\/foo.vmx\r\n# then turn it on using the stuff in tip 5!<\/pre>\n<h2>8.\u00a0 Enable SSH from the command line<\/h2>\n<p>This is an easy one:<\/p>\n<pre>\/etc\/init.d\/TSM-SSH start<\/pre>\n<h2>9.\u00a0 Add the license to the ESXi 4.1 hypervisor<\/h2>\n<p>This came\u00a0 up in a few places and I already documented it in this blog, but figured I&#8217;d do it again.\u00a0 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:<\/p>\n<pre>vim-cmd vimsvc\/license --set XXXXX-XXXXX-XXXXX-XXXXX-XXX11<\/pre>\n<h2>10.\u00a0 Writing output to main console<\/h2>\n<p>In your kickstart files, you may want to redirect output to the main console that people watch as an installation takes place.\u00a0 This is \/dev\/tty2.\u00a0 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.\u00a0 Here&#8217;s an example:<\/p>\n<pre>vmkfstools -i $DATASTOREREMOTE\/stage\/stage.vmdk -d zeroedthick $DATASTOREOTHER\/new\/new.vmdk | tee -a \/dev\/tty2<\/pre>\n<p>This is cool in that you&#8217;ll see the percentage points pop up as you go along.\u00a0 The thing to remember is that you&#8217;ll have to send some carriage return escape sequences a la echo -e &#8220;\\r\\n&#8221; to line things up better.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I spend a lot of time on the command line of ESXi 4.1 due to my development duties at Sumavi.\u00a0 There are quite a few things you can do on the command line that make it pretty cool to work with.\u00a0 As such, in many instances I don&#8217;t install vSphere Server nor vSphere client.\u00a0 I&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[74,39],"tags":[97,98,87,13,981],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/266"}],"collection":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=266"}],"version-history":[{"count":5,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions"}],"predecessor-version":[{"id":2809,"href":"https:\/\/benincosa.com\/index.php?rest_route=\/wp\/v2\/posts\/266\/revisions\/2809"}],"wp:attachment":[{"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=266"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=266"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/benincosa.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=266"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}