Sometimes you may need to directly connect an external USB flash drive (stick) to your VMWare ESXi host. For example, you may need it to copy a virtual machine image to send it to a remote office (if the WAN channel between offices is slow or highly loaded), to backup VM files to an external USB media, to copy an ISO file or VM image to the ESXi host (when it is better not to overload your LAN). In this article we’ll show how to connect a USB flash drive/stick to an ESXi host as a VMFS datastore or to copy files from a FAT32/NTFS partition directly.
How to Connect an External USB Drive as a VMFS Datastore in VMWare ESXi?
Suppose you want to connect a USB drive to an ESXi host and create a VMFS datastore on it to copy/move files and images of virtual machines conveniently.
In VMWare ESXi 6.5 and higher, the method of connecting a USB device to a host was changed. Earlier several drivers (xhci, ehci-hcd, usb-uhci, usb-storage) were used. Then a single USB driver (vmkusb) replaced all of them.
- Connect to the ESXi host console over SSH;
- Stop the USB arbitrator. The service is used to passthrough a USB device from an ESXi host to a virtual machine (USB Passthrough):
# /etc/init.d/usbarbitrator stopIf you don’t want the USB arbitrator to start after the host restart, run the command:
# chkconfig usbarbitrator off
- Connect an empty USB drive to your ESXi host;
- You can identify the name of the USB drive in the log: /var/log/vmkernel.log or using /dev/disks:
# ls /dev/disks/The USB disk is usually named mpx.vmhbaX or naa.X.
- Create a GPT (GUID) partition table on your USB drive:
# partedUtil mklabel /dev/disks/naa.5000000000000001 gpt
- Then create a partition on your drive manually. To do it, specify the first and the last sector on the drive. List the information about the disk sectors:
# partedUtil getptbl /dev/disks/naa.5000000000000001
- The first sector is always 2048. The size of the last sector is calculated based on the getptbl output. In my example, it is calculated as follows:
121597 * 255 * 63 -1 = 1953455804
If there is a partition on the drive, you can remove it:
# partedUtil delete /dev/disks/naa.5000000000000001 1
- Create an VMFS partition (the GUID of such a partition is always AA31E02A400F11DB9590000C2911D1B8):
# partedUtil setptbl /dev/disks/naa.5000000000000001 gpt "1 2048 1953455804 AA31E02A400F11DB9590000C2911D1B8 0"
- Then you can format the partition with the VMFS6:
# vmkfstools -C vmfs6 -S USB-HDD-DSDatastore /dev/disks/naa.5000000000000001:1
- Open the graphic VMWare vSphere Client and go to Storages. Your USB drive will appear in the list of available datastores.
How to Copy Files from USB Drive (NTFS/FAT32) to ESXi Directly?
If you don’t want to change a file system on your USB drive to VMFS (there is a little trick to access VMFS from Windows), you can access files on NTFS or FAT32 formatted partitions from the ESXi console and copy the files you want.
To access FAT32 formatted partitions from ESXi, you can use the mcopy tool. In order to access an NTFS partition on a USB drive, use ntfscat. Ext3 file system is also originally supported. The basic restrictions are:
- FAT32 and Ext3 partitions are available to read and write;
- NTFS drives are read-only (it means that you can copy data from an NTFS USB drive to an ESXi host, but not vice versa).
To copy a file from a FAT32 USB device to ESXi, use this command:
# /bin/mcopy -i "/dev/disks/naa.5000000000000001:2" ::/some.iso /vmfs/volumes/12345678-ddd654321-4321-aaaabbbb2222/iso/some.iso
/some.iso is a path to a file on your USB drive. The second path shows where to copy the file on the ESXi host (for example, to VMFS datastore directly).
To copy a file back from ESXi to USB, just swap the paths in the command.
The main FAT32 problem is that it doesn’t support files over 4 GB. So it is quite hard to copy VMDK files of virtual machines. As a rule, you can split a source file into some parts before copying (of 3 GB, for example):
# split -b 3221225472 /vmfs/volumes/xx/vm1/vm1.vmdk
Then you can copy all parts to a USB drive and join them on a target ESXi host:
# cat vm1* > vm1.vmdk
To copy a file from an NTFS formatted USB drive to an ESXi host, the following command is used:
# /bin/ntfscat -f /dev/disks/naa.5000000000000001:2" some.iso > /vmfs/volumes/12345678-ddd654321-4321-aaaabbbb2222/iso/some.iso
You can only copy files to ESXi, not back. NTFS cannot be written with ntfscat.