All notes
Vmwar

# VMware ESX

• VMware ESX is an enterprise-level computer virtualization tool.
• It is a component of VMware's larger offering, VMware Infrastructure, which adds management and reliability services to the core server product.
• It is recommended to migrate from earlier ESX architecture to the newer ESXi.
• It runs on host server hardware without an underlying operating system.
• ESX is apparently derived from "Elastic Sky X", which is not mentioned by VMware. See wikipedia.
• VMware ESXi is a smaller footprint version of ESX that does not include the ESX Service Console. It is available without the need to purchase a vCenter license as a free download from VMware with some features disabled.
• ESX runs on bare metal, without running an operating system, unlike other VMware products. It includes its own kernel; a Linux kernel is started first, and is then used to load a variety of specialized virtualization components, including VMware's vmkernel component.
• Since running on bare metal, it is type I hypervisor.
• Thus, at normal run-time, the vmkernel is running on the bare computer and the Linux-based service console runs as the first virtual machine. VMWare dropped development of ESX at version 4.1, and uses ESXi, which does not include a Linux kernel.
• ESX uses a Linux kernel to load additional code: often referred to by VMware, Inc. as the "vmkernel".
• vSphere Client (formerly VMware Infrastructure Client), enables monitoring and management of a single instance of ESX or ESXi server. After ESX 4.1, vSphere Client was no longer available from the ESX/ESXi server, but must be downloaded from the VMware web site.

A hypervisor or virtual machine monitor (VMM) is a piece of computer software, firmware or hardware that creates and runs virtual machines.
A computer on which a hypervisor is running one or more virtual machines is defined as a host machine. Each virtual machine is called a guest machine.

# Concepts

## vmotion

What is VMotion? mosaicTec.com: what is vmotion.

VMware VMotion enables the live migration of running virtual machines from one physical server to another with zero downtime, continuous service availability, and complete transaction integrity. It is transparent to users.

# VMWare Workstation: Concepts

## Shortcuts

Ctrl+G  抓取键盘和鼠标输入内容。
Ctrl+Alt 释放鼠标光标。

Ctrl+Alt+Insert 关闭客户机操作系统，或从客户机操作系统注销（取决于客户机操作系统）。此命令只会被虚拟机接收。
Ctrl+Alt+Delete 关闭客户机操作系统，或从客户机操作系统注销（取决于操作系统）。
在 Windows 主机中，如果未使用增强型虚拟键盘功能，那么主机操作系统和虚拟机都会接收到此命令（即使 Workstation 对输入进行着控制）。取消结束主机操作系统会话的操作，并返回到虚拟机，以执行注销、关机或其他管理任务。

Ctrl+Alt+Enter 进入全屏模式。

Ctrl+Alt+空格键 将任何命令发送到虚拟机，使 Workstation 不对其进行处理。要使用此功能，请按住 Ctrl+Alt 并释放空格键，然后在继续按住 Ctrl+Alt 键状态下按组合键的下一个键。

Ctrl+Tab
Ctrl+Shift+Tab （仅限 Windows 主机）在选项卡之间切换。

Ctrl+Alt+Left/Right 在全屏模式下，切换到上/下一个处于开启状态的虚拟机。

Ctrl+Shift+U 在 Unity 模式中，访问虚拟机的[开始]或[应用程序]菜单。
通过修改 Unity 首选项设置可以更改 Unity 热键组合。


## Disks

### Independent Persistent/Non-persistent Mode

In a nutshell, this all related to how the VMDK behaves when a virtual machine snapshot is taken. VMDKs, by default, are said to be dependent. In other words, when the virtual machine is snapshot’ed, this disk is included in the snapshot.

You can think of Independent as meaning ‘Independent of snapshots’.

#### Independent Persistent Mode

No delta file is associated with this disk during a snapshot operation. In another words, snapshot has no effect on disks in Independent Persistent Mode.

All changes to the disk are preserved when the snapshot is deleted.

#### Independent Non-persistent Mode

A redo log is created to capture all subsequent writes to that disk. However, if the snapshot is deleted, or the virtual machine is powered off, the changes captured in that redo log are discarded for that Independent Non-persistent VMDK.

