12 Replies Latest reply on Dec 2, 2011 8:19 AM by csmwww

    vmkfstools convert thick disk to thin tested in vsphere 4.1

    mabedfo Enthusiast

      Hi,

       

      I've been reading a few posts on how to do this and they were a litte incorrect so I put together my own tested steps to converting thick disks to thin disks to reclaim precious storage space:

       

      ESX console commands to convert disk from thick to thin
      --------------------------------------------------------

      VM must be powered off.

       

      1. Use vCenter to see what host the VM to be converted is on and note down disks Datastore location.

      2. Log into that hosts ILO remote console as root user (or putty in if you have the access).

      3. Convert the original thick .vmdk into a thin one
      vmkfstools -i SERVERNAME.vmdk -d thin thinSERVERNAME.vmdk

      4. Move original .vmdk flat file out of the way.
      mv SERVERNAME-flat.vmdk orig-SERVERNAME-flat.vmdk

      5. Move new thin .vmdk flat file into place
      mv thinSERVERNAME-flat.vmdk SERVERNAME-flat.vmdk

       

      6. Remove VM from vcenter inventory and add back again otherwise disks do not show as 'Thin'

       

      7. Check VM boots up and all drives are avaliable

       

      8, Tidy up by deleting the original files

      rm thinSERVERNAME.vmdk
      rm orig-SERVERNAME-flat.vmdk

        • 1. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
          idle-jam Champion
          User Moderators

          Thanks for the tutorial. For those who has Enterprise Edition, you could just do a Storage vMotion and you have to option to go thin.

          • 2. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
            mabedfo Enthusiast

            Yeah true but my current client does not have Enterprise Plus licenses

             

            P.S do I get points for answering my own question

            • 3. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
              idle-jam Champion
              User Moderators

              Nope! =) maybe you could wait for the next similar question that pop up and relink it back here. but i do not mind if you provide me some useful points

               

              Merry X'mas

              • 4. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                a.p. Guru
                User ModeratorsCommunity WarriorsvExpert
                4. Move original .vmdk flat file out of the way.
                mv SERVERNAME-flat.vmdk orig-SERVERNAME-flat.vmd

                5. Move new thin .vmdk flat file into place
                mv thinSERVERNAME-flat.vmdk SERVERNAME-flat.vmdk

                Even though this may work, it's not the way you should do it. Instead of using the "mv" command, use "vmkfstools -E oldname.vmdk newname.vmdk" to rename the virtual disks. This will rename the data disk as well as the header file and also modify the header file accordingly.

                 

                André

                • 5. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                  mabedfo Enthusiast

                  I did try with using vmkfstools -E originally but it returned with an error that it wasnt a valid vmdk file, I went back and tried it again and realised where I went wrong so here is the correct way to do it:

                   

                  ESX console commands to convert disk from thick to thin
                  --------------------------------------------------------

                  VM must be powered off.

                   

                  1. Use vCenter to see what host the VM to be converted is on and note down disks Datastore location.

                   

                  2. Log into that hosts ILO remote console as root user.

                   

                  3. Convert the original thick .vmdk into a thin one
                  vmkfstools -i SERVERNAME.vmdk -d thin thinSERVERNAME.vmdk

                  4. Move original .vmdk flat file out of the way.
                  vmkfstools -E SERVERNAME.vmdk orig-SERVERNAME.vmdk

                  5. Move new thin .vmdk flat file into place
                  vmkfstools -E thinSERVERNAME.vmdk SERVERNAME.vmdk

                   

                  6. Remove VM from vcenter inventory and add back again otherwise disks do not show as 'Thin'

                   

                  7. Check VM boots up and all drives are avaliable

                   

                  8, Tidy up by deleting the original files
                  vmkfstools -U orig-SERVERNAME.vmdk

                  • 6. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                    tekknokrat Lurker

                    I tried the commands for changing the vmdk file type to thin. The goal is to reduce the disk size for making moves of big vmdks more comfortable.

                    I did not get any reduced vmdk files, even when applying the -K (punchzero) switch to vmkfstools and the cloned disk. Any idea how to reduce the disk size?

                    • 7. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                      mabedfo Enthusiast

                      Tested with better results after a 'sdelete', here are the updated steps:

                       

                       

                      ESX console commands to convert disk from thick to thin
                      --------------------------------------------------------

                      1. Within the VM run a defrag of the disk (this is optional but recommended)

                       

                      2. Whilst it's defragging, copy MS Windows Sysinternals 'SDelete' exe to your local

                      VM's disk.
                      This can be downloaded at http://technet.microsoft.com/en-us/sysinternals/bb897443

                      (47Kb)

                       

                      3. Run 'sdelete -c' on the the disk.

                       

                      3. VM must now be powered off, make a note of what vSphere host the VM is running

                      on and what datastores its disks are on.

                       

                      4. Log into that hosts ILO remote console or SSH in as root user.

                       

                      5. Convert the original thick .vmdk into a thin one

                      vmkfstools -i SERVERNAME.vmdk -d thin thinSERVERNAME.vmdk

                      6. Move original .vmdk flat file out of the way.
                      vmkfstools -E SERVERNAME.vmdk orig-SERVERNAME.vmdk

                      7. Move new thin .vmdk flat file into place
                      vmkfstools -E thinSERVERNAME.vmdk SERVERNAME.vmdk

                       

                      8. Remove VM from vcenter inventory and add back again otherwise disks do not show

                      as 'Thin'

                       

                      9. Check VM boots up and all drives are avaliable

                       

                      10. Check to see how much space youve just saved
                      ls -s

                       

                      11. Tidy up by deleting the original files
                      vmkfstools -U orig-SERVERNAME.vmdk

                      • 8. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                        tekknokrat Lurker

                        Hi mabedfo, so you think the size does not change cause of filesystem fragmentation? I can't use sdelete cause our vmdks contains linux filesystems. Perhaps there is an appropriate tool for linux. Someone an hint?

                        • 9. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                          bane201110141 Lurker

                          in linux you could try running bleachbit if it's available for your distribution, then use a bootable version of gparted to shring the partition to about 6% of orginial size away from minimum (ex, 30GB thick, 20GB used -> shrink to 21.8GB) then expand it back to the original size. This will move all data to the front of the disk, so that in the conversion to a thin disk, it won't be copying marked freespace between actual data.

                           

                          Now this will only apply if vmkfstools is doing a raw copy process; when I converted an 80GB thick disk with server 2003 R2 on it, it shrunk down to about 16.4GB which was about 700MB from the amount of actual data in the disk. So by my experience it appeared that vmkfstools is performing a logical copy.

                           

                          One thing I did different than the above tutorial is that I put the "-d thin" at the end of the line as described in this article:  http://kb.vmware.com/selfservice/microsites/search.do?cmd=displayKC&docType=kc&externalId=1028042&sliceId=1&docTypeID=DT_KB_1_1&dialogID=121884319&stateId=0%200%20121886152

                           

                          not sure if changing the syntax of the command by moving the switch to the end actually made any difference; your esx install may be different.

                           

                           

                           

                          fyi, i'm running ESXi 4.1 update 1, and I issued the command via SSH using PuTTY. Here is the command that I used in PuTTY running as root:

                          vmkfstools -i /vmfs/volumes/datastore1/server03r2/server03r2.vmdk  /vmfs/volumes/scratch_disk/server03r2.vmdk -d thin

                          • 10. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                            Enthusiast

                            Here is an script called makeThin that does the conversion of virtual disks in a clean and precise way, with warnings and review after each conversion, for as many VMs as you want.

                             

                            http://vmutils.blogspot.com/2011/06/automatic-thinning-of-virtual-disks.html

                             

                            It can also give you a summary of storage savings.

                            • 11. Re: vmkfstools convert thick disk to thin tested in vsphere 4.1
                              csmwww Lurker

                              >I did not get any reduced vmdk files

                               

                              Among other ideas noted above, be sure you are using "ls -s" to check sizes (also noted below), not "ls -a", to see "real disk usage" size. To furher help avoid confusion, elsewhere I have also read notes about "du" showing disk size... however, my 4.0.0 ESXi did not have "du" (while a 4.1.0 ESXi machine I have did). The "ls -s" worked on "4.0.0" and "4.1.0" for me (see "ls --help"). [tangent - further confusion since "which", as in "which du" does not work, and I did not manually find "du" in the PATH "/bin:/sbin" on 4.1.0 which means it is built-in magic, I guess]