Recently I wanted to install ESXi 6.5 on a USB disk and also use that disk as a datastore to store VM on. I couldn’t get any VMs to run off the USB disk but I spent some time getting the USB disk presented as a datastore so wanted to post that here.
Installing ESXi 6.5 to a USB is straight-forward.
And this blog post is a good reference on what to do so that a USB disk is visible as a datastore. This blog post is about presenting a USB disk without ESXi installed on it – i.e. you use the USB disk entirely as a datastore. In my case the disk already had partitions on it so I had to make some changes to the instructions in that blog post. This meant a bit of mucking about with partedUtil
, which is the ESXi command line way of fiddling with partition tables. (fdisk
while present is no longer supported as it doesn’t do GPT).
1. First, connect to the ESXi host via SSH.
2. Shutdown the USB arbitrator service (this is used to present a USB disk to a VM): /etc/init.d/usbarbitrator stop
(Update: one of the readers emailed me to say this step and the next are not needed and in fact it stops the USB disk from being made visible. So skip them, but if skipping them doesn’t help then try again without skipping them. :)
3. Permanently disable this service too: chkconfig usbarbitrator off
4. Now find the USB disk device from /dev/disks
. This can be done via an ls -al
. In my case the device was called /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514
.
So far so good?
To find the partitions on this device use the partedUtil getptbl
command. Example output from my case:
1 2 3 4 5 6 7 8 9 |
[root@esx01:~] partedUtil getptbl /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 gpt 7625 255 63 122508544 1 64 8191 C12A7328F81F11D2BA4B00A0C93EC93B systemPartition 128 5 8224 520191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 6 520224 1032191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 7 1032224 1257471 9D27538040AD11DBBF97000C2911D1B8 vmkDiagnostic 0 8 1257504 1843199 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 9 1843200 7086079 9D27538040AD11DBBF97000C2911D1B8 vmkDiagnostic 0 |
The “gpt” indicates this is a GPT partition table. The four numbers after that give the number of cylinders (7625), heads (255), sectors per track (63), as well as the total number of sectors (122508544). Multiplying the cylinders x heads x sectors per head should give a similar figure too (122495625).
An entry such as 9 1843200 7086079 9D27538040AD11DBBF97000C2911D1B8 vmkDiagnostic 0
means the following:
- partition number 9
- starting at sector 1843200
- ending at sector 7086079
- of GUID 7086079 9D27538040AD11DBBF97000C2911D1B8, type vmkDiagnostic (you can get a list of all known GUIDs and type via the
partedUtil showGuids
command) - attribute 0
In my case since the total number of sectors is 122495625 (am taking the product of the CHS figures) and the last partition ends at sector 7086079 I have free space where I can create a new partition. This is what I’d like to expose to the ESX host.
There seems to be gap of 33 sectors between partitions (at least between 8 and 7, and 7 and 6 – I didn’t check them all :)). So my new partition should start at sector 7086112 (7086079 + 33) and end at 122495624 (122495625 -1) (we leave one sector in the end). The VMFS partition GUID is AA31E02A400F11DB9590000C2911D1B8, thus my entry would look something like this: 10 7086112 122495624 AA31E02A400F11DB9590000C2911D1B8 0
.
But we can’t do that at the moment as the disk is read-only. If I try making any changes to the disk it will throw an error like this:
1 2 |
Error: Read-only file system during write on /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 SetPtableGpt: Unable to commit to disk |
From a VMware forum post I learnt that this is because the disk has a coredump partition (the vmkDiagnostic
partitions we saw above). We need to disable that first.
5. Disable the coredump partition: esxcli system coredump partition set --enable false
6. Delete the coredump partitions:
1 2 |
[partedUtil delete /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 9 [partedUtil delete /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 7 |
7. Output the partition table again:
1 2 3 4 5 6 7 |
[root@esx01:~] partedUtil getptbl /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 gpt 7625 255 63 122508544 1 64 8191 C12A7328F81F11D2BA4B00A0C93EC93B systemPartition 128 5 8224 520191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 6 520224 1032191 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 8 1257504 1843199 EBD0A0A2B9E5443387C068B6B72699C7 linuxNative 0 |
So what I want to add above is partition 9. An entry such as 9 1843232 122495624 AA31E02A400F11DB9590000C2911D1B8 0
.
8. Set the partition table. Take note to include the existing partitions as well as the command replaces everything.
1 |
[root@esx01:~] partedUtil setptbl /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514 gpt "1 64 8191 C12A7328F81F11D2BA4B00A0C93EC93B 128" "5 8224 520191 EBD0A0A2B9E5443387C068B6B72699C7 0" "6 520224 1032191 EBD0A0A2B9E5443387C068B6B72699C7 0" "8 1257504 1843199 EBD0A0A2B9E5443387C068B6B72699C7 0" "9 1843232 122495624 AA31E02A400F11DB9590000C2911D1B8 0" |
That’s it. Now partition 9 will be created.
All the partitions also have direct entries under /dev/disks
. Here’s the entries in my case after the above changes:
1 2 3 4 5 6 7 8 9 10 11 12 |
-rw------- 1 root root 62724374528 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514 -rw------- 1 root root 4161536 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514:1 -rw------- 1 root root 262127616 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514:5 -rw------- 1 root root 262127616 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514:6 -rw------- 1 root root 299876352 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514:8 -rw------- 1 root root 61774025216 Nov 14 14:29 t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9 lrwxrwxrwx 1 root root 52 Nov 14 14:29 vml.0000000000766d68626133383a303a30 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514 lrwxrwxrwx 1 root root 54 Nov 14 14:29 vml.0000000000766d68626133383a303a30:1 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514:1 lrwxrwxrwx 1 root root 54 Nov 14 14:29 vml.0000000000766d68626133383a303a30:5 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514:5 lrwxrwxrwx 1 root root 54 Nov 14 14:29 vml.0000000000766d68626133383a303a30:6 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514:6 lrwxrwxrwx 1 root root 54 Nov 14 14:29 vml.0000000000766d68626133383a303a30:8 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514:8 lrwxrwxrwx 1 root root 54 Nov 14 14:29 vml.0000000000766d68626133383a303a30:9 -> t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9 |
Not sure what the “vml” entries are.
9. Next step is to create the datastore.
1 2 3 4 5 6 7 8 |
[root@esx01:~] vmkfstools -C vmfs6 -S USB-Datastore /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9 create fs deviceName:'/dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9', fsShortName:'vmfs6', fsName:'USB-Datastore' deviceFullPath:/dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9 deviceFile:t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9 ATS on device /dev/disks/t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9: not supported . Checking if remote hosts are using this device as a valid file system. This may take a few seconds... Creating vmfs6 file system on "t10.SanDisk00Cruzer_Switch0000004C531001441121115514:9" with blockSize 1048576, unmapGranularity 1048576, unmapPriority default and volume label "USB-Datastore". Successfully created new volume: 5a0afdeb-6fb1e7ee-e3a5-1cc1de7a06d0 |
That’s it! Now ESXi will see a datastore called “USB-Datastore” formatted with VMFS6. :)