Defragmentation of a file system. Multiple files within the file system may be fully or partially defragmented with respect to the physical storage system containing the physical file system. The defragmented files include at least one file that represents a virtual storage system. That virtual storage system file contains a number of sub-files that represent files (i.e., virtual files) of the virtual storage system. These virtual files are not files managed by the physical file system, but are files recognized by a virtual file system managed by a virtual machine running on the physical machine. The defragmentation of the virtual files occurs using knowledge of the unordered nature of the allocation segments that make up the virtual storage system file. Accordingly, after defragmentation, the files of the physical file system and the virtual file system are more defragmented with respect to the physical storage system, while not requiring a shut down of the virtual file system.