Thursday, May 9, 2019

How to create an ADDITIONAL partition on a ESXi 6.5 bootable USB drive


In the old day's it was possible to create a VMFS partition on a flash drive, VMware even did it automatically.
But if you try do do this now, there is no obvious way to do this.


Disclaimer: this guide is not for the faint of heart we will be rewriting the entire partition table, if you are not careful you WILL destroy your data. Make sure you have a backup of your ESXi drive and/or configuration.
This is probably not recommended for production environment's, use at your own risk.


The reason I made this post is I wanted to use my 2 Sandisk Cruzer fit 64GB drives (https://www.sandisk.com/home/usb-flash/cruzer-fit) for something other than just booting ESXi, obviously they are not gonna break any speed records, but a simple VM like FreeNAS should be fine to run on there, and it's a nice place to store some ISO's.

As you can see, 1 have 2 host's that are not in use

They both have a bunch of old disk I had laying around on a build in controller

But the main reason is this little guy, 64GB, well 58GB really counting after the overhead, of sweet USB goodness.
However it's only accessible by the underlying VMware hypervisior.
As you can see, it has a bunch of partitions on it already, and we like to keep it that way so our host can continue to boot from it.

Adding a new datastore is not possible:


Like any good guide, let's make sure SSH is on and log into the console


Collect information:

ls -lah /dev/disks/

There is the USB drive "t10.SanDisk00Cruzer_Fit0000000000004C530001290828121532" and it's corresponding partitions 1...5,6,7,8 and 9... (no idea what happened to partitions 2 trough 4, this is a clean install)
We need the "vml... " name for this:


Let's look at that drive in some more detail:
partedUtil getptbl /dev/disks/vml.0000000000766d68626133323a303a30

Now in this picture is a lot of information and most of it can be done by just this command.
I't important to know what we are changing and how.
this information will differ from drive to drive and from installation to installation, so it's important to save this information, this will help us if we need to recover from a finger fumble.

So in this case we have a drive with 7667 cylinders, 255 heads, 63 sectors per track and 123174912 sectors

The first partition spans from sector 64 to 8191 that makes a total of 8127 sectors * 512 bytes per sector = 4161024 bytes = 4MB
the second spans from 8224 to 520191 etc.

You know where this is going right? "just add another partition, starting at 7086080 and ending at the last sector" right? WRONG

with partedUtil it's not possible to add a partition, so my initial try was something like this:

partedUtil setptbl "/dev/disks/vml.0000000000766d68626133323a303a30" gpt "10 7086080 122575949 AA31E02A400F11DB9590000C2911D1B8 0"

Error: Read-only file system during write on /dev/disks/t10.SanDisk00Cruzer_Fit0000000000004C530001290828121532 SetPtableGpt: Unable to commit to disk

resulting in a error:
Error: Read-only file system during write on /dev/disks/t10.SanDisk00Cruzer_Fit0000000000004C530001290828121532
SetPtableGpt: Unable to commit to disk

The reason for this is that VMware has the entire drive locked so it can do a coredump to one of the partitions on the drive.
This can be disabled by using this command:

esxcli system coredump partition set --enable false
with esxcli system coredump partition get you can verify it's disabled.


Right! of to the races then:
nope, that's not good, that definitely not good.

now I have just one partition, starting at 7086080 and ending 122575949, just no boot partitions anymore. Don't worry there is still a way to recover, since ESXi run's from memory it does not really need the boot drive unless the host is (re)booted.

So how to get to the numbers that we need:

The original partition table was this:
gpt
7667 255 63 123174912
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
and we want a partition 10 with the remaining free space

the first usable sector is the sector after the last sector of the last partition so 7086079 + 1 = 7086080
the last sector takes some math and since our drive is 7667 cylinders, 255 heads, 63 sectors per track the formula is 7667 * 255 * 63 - 1 = 123170354
I made a mistake in the first calculation because I assumed "I have 2 identical USB drives, identical servers, identical installations so the numbers must be the same" WRONG

Also: what are all these numbers C12A7328F81F11D2BA4B00A0C93EC93B  / 9D27538040AD11DBBF97000C2911D1B8 etc? you can find this using the command partedUtil showGuids

This will list all the possible partition GUID's that VMware understands

we want a vmfs partition so we pick AA31E02A400F11DB9590000C2911D1B8

and now for the correct syntax of the command: rewrite the entire partition table in one command like this:

partedUtil setptbl "/dev/disks/vml.0000000000766d68626133323a303a30" gpt "1 64 8191 C12A7328F81F11D2BA4B00A0C93EC93B 128" "5 8224 520191 EBD0A0A2B9E5443387C068B6B72699C7 0" "6 520224 1032191 EBD0A0A2B9E5443387C068B6B72699C7 0" "7 1032224 1257471 9D27538040AD11DBBF97000C2911D1B8 0" "8 1257504 1843199 EBD0A0A2B9E5443387C068B6B72699C7 0" "9 1843200 7086079 9D27538040AD11DBBF97000C2911D1B8 0" "10 7086080 123170354 AA31E02A400F11DB9590000C2911D1B8 0"


and we have a partition 10:

now the partition is not formatted yet, so we do that using either vmfs5 or vmfs6:

vmkfstools -C vmfs5 -S USB-Datastore1 /dev/disks/vml.0000000000766d68626133323a303a30:10

vmkfstools -C vmfs6 -S USB-Datastore1 /dev/disks/vml.0000000000766d68626133323a303a30:10


and if we rescan the host for new datastores:


after all is done, we can re-enable coredump creation:
esxcli system coredump partition set --enable true
and verify using
esxcli system coredump partition get


Some interesting read's for more information and how to use an entire (USB) drive, where I got most of the information and inspiration for this post:

https://kb.vmware.com/articleview?docid=1036609

https://communities.vmware.com/thread/582002

https://docs.vmware.com/en/VMware-vSphere/6.5/com.vmware.vsphere.storage.doc/GUID-2062B38D-C1F0-4620-BC29-EDD566B0D4D1.html

https://www.virten.net/2016/11/usb-devices-as-vmfs-datastore-in-vsphere-esxi-6-5/

http://iamjoost.com/2017/06/01/usb-drive-as-datastore-on-esxi-6-0/

Wednesday, October 23, 2013

Installing a KPN USB Adapter (Siemens Gigaset USB adapter 108) on Windows 7

Recently I found a KPN USB adapter in a box I had forgotten about, since it looked pretty cool I was wondering if I could hook it up to my Windows 7 (64 bit) machine.
Since i don't have a CD-rom or DVD-drive in PC and most drivers that come supplied with hardware are out of date, I tried downloading the drivers from the suppliers (KPN) website, unfortunately they have no Windows 7 drivers available
I also tried the manufacturer: Siemens, apparently they forgot they ever made such a device, however the drivers are still on the website, if you know where to look.

Sunday, July 24, 2011

Running MRTG on unRAID

MRTG or "Multi Router Traffic Grapher" is a tool to graplicy display stats for your router, server or pretty much anything you want to monitor via SNMP.
It's published under the GNU General Public License which means you can do most things you want with this software as long as you do not claim you created the software and don't sell it.
So I tough it would be fun to run this on my unRAID server, so here is how I did.




Thursday, July 21, 2011

Installing CentOS via local FTP using PXE and unRAID

So I have my unRAID server serving PXE requests, now what? Well: install CentOS of course!
CentOS is an Enterprise-class Linux Distribution and they have created some nice tools to be able to create a PXE installation environment, here is how I did it.



Tuesday, July 19, 2011

Using unRAID and DD-WRT to create a PXE boot server

For a while if been struggling with the idea to create a PXE server in my network. It annoys me carrying USB sticks or DVD's around in my local network, especially since I have a unRAID (Slackware 12 running from a USB stick) server running 24/7.
My unRAID server
So I went and made myself a PXE server.