Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Vmware Command Line


Published on

Published in: Technology
  • Be the first to comment

Vmware Command Line

  1. 1. ESX Server from the Command Line <ul><li>The command-line environment </li></ul><ul><li>Working with disks </li></ul><ul><li>Working with virtual machines </li></ul>
  2. 2. Tips for command-line use <ul><li>Install an ssh (Secure Shell) client on your desktop </li></ul><ul><ul><li>Windows: PuTTY (freeware), SecureCRT (commercial) </li></ul></ul><ul><li>Know the features of the bash shell </li></ul><ul><ul><li>Use arrow keys to navigate command history </li></ul></ul><ul><ul><li>Use TAB to complete file names and commands </li></ul></ul><ul><ul><li>Useful keystrokes: </li></ul></ul><ul><ul><ul><li>ctrl- A : beginning of line ctrl- E : end of line </li></ul></ul></ul><ul><ul><ul><li>ctrl- W : erase previous word ctrl- U : blank this line </li></ul></ul></ul><ul><ul><ul><li>ctrl- Z : suspend this job </li></ul></ul></ul><ul><ul><li>bg command puts suspended job in background </li></ul></ul><ul><ul><li>Caution! ctrl- S freezes the screen; use ctrl- Q to unfreeze </li></ul></ul>
  3. 3. Useful Service Console add-on packages <ul><li>nano : a simple text editor </li></ul><ul><ul><li>An alternative to vi </li></ul></ul><ul><ul><li>Always invoke as nano –w filename to turn off word-wrap </li></ul></ul><ul><li>lynx : a text-only Web browser </li></ul><ul><ul><li>Especially useful for downloading files from Web sites to Service Console </li></ul></ul><ul><li>ncftp : an enhanced text-only FTP client </li></ul><ul><ul><li>Contains ncftpget , useful for unattended FTP downloads </li></ul></ul><ul><li>lsof : list open files </li></ul><ul><ul><li>Shows what processes are using what files and ports </li></ul></ul>
  4. 4. Working with Service Console packages <ul><li>rpm –qa : list installed packages </li></ul><ul><li>rpm –qi packagename : get more information about a package </li></ul><ul><li>rpm –ql packagename : list files composing a package </li></ul><ul><li>rpm –Uvh filename(s) : install a package </li></ul><ul><ul><li>You may need to satisfy a package’s dependencies; list multiple package filenames on command line </li></ul></ul><ul><li>rpm –e packagename : uninstalls a package </li></ul><ul><ul><li>Warning: do not uninstall VMware packages! </li></ul></ul>Or use –p packagefilename in place of packagename
  5. 5. Partitioning disks with fdisk <ul><li>fdisk requires a device file pointing at desired disk fdisk /dev/sdb </li></ul><ul><ul><li>Enter p to print the present partition table </li></ul></ul><ul><ul><li>Enter n to create a new partition </li></ul></ul><ul><ul><ul><li>Specify partition number if primary </li></ul></ul></ul><ul><ul><ul><li>Specify starting cylinder </li></ul></ul></ul><ul><ul><ul><li>Specify size: +1024M gives a 1 GB partition </li></ul></ul></ul><ul><ul><li>Enter t to change the partition type: FB for VMFS </li></ul></ul><ul><ul><li>Enter w to save partition table to disk </li></ul></ul><ul><li>Warning: Changing partition table of a disk with mounted Linux file systems may require reboot </li></ul>
  6. 6. vmkfstools Syntax <ul><li>The option flag governs the action of the command </li></ul><ul><ul><li>Either a single letter with one hyphen or a word with two </li></ul></ul><ul><li>The last argument is always a path using the VMkernel’s device space </li></ul><ul><ul><li>Either a VMFS name (physical or friendly) vmhba0:1:0:5 /vmfs/vmhba0:1:0:5 myvmfs /vmfs/myvmfs </li></ul></ul><ul><ul><li>Or a VMFS name followed by a virtual disk file name vmhba0:1:0:5:a.dsk /vmfs/vmhba0:1:0:5/a.dsk myvmfs:a.dsk /vmfs/myvmfs/a.dsk </li></ul></ul>vmkfstools -? [ otherarg otherarg … ] VMkernel-path
  7. 7. Creating a new VMFS volume <ul><li>Use vmkfstools –N to map from VMkernel disk to a Linux device file /dev/vsd n # vmkfstools –N vmhba0:8:0:0 /dev/vsd0 </li></ul><ul><li>fdisk /dev/vsd0 Make a partition number 1 with type FB </li></ul><ul><li>Make new VMFS volumes using MUI or command line </li></ul>Whole disk
  8. 8. Creating a new VMFS volume (cont’d) <ul><li>Use vmkfstools –C to build a new VMFS vmkfstools –C vmfs2 vmhba0:8:0:1 </li></ul><ul><li>Use vmkfstools –S to set the volume label vmkfstools –S VOL3 vmhba0:8:0:1 </li></ul><ul><li>Use vmkfstools –l to list contents vmkfstools –l VOL3 or ls –l /vmfs/VOL3 </li></ul>
  9. 9. Basic VMFS virtual-disk operations <ul><li>To create a new virtual disk: vmkfstools –c 4096m VOL3:webserver.dsk </li></ul><ul><li>To set access rights: chown ted:finance /vmfs/VOL3/webserver.dsk chmod u=rw,go= /vmfs/VOL3/webserver.dsk </li></ul><ul><li>To rename a virtual disk mv /vmfs/VOL3/ws.dsk /vmfs/VOL3/webserver.dsk </li></ul><ul><li>To remove a virtual disk rm /vmfs/VOL3/ws.dsk </li></ul>
  10. 10. Copying a virtual disk <ul><li>It’s safe to use the Service Console’s cp command on > 2 GB virtual disks </li></ul><ul><li>Not all Service Console utilities have been customized </li></ul><ul><li>Other environments may contain unsafe tools too </li></ul><ul><li>Safest to handle virtual disks in their exported (“COW”) format </li></ul><ul><ul><li>To export: vmkfstools –e /vmimages/ws.vmdk vmfs3:ws.dsk </li></ul></ul>
  11. 11. Copying a virtual disk from one ESX Server to another <ul><li>Use scp to copy securely scp /vmfs/VOL3/ws.dsk  user @esx2:/vmfs/myvmfs/ws.dsk </li></ul><ul><li>Always check for integrity # sum /vmfs/myvmfs/ws.dsk 39678 489473 /vmfs/myvmfs/ws.dsk # md5sum /vmfs/myvmfs/router-2.1.dsk 77dfc2ba10c75b6ad0a1812805887e28 router-2.1.dsk </li></ul>16-bit checksum size in 1 KB blocks
  12. 12. Extending a virtual disk <ul><li>Make a backup first! </li></ul><ul><li>Extend the virtual disk vmkfstools –X 4096M VOL3:windata.dsk </li></ul><ul><li>Now the file system inside the virtual disk does not fill the medium </li></ul><ul><li>Use Partition Magic or the equivalent inside the VM to extend the file system </li></ul>
  13. 13. Inspecting virtual disks from Service Console <ul><li>To identify a virtual disk: # head mydisk.dsk | file – </li></ul><ul><li>To import: vmkfstools –i /vmimages/otherdisk.dsk VOL3:other.dsk </li></ul><ul><ul><li>GSX Server 2.x virtual disks can also be imported </li></ul></ul>{nothing} Workstation 3.x GSX Server 2.x ASCII English text Workstation 4 x86 boot sector ESX Server
  14. 14. Opening virtual disks from Service Console <ul><li>To display the partition table inside a virtual disk: # –p /vmfs/VOL3/w2k.dsk Nr Start Size Type Id System -- ----- ------- ---- --- --------------- 1 63 4176837 BIOS 7 HPFS/NTFS # –p /vmfs/VOL3/linux.dsk Nr Start Size Type Id System -- ----- ------- ---- --- --------------- 1 32 81888 BIOS 83 Linux 2 81920 262144 BIOS 82 Linux swap 3 344064 972800 BIOS 83 Linux </li></ul><ul><ul><li>Virtual disk must be in ESX format, reside in a VMFS, not powered on </li></ul></ul>
  15. 15. Opening virtual disks from Service Console (cont’d) <ul><li>You may mount file systems from within a virtual disk onto the Service Console </li></ul><ul><ul><li>Virtual disk must not be powered on </li></ul></ul><ul><ul><li>NTFS file systems are read-only! </li></ul></ul><ul><ul><ul><li>vfat and ext3 file systems may be mounted read-write </li></ul></ul></ul><ul><li>Press ctrl- C to kill when done </li></ul># mkdir /myntfs # /vmfs/ted/w2k.dsk 1  -t ntfs -o ro /myntfs In another window: # ls /myntfs AUTOEXEC.BAT CONFIG.SYS IO.SYS boot.ini Documents and Settings MSDOS.SYS
  16. 16. VM Configuration File Syntax <ul><li>Comments begin with a # character </li></ul><ul><ul><li>Blank lines are allowed </li></ul></ul><ul><li>Each other line is of the form attribute = value or class.attribute = value </li></ul><ul><li>Class can be: </li></ul><ul><ul><li>A family of related items </li></ul></ul><ul><ul><li>A device controller </li></ul></ul><ul><ul><li>A device on a device controller </li></ul></ul>
  17. 17. A sample configuration file <ul><li>config.version = &quot;6&quot; </li></ul><ul><li>virtualHW.version = &quot;3&quot; </li></ul><ul><li>memSize = &quot;192&quot; </li></ul><ul><li>numvcpus = &quot;2&quot; </li></ul><ul><li>displayName = &quot;Controller for domain TEXAS.ORG&quot; </li></ul><ul><li>guestOS = &quot;win2000Serv&quot; </li></ul><ul><li>ide1:0.present = &quot;TRUE&quot; </li></ul><ul><li>ide1:0.startConnected = &quot;TRUE&quot; </li></ul><ul><li>ide1:0.deviceType = &quot;atapi-cdrom&quot; </li></ul><ul><li>ide1:0.fileName = &quot;/dev/cdrom&quot; </li></ul><ul><li>floppy0.present = &quot;TRUE&quot; </li></ul><ul><li>floppy0.startConnected = &quot;FALSE&quot; </li></ul><ul><li>floppy0.fileName = &quot;/dev/fd0&quot; </li></ul><ul><li>scsi0.present = &quot;TRUE&quot; </li></ul><ul><li>scsi0.virtualDev = &quot;vmxbuslogic&quot; </li></ul><ul><li>scsi0.sharedBus = &quot;none&quot; </li></ul><ul><li>scsi0:0.present = &quot;TRUE&quot; </li></ul><ul><li>scsi0:0.fileName = “VOL3:winnt.dsk&quot; </li></ul><ul><li>scsi0:0.mode = &quot;persistent&quot; </li></ul>
  18. 18. A sample configuration file (cont’d) <ul><li>ethernet0.present = &quot;TRUE&quot; </li></ul><ul><li>ethernet0.virtualDev = &quot;vlance&quot; </li></ul><ul><li>ethernet0.connectionType = &quot;monitor_dev&quot; </li></ul><ul><li>ethernet0.devName = &quot;vmnic0&quot; </li></ul><ul><li> = &quot;/vmfs/VOL3&quot; </li></ul><ul><li>remotedisplay.depth = &quot;8&quot; </li></ul><ul><li>checkpoint.cptconfigname = &quot;rn2-52ff1bdc&quot; </li></ul><ul><li>uuid.location =  &quot;56 4d 7c 66 1f 23 b5 c3-2f 50 a9 29 7f 53 72 b5&quot; </li></ul>
  19. 19. Configuring for Terminal Services <ul><li>Windows Terminal Services and Citrix Metaframe systems run with many processes </li></ul><ul><li>Windows 2000 systems benefit from a performance tweak </li></ul><ul><li>Add to configuration file workload = &quot;TerminalServices&quot; </li></ul><ul><li>If Citrix Metaframe XP, install Citrix hotfix XE102W014 in guest OS </li></ul>
  20. 20. Time sync for graphicsless VMs <ul><li>Normally need GUI VMware Tools agent to enable time synchronization between guest OS and Service Console </li></ul><ul><li>But Linux servers often run without graphics </li></ul><ul><li>To enable time sync without GUI: tools.syncTime = &quot;TRUE&quot; </li></ul>
  21. 21. Adjusting Remote Console keyboard repeat <ul><li>By default, virtual keyboard device in VM starts autorepeat if a physical key is not released within less than a second </li></ul><ul><li>Network latency or congestion may trigger autorepeat </li></ul><ul><li>Add to config file: keyboard.typematicMinDelay = 2000000 </li></ul><ul><ul><li>Value in microseconds (2 million  sec = 2 sec) </li></ul></ul><ul><ul><li>Choose a value that results in satisfactory performance </li></ul></ul>
  22. 22. Specifying autostart and autostop behavior <ul><li>Config files may contain autostart = &quot;poweron&quot; autostart.delay = &quot;2&quot; Seconds to pause autostop = &quot;poweroff&quot; or… autostop = &quot;suspend&quot; autostop.delay = &quot;2&quot; Seconds to pause </li></ul><ul><li>Caution! Memory page sharing is not active when suspended VMs are resumed </li></ul>
  23. 23. Starting and stopping VMs from the command line <ul><li>To stop a VM: vmware-cmd /home/ted/vmware/a/a.vmx stop mode </li></ul><ul><li>To start a VM: vmware-cmd /home/ted/vmware/a/a.vmx start mode </li></ul>Abrupt power-off; resume without running normal scripts hard Try to run scripts in guest OS; use hard mechanism if VMware Tools is not accessible trysoft Run normal scripts in guest OS before shutdown or after resume; soft
  24. 24. Questions?