Section 13.2. Using the Command-Line Interface


13.2. Using the Command-Line Interface

In order to fully and efficiently manage your ESX Server, you need to become very familiar with the command-line interface of the ESX Server Service Console. Although the MUI can be used to perform the majority of the administrative tasks for your ESX Server, several tasks can be carried out only from the command line. This section walks you through the most common task you must perform at the Service Console. Specifically, you'll learn the following:

  • How to connect to the Service Console

  • Command-line shortcuts

  • Basic commands for files and directories

  • How to move and copy files

  • How to find files and search there content

  • How to edit files

  • How to manage users and groups

  • How to manage file and directory ownership and permissions

  • How to archive and compress files and directories

  • How to mount file systems in the Service Console (ISO images, external file systems, and Virtual Disk)

13.2.1. Connecting to the Service Console

In order to use the command-line interface, you must connect to the Service Console with either an SSH client or work at the physical Service Console and use the virtual terminals that are available by using the Alt + F2 through Alt + F6 keys.

13.2.1.1. Virtual Terminal

Working from the physical console, you can access the virtual terminals by pressing Alt + F2 through ALT + F6. Alt + F1 brings you back to the Service Console Status screen. Thus, you have five virtual terminals to work with at the physical console.

13.2.1.2. Remote Access Card

It's highly recommended that you include a remote access card in your ESX Server, which will give you the ability to perform remote management. Some of the most common vendor solutions allow for remote management of your server with virtual power, virtual CD-ROM, and virtual floppy capabilities. Some of these solutions are listed in the next paragraph. Once connected, you can use the Alt + F2 through Alt + F6 commands to access virtual terminals as if you where at the physical server. Most will run through a web browser. The main reason this option is recommended is because you'll have the ability to control virtual power and still maintain access to the console even if someone configured the Service Console incorrectly.

Major vendor remote access solutions include the following:

  • HP Insight Lights Out (ILO)

  • DELL Dell Remote Access Card (DRAC)

  • IBM Remote Supervisor

13.2.1.3. SSH Client

If you're working from a Linux workstation, you can connect to the Service Console remotely using an SSH client.

For Windows-based clients, you can download the PuTTY ssh client for free.

13.2.1.4. Telnet

If you have set your ESX Server security to Medium or Custom to allow telnet, you'll also be able to use a standard telnet client to connect to the Service Console (it's not very secure; therefore, it's not recommended).

To attach to the Service Console remotely from a Windows workstation, you can use the PuTTY SSH client shown in Figure 13.1 Specify the IP or host name and you'll get the window shown in Figure 13.2

Figure 13-1. The PuTTY Configuration Screen


Figure 13.2 shows the SSH login screen for your ESX Server Service Console.

Figure 13-2. The SSH Login Screen


Once you've successfully logged in to the Service Console, you can use the following command to validate who you're logged in as, check group membership, or view another user account and their group memberships.

To view your own user account information, type

id

To view user account information for another user, type

id username

This can be useful if you want to validate that a user account is a member of a specific group (see Figure 13.3).

Figure 13-3. Output from the ID Command


As a best practice, you should always log in with an account that does not have root privileges. If you require root access to perform administrative tasks, you can use the following command:

su

This prompts you for the password of the root user account and logs you in as the root user, thus you'll get the root user's environment. Make sure you include the hyphen or you'll get errors when trying to execute certain commands. When you're finished using root privileges, simply type logout and you'll be returned to your normal non-root user environment.

When you've completed your command-line session and want to log out, type

exit

This logs you out and you exit the SSH client window.

13.2.1.5. Man Pages

If you require more detailed documentation for a command, you can view its man page (also called a manual page).

To view the man pages for a command, type

man command-name

To search all man pages for a specific keyword, you can do so, but you'll first need to build an index by typing the following:

makewhatis

This allows you to search all man pages by keyword, as in the following command example:

mank reboot

Figure 13.4 shows the output from the mank command.

Figure 13-4. Output from the mank Command


