To extract files from .vmdk files on the CLI, first 2 tools are needed
- app-arch/p7zip
- sys-fs/multipath-tools
VMWare disk files are compressed archives. First step is to decompress the vmdk archive
user@host $ 7z e virtualdisk.vmdk
This command will decompress the archive and extract the included partitions. The extracted partitions might look like this
user@host $ ls -l
total 48452008
-rw-r--r-- 1 user usergroup 510656512 Jan 11 15:08 0.img
-rw-r--r-- 1 user usergroup 42435870720 Jan 11 19:01 1.lvm
-rw-r--r-- 1 user usergroup 1048576 Jan 11 15:08 2
-rw------- 1 user usergroup 6671171584 Jan 11 15:08 virtualdisk-disk1.vmdk
In the vmdk file contained - 0.img file, - 1.lvm file - 2 file
In this particular case the interesting files have been included in the 1.lvm file. Now the .lvm file needs to be mounted to gain access to the files.
Execute losetup which sets up and controls loop devices:
root@host # losetup /dev/loop0 1.lvm
Use kpartx tool which creates device maps from partition tables:
root@host # kpartx -a /dev/loop0
Mount the partition file to a mount point in the tree here /dev/partition/
root@host # mount /dev/mapper/
completing device or mount point
operating-system-vg-root@ operating-system-vg-swap_1@ loop0p1
root@host # mount /dev/mapper/operating-system-vg-root@ /mnt/partition/
At this moment the interesting files can be accessed via the mountpoint:
user@host $ df -h | grep mnt
/dev/mapper/operating-system-vg-root 33G 4.3G 27G 14% /mnt/partition
Change to /mnt/partition to access the interesting files:
user@host $ cd /mnt/partition
user@host $ ls -l
drwxr-xr-x 2 root root 4096 May 27 2017 bin/
drwxr-xr-x 2 root root 4096 May 27 2017 boot/
drwxr-xr-x 4 root root 4096 May 27 2017 dev/
drwxr-xr-x 97 root root 4096 Jan 11 13:56 etc/
drwxr-xr-x 2 root root 4096 Apr 12 2016 home/
drwxr-xr-x 16 root root 4096 May 27 2017 lib/
drwxr-xr-x 2 root root 4096 Feb 15 2017 mnt/
drwxr-xr-x 9 root root 4096 May 27 2017 opt/
drwxr-xr-x 2 root root 4096 Apr 12 2016 proc/
drwx------ 3 root root 4096 Jan 11 15:04 root/
drwxr-xr-x 2 root root 4096 May 27 2017 sbin/
drwxr-xr-x 2 root root 4096 Feb 5 2016 sys/
drwxrwxrwt 8 root root 4096 Jan 11 15:07 tmp/
drwxr-xr-x 11 root root 4096 May 27 2017 usr/
drwxr-xr-x 12 root root 4096 May 27 2017 var/