Example:

Let’s take a virtual machine which hosts a web service, but it is primarily a read-only web site with content that rarely changes. This VM has three disks. Disk 1 contains the Guest OS and web application (e.g. Apache). Disk 2 contains the web pages for the web site. Disk 3 contains all the logging activity.

### Virtual disk in single or multiple files

A monolithic disk: a virtual machine disk contained in a single file.

A split disk: a virtual machine disk split into 2GB files.

Disadvantages of monolithic disks:

If you delete snapshots and need to consolidate unused .vmdk files, if you need to defragment .vmdk files, etc., then your host needs as much free space as the entire .vmdk file. In contrast, if you use split disks, then your host needs only as much free space as one of the individual .vmdk extents.
If you want to copy or back up a VM, you might be copying it to a file system that doesn't support such large files.
If you're in the middle of copying or backing up a VM but need to cancel the operation and to resume it later, using split disks is much less painful.

Less file system clutter (and in that sense it's easier to manage).
The VM will require fewer open file handles. Some host operating systems have a somewhat low limit on the maximum number of open file handles, and this can matter if you take a lot of snapshots.


kb.vmware.com: convert a monolithic disk to sparse disks. To change from a monolithic disk to a split disk, you must copy the virtual disk data from the monolithic disk to a new split disk. After copying the data, you must then associate the virtual machine with the new split disk. You may then delete the old monolithic disk.

### Thin/Thick Provisioning

• Thin. VMDKs only consume blocks when data is written to disk from within the VM/Guest OS. The amount of actual space consumed by the VMDK starts out small, but grows in size as the Guest OS commits more I/O to disk, up to a maximum size set at VMDK creation time.
• Thick (aka LazyZeroedThick). These disks reserve space on the VMFS filesystem but there is an interesting caveat. Although they are called thick disks, they behave similar to thinly provisioned disks. Disk blocks are only used on the back-end (array) when they get written to inside in the VM/Guest OS.
• EagerZeroedThick. These virtual disks reserve space on the VMFS filesystem and zero out the disk blocks at creation time.

stat zzz-flat.vmdk
File: "zzz-flat.vmdk"
Size: 4294967296      Blocks: 3502080    IO Block: 131072 regular file
Device: c2b73def5e83e851h/14030751262388250705d Inode: 163613572   Links: 1
Access: (0600/-rw——-)  Uid: (    0/    root)   Gid: (    0/    root)
Access: 2012-02-29 13:04:53.000000000
Modify: 2012-03-01 15:29:11.000000000
Change: 2012-02-22 00:12:40.000000000

# This is a thinly provisioned 200GB VMDK (4294967296 * 512) but only ~ 1.8 GB (3502080 * 512) used.


### Fragmentation

#### Recommended steps

1. Run a disk defragmentation utility inside the virtual machine (guest OS).
2. Power off the virtual machine, then defragment its virtual disks from the virtual machine settings editor (VM - Settings). Select the virtual disk you want to defragment, then click Defragment. Note: This capability works only with virtual disks, not physical or plain disks.
3. Run a disk defragmentation utility on the host computer.

#### Best practices

Large single virtual disk file has a problem in defragmentation. The defragmentation process requires free working space on the host computer's disk. If your virtual disk is contained in a single file, for example, you need free space equal to the size of the virtual disk file.

Host disks, virtual disks and guest disks all affect the performance of VMware Workstation.

It is strongly recommended that you defragment using a guest operating system mechanism before taking the first snapshot (or linked clone):

• Workstation makes all its changes to the redo log, not to the original disk, when you run a defragmenting program on the guest after a snapshot. You lose the ability to defragment inside the original disk forever.
• Every sector that moves is copied to the redo log, making the virtual machine redo log extremely large when the disk is heavily fragmented and you run defragmentation after a snapshot.

#### Performance Impact of Defragmenting Snapshots and Linked Clones

There may be a performance impact when you defragment a linked clone or a virtual machine with a snapshot. Exact performance degradation depends on:

• The fragmentation of the parent virtual machine disk when you created the snapshot or linked clone.
• The nature of the subsequent updates to the parent virtual machine disk.

Defragmentation tends to make the redo file grow. The redo file itself can become defragmented with respect to the host file system. If your use of virtual machines is strongly performance oriented, you should avoid defragmenting - or using - linked clones and snapshots.

## Files

• vmname.vmx: The primary configuration file.
• vmname.nvram: stores the state of the virtual machine BIOS.
• vmname-s###.vmdk: the Virtual disk files can increase. E.g. As data is added to a virtual disk, the files increase to a maximum of 2GB each.
• vmname-f###.vmdk: all disk space was allocated.
• vmname.vmsd: A centralized file for storing information and metadata about snapshots. It is stored in the working directory.
• vmname.Snapshot.vmsn: The snapshot state file, which stores the running state of a virtual machine at the time you take that snapshot. It is stored in the working directory.
• vmname.Snapshot###.vmsn: The file that stores the state of a snapshot.
• vmname.vmss: The suspended state file, which stores the state of a suspended virtual machine. It is stored in the working directory.

## Shared VMDK for two VMs

Is is possible to create shared VMDK for two VMs? Simply put, yes it is but not recommended (even dangerous to data!).

Now what you have to consider is that there is no magic here, it literally is the same as a physical environment.  The same as attaching a single SCSI disk to two hosts.  We used to do this decades ago, but it comes with risks.

Just like any shared block storage, you need a clustered file system to handle the access.  So you can't just take NTFS and attach it to two hosts at once.  And even if you have a clustered filesystem, you can't share a SQL database between two systems just by attaching it to them.

What's dangerous? shared disk in general or to use it with SQL? Both. NTFS can't be shared.  It is not a clustered file system.  SQL on a clustered file system can't just be shared either.  Just because a filesystem is clustered doesn't mean that a database file is.  You need both a clustered file system and then you need your application (SQL Server in this case) to be clustered too.


### Turn off guest time sync with host

The time synchronization checkbox controls only whether time is periodically resynchronized while the virtual machine is running. Even if this box is unselected, by default VMware Tools synchronizes the virtual machine's time after a few specific events that are likely to leave the time incorrect.

For VM ESXI, edit /vmfs/volumes/datastore_name/vm_name/vm_name.vmx. Set these options to zero. If the entries do not exist, add them.

Note: 0 = disabled, 1 = enabled.

tools.syncTime = "0"
time.synchronize.continue = "0"
time.synchronize.restore = "0"
time.synchronize.resume.disk = "0"
time.synchronize.shrink = "0"
time.synchronize.tools.startup = "0"
time.synchronize.tools.enable = "0"
time.synchronize.resume.host = "0"


Note: In GSX, VMware Fusion, VMware Player and VMware Workstation, you must use "FALSE" instead of "0".

# Networks

## vmnet0, vmnet1, vmnet8

These are VMware virtual network interfaces on the local machine when running VMware Workstation or VMware Fusion. vmnet1 is for host-only communication and vmnet8 for Nat the physical network. quora.com.

The Bridged network adapter is known as vmnet0. In Fusion 3.x and later, it uses the vmnet-bridge and vmnet-netifup services.
The Host-only network adapter is known as vmnet1. In Fusion 3.x and later, it uses the vmnet-dhcpd service.
The NAT network adapter is known as vmnet8. In Fusion 3.x and later, it uses the vmnet-natd, vmnet-dhcpd, and vmnet-netifup services.


If you want to modify the dhcp.conf, cd /Library/Preferences/VMware Fusion/vmnet8. See willWarren.com: set static ip address in VMWare.

### Can we use 192.168.*.* for NAT networks?

wcfNote: Yes! I've tried. The validation should be like:


export http_proxy=http://proxy:8083/


## Work with VPN

When usingF5 Big-IP Edge Client, it hijacks all your routings and you can't SSH into your guest VM anymore. The only way to access your VM is to configure port forwarding in VMWare Network Configurations and ssh to localhost.

### Set port forwarding on Mac OS

---------- Change NAT configure file.

sudo vi /Library/Preferences/VMware\ Fusion/vmnet2/nat.conf

-- find [incomingtcp] part
[incomingtcp]
# Use these with care — anyone can enter into your VM through these…
# The format and example are as follows:
#<external port number> = <VM’s IP address>:<VM’s port number>
#8080 = 172.16.3.128:80
# It means we map virtual machine 80 port to host machine 8080 port.

-- Restart network service of VMware Fusion.
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --stop
sudo /Applications/VMware\ Fusion.app/Contents/Library/vmnet-cli --start

Note: The config files you changed will be reset after VMWare Fusion upgrade, please backup it at some where.


# VMWare workstation: operation

## Snapshots

Taking a snapshot saves the current state of the virtual machine, so you can return to it at any time. Snapshots are useful when you need to revert a virtual machine repeatedly to the same state, but you don't want to create multiple virtual machines.

If you simply want to save the current state of your virtual machine temporarily, so you can continue work later from the same state, use Suspend and Resume.

To take snapshots of multiple virtual machines — for example, taking snapshots for all members of a team — requires that you take a separate a snapshot of each team member.

netappKB: SCSI reservation. SCSI reservations are used to control access to a shared SCSI device such as a disk or tape drive. An initiator sets a reservation on a Logical Unit Number (LUN) in order to prevent another initiator from making changes to the LUN. This is similar to the file-locking concept.

### Created Files

When a snapshot is created, it is comprised of these files:

• "vm"-"number".vmdk and "vm"-"number"-delta.vmdk
A collection of .vmdk and -delta.vmdk files for each virtual disk is connected to the virtual machine at the time of the snapshot. These files can be referred to as child disks, redo logs, or delta links. These child disks can later be considered parent disks for future child disks. From the original parent disk, each child constitutes a redo log pointing back from the present state of the virtual disk, one step at a time, to the original.
Note: The "number" value may not be consistent across all child disks from the same snapshot. The file names are chosen based on filename availability. If the virtual disk is larger than 2TB in size, the redo log file is of "vm"-"number"-sesparse.vmdk format.
• "vm".vmsd
The .vmsd file is a database of the virtual machine's snapshot information and the primary source of information for the Snapshot Manager. The file contains line entries which define the relationships between snapshots as well as the child disks for each snapshot.
• "vm"Snapshot"number".vmsn
The .vmsn file includes the current configuration and optionally the active state of the virtual machine. Capturing the memory state of the virtual machine lets you revert to a turned on virtual machine state. With nonmemory snapshots, you can only revert to a turned off virtual machine state. Memory snapshots take longer to create than nonmemory snapshots.

### Delete, Revert

• 当删除虚拟机的所有快照时，针对该虚拟机所创建的所有delta文件中的内容将会合并到原来的vmdk文件中，合并完成后再删除vmdk文件。如果只选择删除一个快照，那么这个快照的delta文件将和其父快照的delta文件进行合并。
• 如果选择回滚到某一个快照，那么当前的磁盘和内存状态将会被丢弃，而且虚拟机会转变到revert-to的状态。

### Disabling Snapshots for Better Performance

VMware Workstation operates more efficiently with snapshots disabled. If you do not need snapshot functionality, disable it for better performance.

## Clones

A clone is a copy of an existing virtual machine. The existing virtual machine is called the parent of the clone. When the cloning operation is complete, the clone is a separate virtual machine.

### Why Make a Clone?

Installing a guest operating system and applications can be time consuming. With clones, you can make many copies of a virtual machine from a single installation and configuration process.

Clones are useful when you must deploy many identical virtual machines to a group.

### Full clones vs Linked clones

A full clone is an independent virtual machine, with no need to access the parent. Because a full clone does not share virtual disks with the parent virtual machine, full clones generally perform better than linked clones. However, full clones take longer to create than linked clones.

A linked clone is made from a snapshot of the parent. Ongoing changes to the virtual disk of the parent do not affect the linked clone, and changes to the disk of the linked clone do not affect the parent.

Linked clones are created swiftly, so you can easily create a unique virtual machine for each task you have.

You can also easily share a virtual machine with other users by storing the virtual machine on your local network, where other users can quickly make a linked clone. This facilitates collaboration: for example, a support team can reproduce a bug in a virtual machine, and an engineer can quickly make a linked clone of that virtual machine to work on the bug.