The command output in Figure 13.4 shows the results for the man page keyword search and the associated command and man page references.

13.2.2. Command-Line Shortcuts

Obviously, using the command line may not be as intuitive as a GUI for some individuals, but there are a few key shortcuts you can use at the command line to alleviate some of the pain. This section covers a few of the shortcuts you can use at the command line.

When typing commands or file names, you can use the Tab key to auto complete the text of the command. You'll need to type enough characters to make the filename or command unique. If you don't type enough characters to be unique, you can press the Tab key twice to see the available choices based on your current characters. For example, in Figure 13.5, the command cd /vm was used, and then the Tab key was pressed twice, which then showed that there are several directories starting with the characters vm in the root directory. This allows you to complete the command and switch to the directory you wish to. If you wanted to switch to the vmimages directory, all you'd need to do is add cd /vmi and press the Tab key and it would complete the rest of the directory name for you.

Figure 13-5. Output of the cd /vm Command


13.2.2.1. Command History

If you want to display a list of previously executed commands, type

history

Figure 13.6 shows the output of history 20, which displays the last 20 commands executed.

Figure 13-6. Output from the history Command


If you want to execute a particular command in the list, you would type

!Event number

Let's say you wanted to execute the ls /etc command, which has event number 1088 shown in Figure 13.6, you'd type !1088 at the command line and it would rerun that command.

Obviously, this technique is more helpful for a much longer command that was executed previously. You can also cycle through the command history by pressing the Up-arrow key to go backward through previous commands at the command prompt.

13.2.3. Basic Commands for Directories and Files

This section covers commands used to move around the directory structure, as well as those used to copy files, move files, delete files, rename files, and make new directories on the Service Console.

If you need to determine your current directory, type

pwd

The output of the pwd command is shown in Figure 13.7

Figure 13-7. Output of the pwd Command


13.2.3.1. Changing Directories

If you need to change to a different directory using the absolute path name, (from the root) type

cd /directory-name

For example, this might manifest itself as cd /vmimages.

To change to a directory relative to your parent directory, type

cd ../directory-name

(This will go up one directory and switch to a directory under your parent.) To change to your parent directory, type

cd ..

To automatically go to your home directory, type

cd

To list the contents of a directory, type

ls

The output of the ls command is shown in Figure 13.8

Figure 13-8. Output of the ls Command


To list the contents of a directory in long format, type

lsl

The output is shown in Figure 13.9 This output offers more detail for the directory list, such as the permissions for the owner, group, and other. The username of the owner and the affiliated group for the file or directory are also displayed. In Figure 13.9, the owner is root and the affiliated group is also root.

Figure 13-9. Output of the ls/ Command


13.2.3.2. Moving and Copying Files

To copy a file from one directory to another, type

cp source-file target-file

In the following example, let's assume your VMFS volume has a label of local and you want to copy a virtual disk file to a backup directory.

To make a copy of a vmdk file and copy it to another directory, type

cp /vmfs/local/w2k3-server.vmdk /backup/w2k3-server-bak.vmdk

To move or rename a file, type

mv current-file new-file or new location

So, for example, if you want to rename a file, type

mv /iso/w2k3.iso /iso/w2k3std.iso

If you want to move a group of files from one directory to another, type

mv /home/vmfinance/server-02/*.*/home/vmadmin/server-02

Note: Before moving any virtual machine configuration files, make sure the machine is powered off and you un-register the VM first. If not, you'll have a lot of fun trying to power it back on (we speak from experience). You can un-register the VM in the MUI and re-register it once you've moved all the files to the new location by clicking the .vmx file in the MUI Manage Files applet. When you click the .vmx file in the MUI, you'll be prompted to register the virtual machine. You can also un-register and register VMs using the vmware-cmd command. This is covered later in this chapter.

To delete file(s), type

rm testfile

If you need to delete a directory (be extremely careful using this command), type

rmrf directoryname

If you need to create a new directory, type

mkdir directoryname

