This assumes you have already added one or more storage drives to your ESXi hypervisor. Let's consider an example where a datastore named Seagate 2 TB (3) has 1.82 TB of Free space.
When attaching the Seagate 2 TB (3) datastore as a drive to a virtual machine, we can use most of the free space (1.80 TB in this example).
Refreshing the datastore, the datastore will now have a minimal amount of free space (18.59 GB in this example). Files added to the virtual machine will not impact the amount of free space in the datastore. At this point, the datastore should never run out of free space.
However, snapshots will reduce the free space. In this example, immediately after taking a snapshot, the free space reduced to 18.57 GB.
As more time passes, the free space will continue to reduce. In this example, a month later, the free space has reduced to 7.95 GB.
Given enough time, snapshots will cause an unmonitored storage drive to eventually run out of free space.
Once the drive runs out of free space, virtual machines using the storage drive will fault. In this example, the following message appears when attempting to use the virtual machine because the storage drive ran out of free space.
Of course, if you do not take snapshots, you would never run out of free space. If you want or need to use snapshots, one way to ensure that you do not run out of free space is to periodically create a new snapshot. Deleting an old snapshot and then taking a new snapshot will increase the free space.
Connect to the ESXi hypervisor using SSH. Create a file named storage.sh.
[root@esx:~] touch storage.sh
Use the vi editor to edit storage.sh.
[root@esx:~] vi storage.sh
In the vi editor, press i to switch to edit mode.Add the following.
#!/bin/sh df -h
Press esc to switch to command mode. Press Shift :, type wq and press enter to save the changes. To test the script, type sh storage.sh.
[root@esx:~] sh storage.sh Filesystem Size Used Available Use% Mounted on VMFS-5 1.8T 1.8T 18.6G 99% /vmfs/volumes/Seagate 2 TB