VMware has not published a grammar for .vmx files. This page gives the grammar of the
reader libvirt uses for them (src/util/virconf.c with its VMX flag, read in full for this
page) and what libvirt's src/vmx/vmx.c does with the encoding line and the escapes. Other
readers may accept more; a file that follows these rules is accepted by libvirt.
Statements
| Part | Rule |
|---|---|
| Statement | name = "value", with optional blanks (spaces and tabs) around the equals sign. |
| Name | Starts with a letter or a dot, then letters, digits and _ : . - *. Names are not case-sensitive when looked up (virConfGetValue compares them without regard to case for VMX files). If a name occurs twice, the first is the one found. |
| Value | A string in double quotes (single quotes and a Python-style triple-quoted string are also accepted by the reader), on one line: the string ends at the next quote and cannot hold a quote. A value that is not quoted is an error: the reader says "numbers not allowed in VMX format" for a bare number and "lists not allowed in VMX format" for a value in brackets. |
| Separator | A line end, or a semicolon followed by more statements. Anything else after a value is "expecting a separator". |
| Comment | A line whose first non-blank character is #, or a # after a value, to the end of the line. |
| Blank lines | Allowed. |
The encoding line
The statement .encoding = "UTF-8" says how the file is encoded. libvirt reads the
file, looks up .encoding, and unless it is absent or UTF-8 (compared without
regard to case) converts the whole file to UTF-8 with libxml2's character-encoding handlers and
reads it again. VMware writes it first. The other values are whatever the converter knows: the
viewer converts UTF-8, windows-1252, ISO-8859-1, Big5, GBK, Shift_JIS, EUC-JP, EUC-KR,
windows-1250 and windows-1251, and reads any other as windows-1252 and says so.
Escape sequences in values
libvirt's virVMXEscapeHex and virVMXUnescapeHex replace a character by an
escape character and its two-digit hexadecimal code (c + XX, with the digits in
lower case when written). Two escape characters are used: the pipe |, for which
displayName and annotation are unescaped (|20 is a space, and a
| without two hexadecimal digits after it is an error: "contains invalid escape
sequence"), and the percent sign %, which displayName is also unescaped with.
Other values are used as written.
Example
.encoding = "UTF-8"
displayName = "Test|20VM" # reads as: Test VM
scsi0:0.fileName = "Test.vmdk"
ide1:0.fileName = "/dev/scd0"; ide1:0.present = "TRUE"
Rules for a valid file
- Every line is blank, a comment, or one or more statements.
- Every value is a quoted string that ends on its line.
- The encoding line, if present, names an encoding the reader can convert.
- libvirt additionally requires
config.versionto be 8 andvirtualHW.versionto be 4 or higher, andmemsizeto be a multiple of 4; VMware's own software has no such rule in any source read, so the viewer reports only amemsizethat is not a multiple of 4 and avirtualHW.versionthat is not a number.