13.2.4. Finding Files and Searching Their Content

You'll find it necessary to search for specific files or search for strings and patterns within files on your ESX Server at some point in time. To do so, use the find and grep command or a combination of both. The find command is used to search for files, while grep is used to search the contents of the files for text strings or patterns. Here are some examples of what you can do with both commands.

If you need to search a file for a specific string, type

grep stringtofind filename

If you want to find out whether a specific user account exists on your server, type

grep username passwd

Figure 13.10 shows the grep command being used to find the user account for vmadmin1 in the /etc/passwd file. In this example, the grep command found a string match for vmadmin1 and printed the line containing the value to the screen.

Figure 13-10. Finding a String Match with the grep Command



Note: The /etc/passwd file contains a list of all user accounts on your ESX Server. It also displays the path to the home directory and default shell.

If you want to find a list of all the virtual switches that exist on your server, type

grep .name /etc/vmware/netmap.conf

This example shows all lines in the /etc/vmware/netmap.conf file that have the string ".name". The /etc/vmware/netmap.conf file contains a list of all the virtual switches and their assigned network devices, as shown in Figure 13.11

Figure 13-11. The /etc/vmware/netmap.conf File


You can also use the cat command to print the contents of a text file to the screen. Also, remember that you can use the cat command with the |more or |less command if the contents of the file are larger than the screen. Figure 13.12 shows the contents of the /etc/vmware/netmap.conf file using the cat command.

Figure 13-12. Using the cat Command to View the Contents of /etc/vmware/netmap.conf


Because the MUI does not give you the option to search for files, you'll need to use the command-line find command to search for files on your ESX Server. Where grep is used to search for strings or patterns within files, find is used to find files that match certain criteria. Figure 13.13 shows the output of the find command when searching the entire directory for files with the .vmx extension. This is useful for locating all virtual machine configuration files whether they are registered or not and to find out if configuration files are being created in the correct locations. Table 13.1 lists the options available for the find command.

Table 13-1. Options for the find Command

find Option

Purpose

-user

Finds files owned by a particular user

-type f

Matches ordinary files (i.e., not executables)

-type d

Matches directories

-name

Matches files are directories based on name. Wildcards can also be used.

-size +50

Finds files larger than 50 100k blocks

-size -50

Finds files smaller than 50 100k blocks

-mtime +5

Finds files or directories modified more than five days ago

-mtime -2

Finds files or directories modified less than two days ago


Figure 13-13. Output of the find Command



Note: As an FYI, the file /etc/vmware/vm-list also contains a dynamically created list of registered virtual machines on ESX Server.

You can use the grep and find commands together to find out information quickly about the configuration of your virtual machines. For example, what if you need to find out which virtual machines are using a specific virtual switch on your ESX Server. You could manually browse all the VMs in the MUI to find out which ones are using the virtual switch or you could use the following command at the Service Console to find out which virtual machines are using a virtual switch named Network01:

find ./ -type f -name "*.vmx" -exec egrep -H -i "Network01" {} \;

The output appears in Figure 13.14 This command shows the path to the .vmx file and the line within the file that shows which virtual interface is using the virtual switch.

Figure 13-14. Output of the find and grep Commands


13.2.4.1. Searching Virtual Machine Configuration Files for Important Information

If you cat out the contents of a virtual machine .vmx configuration file, you can find some useful strings to search for. Figure 13.15 shows the contents of a virtual machine configuration file. A few of the strings have been highlighted that can be useful for finding specific information about your virtual machines.

Figure 13-15. Contents of a Virtual Machine Configuration File


The following are some of the commands that can be used to find useful information about your virtual machines. Hopefully, you'll get the hang of it.

If you want to find all machines that are set to autostart, type

find ./ -type f -name "*.vmx" -exec egrep -H -i "autostart = \"True" {} \;

Incidentally, the backslash (\) is used before "True" because the quote is part of the string being searched for. In this case, the \ lets the command know that the character following the \ is part of the string pattern to search for.

