Mount USB drive in ESX Service Console (COS)

I was asked whether it was possible to read from or write to a USB stick from an ESX Service Console. The simple answer is yes although there are some “buts” to be considered.

  • There are some limitations to the size of FAT32 partition that Windows will recognise.
  • NTFS partitions will be treated as read-only, the COS cannot write to them. Also, some NTFS partitions will not be recognised so it's best to avoid NTFS altogether.

So, having plugged in the USB drive, don't expect it to be automatically mounted as you would in Windows. It's a manual process that requires you to either be present at a keyboard and monitor attached to your ESX host or connected to it via SSH.

Assuming that you're logged in and that you have sufficient privileges (no sucking of eggs here), you first need to find out what device name the drive has been given.

[bash]tail -100 /var/log/messages[/bash]

You need to do this fairly soon after inserting the USB drive or the bits that you need could get buried under lots of toher messages. What you're looking for though is something like this:

[bash]Sep 10 12:03:58 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:44997
Sep 10 12:04:02 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:33220
Sep 10 12:04:08 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:33506
Sep 10 12:04:15 xxxxxxxx kernel: [761378.755253] scsi6 : usb-storage
Sep 10 12:04:17 xxxxxxxx kernel: [761380.746970]   Vendor: SanDisk   Model: Cruzer Micro      Rev: 8.02
Sep 10 12:04:17 xxxxxxxx kernel: [761380.747141]   Type:   Direct-Access                      ANSI SCSI revision: 02
Sep 10 12:04:17 xxxxxxxx kernel: [761380.748979] SCSI device sdb: 15695871 512-byte hdwr sectors (8036 MB)
Sep 10 12:04:17 xxxxxxxx kernel: [761380.749628] sdb: Write Protect is off
Sep 10 12:04:17 xxxxxxxx kernel: [761380.750235] sdb: asking for cache data failed
Sep 10 12:04:17 xxxxxxxx kernel: [761380.750237] sdb: assuming drive cache: write through
Sep 10 12:04:17 xxxxxxxx kernel: [761380.752231] SCSI device sdb: 15695871 512-byte hdwr sectors (8036 MB)
Sep 10 12:04:17 xxxxxxxx kernel: [761380.752890] sdb: Write Protect is off
Sep 10 12:04:17 xxxxxxxx kernel: [761380.753451] sdb: asking for cache data failed
Sep 10 12:04:17 xxxxxxxx kernel: [761380.753453] sdb: assuming drive cache: write through
Sep 10 12:04:17 xxxxxxxx kernel: [761380.753456]  sdb: sdb1
Sep 10 12:04:17 xxxxxxxx kernel: [761380.754780] sd 5:0:1:0: Attached scsi removable disk sdb
Sep 10 12:04:17 xxxxxxxx kernel: [761380.754826] sd 5:0:1:0: Attached scsi generic sg2 type 0
Sep 10 12:05:01 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:43111
Sep 10 12:05:02 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:53396
Sep 10 12:05:10 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:53338
Sep 10 12:05:58 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:36887
Sep 10 12:06:04 xxxxxxxx snmpd[2613]: Received SNMP packet(s) from UDP: [127.0.0.1]:54275[/bash]

As you can see, my device has been mounted as /dev/sdb and the sole partition on it is /dev/sdb1. If you have a USB device with multiple partitions on it, you'll need to know which one you want. The following command will show which partitions are present on a device and how big they are – I hope that it helps:

[bash]fdisk -l /dev/sdb[/bash]

Now that we know which device and partition we want, we have to mount it. First we create a mount point:

[bash]mkdir /mnt/usb[/bash]

You'll only need to do that once. Next we mount our chosen partition:

[bash]mount /dev/sdb1 /mnt/usb[/bash]

Now you should find your USB device mounted under /mnt/usb. You can copy files to and from it as you wish (subject to the filesystem restrictions mentioned earlier).

When you're finished, make sure that you're not using /mnt/usb or any directory or file beneath it (try using “cd /” to go back to the root directory) and issue the following command:

[bash]umount /mnt/usb[/bash]

That's it. You can remove the USB device.