Kamis, 06 Juli 2023

ESXI-mount usb to datastore

 

Accessing USB Flash Drive from VMWare ESXi

https://woshub.com/mount-usb-flash-drive-vmware-esxi/

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.

Officially, VMWare doesn’t support external USB drives as VMFS datastore. However, it works and you can use it. Also, ESXi doesn’t support USB devices larger than 2 TB.

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.

  1. Connect to the ESXi host console over SSH;
  2. 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 stop
    If you don’t want the USB arbitrator to start after the host restart, run the command: # chkconfig usbarbitrator off
  3. Connect an empty USB drive to your ESXi host;
  4. 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.
    stop usbarbitrator to directly connect USB device to vmware esxi host
  5. Create a GPT (GUID) partition table on your USB drive: # partedUtil mklabel /dev/disks/naa.5000000000000001 gpt
  6. 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 vmware esxi shecll - create vmfs partition on the usb drive using partedUtil
  7. 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
  8. 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"
  9. Then you can format the partition with the VMFS6: # vmkfstools -C vmfs6 -S USB-HDD-DSDatastore /dev/disks/naa.5000000000000001:1
  10. Open the graphic VMWare vSphere Client and go to Storages. Your USB drive will appear in the list of available datastores.

usb stick as a vmfs datastore on vmware esxi

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.

Disable the USB arbitrator service before connecting a USB drive to the ESXi host.

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

where /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.

Tidak ada komentar:

Posting Komentar