If you want to find all Windows 2003 Standard VMs, type

find ./ -type f -name "*.vmx" -exec egrep -H -i "WinNetStandard" {} \;

Figure 13.16 shows the output of find ./ -type f -name "*.vmx" -exec egrep -H -i "WinNetStandard" {} \;. Table 13.2 contains additional values you can use to query to your server to determine which operating systems are running as virtual machines on your ESX Server.

Figure 13-16. Output of the find and egrep Commands Searching All .vmx Files for the Pattern "WinNetStandard"


Table 13-2. Search Values That Can Be Used with the find and grep Commands to Determine OS Versions on ESX Server

Guest OS Type

guestOS Value

FreeBSD

freebsd

GNU/Linux

Linux

Microsoft Windows NT

winNT

Microsoft Windows 2000 Professional

win2000Pro

Microsoft Windows 2000 Server

win2000Serv

Microsoft Windows 2000 Advanced Server

win2000AdvServ

Microsoft Windows XP Professional

winXPPro

Microsoft Windows 2003, Enterprise Edition

winNetEnterprise

Microsoft Windows 2003, Standard Edition

winNetStandard

Microsoft Windows Small Business Edition Server 2003

winNetBusiness

Microsoft Windows 2003, Web Edition

winNetWeb

Novell NetWare 5

netware5

Novell Netware 6

netware6


13.2.5. Editing Text Files

You may find it necessary to edit text files on your server in order to change configurations or create scripts. The wimpy and inefficient way to edit a text file would be to create them in Windows and run a DOS-to-UNIX file conversion (just to avoid any issues with file formats) and then copy them to the Service Console via an scp/winscp client. If you want to feel more manly/womanly go ahead and learn vi or nano and edit the files on the Service Console directly. It will be worth it in the long run. You'll generally need to edit configuration files that specify network settings such as host name, IP address, gateway address, or that are used for creating and editing scripts. The two text editors available by default are vi and nano. Each can be used to edit text files but have different capabilities. You should try both editors to see which one fits your needs.

13.2.5.1. Editing with vi

To launch vi, type vi at the command prompt. The vi editor has three modes of operation: command mode, edit mode, and ex mode. We'll cover only the most basic functions of vi for editing files.

Typing vi at the command prompt gives you the options shown in Figure 13.17

Figure 13-17. Options for vi


If you need to edit an existing file, type

vi /etc/sysconfig/network

If you want to create a new blank file to edit, type

vi filename

Whenever you open a new or existing file for editing, you are in command mode. To actually start editing text, you'll need to enter edit mode. This can be accomplished by typing i or pressing Insert on your keyboard. This allows you to add text or edit existing text in your file.

Once you're done editing your file, you can get back to command mode by pressing the Esc key on your keyboard. If you'd like to save the file and exit, you'll need to enter ex mode. You can do this by typing :wq (see Figure 13.18). If you'd like to simply exit the file without saving, just type q!; otherwise, you'll be prompted to save if changes have been made to the file. If no edits have been made to the file, simply typing :q will be sufficient.

Figure 13-18. Entering Ex Mode


13.2.5.2. Editing with Nano

The other text editor you have available is nano. Make sure when you edit configuration files with nano that you use nanow. This controls the way nano wraps long lines and can result in syntax errors if not specified when editing configuration files. The nano editing screen is shown in Figure 13.19 To give you an example from the screen in Figure 13.19, use Ctrl + x to exit the editor or Ctrl + k to cut text. The keyboard functions available for editing your file are shown in Table 13.3.

Figure 13-19. The Nano Editing Screen


Table 13-3. Keyboard Functions for Editing Files with Nano

Ctrl + G or F1

Get Help. Show detailed help.

Ctrl + O or F3

Writeout; that is Save File

Ctrl + \ or F14 (according to the Help file)

Replace. Works like find and replace in Notepad. It prompts you for the text you'd like to search for, and then what you'd like to replace it with. When it finds a match, it prompts you to confirm replacement.

