تجربه این بنده خدا رو هم بخونید :
I recently wanted to back up the virtual machines stored on my server running ESXi 5, but the only other media I had lying around was an external USB drive. After some reading I discovered that it is not possible to mount a USB device as a datastore in ESXi, however it is possible to mount a NFS volume as a datastore.
To get around this, I created a new small virtual machine running Ubuntu Server 11.10, added a USB controller and the USB device (external drive) to the VM in vSphere, set the drive to mount at startup of the machine, configured it as a NFS share and then added the NFS share as a datastore in vSphere. The steps I followed are shown below:
Setting ESXi to pass the connected USB drive to the virtual machine
After creating the new VM containing Ubuntu Server and connecting the USB external hard drive to my ESXi server, it is necessary to tell ESXi which VM it should connect this USB device to.
- Right click on the VM and select Edit Settings…
- On the Hardware tab click Add… and choose USB Controller as the Device Type. Controller type can be left as xHCI.
- Click Add… again and choose USB Device, the external hard drive should be listed as a host USB device.
- This USB hard drive can now be accessed by your new VM.
Setting the USB drive to mount at startup of the virtual machine
If you are using Ubuntu Server as I am, the USB drive will not mount automatically. In order to get the device to mount automatically every time the VM starts, add an entry to the fstab file that stores details about the static file system. This assumes that the drive has been partitioned already (
see guide for Ubuntu here).
- On the VM: create a folder at the point you wish to mount your drive, I used /media/WD-NFS, and set permissions to 777.
- Find the unique identifier for your drive using blkid in the terminal and note the UUID.
- Open the file /etc/fstab.
- Enter a new line at the bottom of this file that looks something like this:
UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx /media/WD-NFS ext4 defaults 0 0
Where the first item is the UUID of the drive copied in a previous step, the second item is the file path of the mount point folder created in a previous step and the third item is the file system used on the drive. For a more detailed explanation of the fstab file see the Ubuntu documentation here.
- If you now restart the VM the USB drive should be mounted at /media/WD-NFS
Configuring the drive as an NFS share
This section follows the same general instructions as the
Ubuntu documentation found here except that we have already mounted our drive.
- Install the NFS server: apt-get install nfs-kernel-server
- In the file /etc/default/nfs-kernel-server set NEED_SVCGSSD=no
- In the file /etc/default/nfs-common set NEED_IDMAPD=yes and NEED_GSSD=no
- In the file /etc/exports add the following line:
/media/WD-NFS 192.168.1.0/24(rw,nohide,insecure,no_subtree_check,async)
Where the first item is the file path of the mount point of your drive and the second is the network address with network prefix that specifies the local network this drive will be shared on. For a more detailed explanation of the exports file see the documentation linked at the start of this section.
- Restart the service: /etc/init.d/nfs-kernel-server restart
Adding the NFS share as a datastore in vSphere
Back in vSphere, the USB hard drive being shared over NFS can be added as a datastore.
- Select your host server in the Inventory list and open the Configuration tab.
- In the Hardware list select Storage and click Add Storage…
- Select Network File System as the storage type.
- For the server, enter the IP address/name of the VM you mounted your USB drive to
- For the folder, enter the full path to the NFS share on that machine (in this case /media/WD-NFS)
- Finish the wizard.
The USB drive should now be shared using NFS and listed as a datastore in vSphere. Now you are able to browse both your VSXi datastore and the USB drive datastore (and also copy files between the two).