Ctrl + Y or F7

Prev Page. Moves you to the previous page.

Ctrl + K or F9

Cut Text; you can use your mouse to highlight text.

Ctrl + C or F11

Cur Position. Shows the line number and character position within the file. Excellent for locating lines in a script file that are reporting an error on a specific line in the script.

Ctrl + X or F2

Exits your current file. Prompts you to save the file if you haven't already.

Ctrl + R or F5

Read File. This option reads in a file and places its contents at the point of your cursor. Similar to cutting and pasting from another file.

Ctrl + W or F6

Where is. Similar to Find in Windows Notepad. It searches for the text string you specify.

Ctrl + U or F10

Uncut Txt. Paste previously cut text.

Ctrl + T or F12

To Spell. Performs spell check on file.


In nano, when you want to copy text, it copies to the whole line by default from the start of the cursor to the end of the line. In Windows, you have the ability to press the Shift key and use the arrow keys to highlight specific text you want to block for copying and pasting. In nano, place the cursor at the starting point of the text you want to copy and then press Ctrl + 6 to set the mark. From there, use the arrow keys to highlight the text you want to copy. The example in Figure 13.20 shows what it will look like in the nano editor. Press Ctrl + 6 again to UNset the mark. Once you've marked your text, you can use Ctrl + K to cut the text and then move the cursor to the point you want to paste the text and then press Ctrl + U to uncut (paste) the text.

Figure 13-20. Highlighting Text to Copy in the Nano Editor


13.2.6. Managing Users and Groups

You can create users and groups from the ESX Server MUI, but you may find it necessary to create or modify users and groups from the command line. One example is the integration of ESX Server authentication with Active Directory. If you create the user account in the MUI, it forces you to create a password which is stored locally and causes ESX to authenticate locally versus going to Active Directory to perform Kerberos authentication. The adduser program allows you to create user accounts without specifying the password (not blank, just no local password), which forces the authentication mechanism to look for alternate authentication sources if you have configured the appropriate Pluggable Authentication Module (PAM).

To create a new user account, type

adduseroptions username

The following's an example for adduser:

adduserc "Supreme VM Leader" svmleader

Figure 13.21 shows the options available for the adduser program.

Figure 13-21. Options for the adduser Program


To delete a user from your server, type

userdel username

To add new groups to your ESX Server, type

groupadd group-name

To modify existing group memberships, type

usermodG group-name username

13.2.7. Managing Directory and File Ownership and Permissions

You may need to change the permissions on a file or directory to allow other groups access to the file or directory. One example of this would be to allow members of a group the ability to manage virtual machines. You would need to grant permissions on the directory and VM configuration files for them to have access. To change the permissions settings on a file or directory use the chmod command.

13.2.7.1. Changing Permissions on a File or Directory

For permissions, you have three different entities you can assign permissions to. Permissions can be set for the user who owns the file, the permissions for the group that is affiliated with the file and other (that is, everyone else). The options are listed as follows:

u The user who owns the file
g The group affiliated with the file or directory
o Other

You also have three different permission attributes you can assign to a file or directory and they can be assigned to the owner, group, or other. The permissions are r=read, w=write, and x=execute. Use the chmod command to set permissions on files and directories. Each entity is identified as follows:

Let's say you wish to grant the owner of the file execute permissions on the file and you want to remove the read permission for other.

To change the permissions on a file, type

chmod u+x,o-r filename

Use either u, g, or o to specify who you are changing permissions for and then you use + or - along with r, w, or x to add or remove that specific permission. In another example, we could add the execute permission for the owner of the file, the group, and remove the read permission for other. This is shown in Figure 13.22

To set the permissions specified in the previous paragraph, type

chmod g+x,u+x,o-r filename

Figure 13-22. Permissions Changes on a File


The permissions are now changed for the file vmwareiscool. Originally, the permissions wererw-rw-r--. After the command chmod g+x,u+x,o-r vmwareiscool, the permissions arerwxrwx---, as shown in Figure 13.22


Note: If you decide to create a shell script (similar to a batch file in DOS/Windows), you'll need to set the execute permissions in order for it to run the commands within the file.
13.2.7.2. Changing File or Directory Owner or Group Affiliation

To change the owner on a file or directory, use the chown command. To change the group affiliation, use the chgrp command. Figure 13.23 shows a directory created by the root user, who is the owner by default, while the group root is the default group affiliated with the directory.

Figure 13-23. Directory Created by a Root User


To change the owner of the directory and all files and subdirectories within it, type

chownR username dirname

You can see an example in Figure 13.24, which shows that the ownership of the testdir has been changed to the user vcadmin.

Figure 13-24. Changing the Ownership of testdir


Now, the user vmadmin is the owner of the testdir directory as well as all files and directories below it.

To change the group affiliation of a file or directory, type

chgrp groupname filename

See Figure 13.25 for the results of the command.

Figure 13-25. Changing the Group Affiliation of a File or Directory


Now, the group affiliation is changed from root to vmadmin, as reflected in Figure 13.25

13.2.8. Archiving and Compressing Files and Directories

The following utilities are used to archive files, to compress files as well as extract files from archives, and to uncompress zipped files.

If you need to create an archive containing a group of files, type

tar cvf filename.tar directory

Figure 13.26 shows an example of archiving all vm configuration files stored under the /home/vmware directory to a directory named /home/archives. You end up with a file named vm_configs.tar in the /home/archives directory.

Figure 13-26. Archiving vm Configuration Files


If you need to see the contents of a tar file, type

tar tvf filename.tar

If you need to compress a file using gzip or bzip2, type

gzip /filename

The following command archives the vm_configs.tar file created in the previous example:

gzip /home/archives/vm_configs.tar

You then end up with a file named vm_configs.tar.gz. You can also use the bzip2 tool to compress files by typing the following:

bzip2 /home/archives/vm_configs.tar

This results in a file named vm_configs.tar.bz2.

To uncompress files, use gunzip or bunzip2, depending on which utility was used to compress the file. This will be evident from the file extension. Files compressed with gzip will have a .gz extension, whereas a file compressed with bzip2 will have a .bz2 extension.

If you need to uncompress a file compressed with gzip, type

gunzip /directory/filename.gz

If you need to uncompress a file compressed with bzip2, type

bunzip2 /directory/filename.bz2

If you need to extract archived files that were compressed with gzip, type

tar xzvf filename.tar.gz

If you need to extract archived files that were compressed with bzip2, type

tar xjvf filename.tar.bz2

In you need to extract files from an archive, type

tar xvf filename.tar

The preceding command extracts the archive into your current directory. You may want to create a new directory or specify the path to extract the archive to in the command line.

If you want to specify a different directory to extract the archive to, type

tar xvfC filename.tar /targetdirectory

This command extracts the archive into the /targetdirectory specified on the command line. The C option is needed to specify a directory name other than the current directory.

To list the contents of files that are compressed with either gzip or bzip2, use the following commands:

For an archive compressed with gzip, type

tar tzvf filename.tar.gz.

For an archive compressed with bzip2, type

tar tjvf filename.tar.bz2.

13.2.9. Mounting ISO Images, CD-ROMs, and Virtual Disks in the Service Console

The Service Console gives you the ability to mount several different devices as well as ISO images and virtual disks so you can access those file systems. This section covers the commands used to mount these file systems so you can gain access to the files.

To mount a CD-ROM on your ESX Server Service Console, type

mount /mnt/cdrom

To unmount a CD-ROM, type

umount /mnt/cdrom

To mount a virtual disk in the Service Console, type

vmware-mount.pl /vmfs/vmfs_name/virtual_disk_filename partition_number mount-point



Virtualization With VMware ESX Server
Configuring VMware ESX Server 2.5 (Vol 1)
ISBN: 1597490199
EAN: 2147483647
Year: 2005
Pages: 173

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net