Tip: extract a filesystem from a disk image

You’ve got a partitioned disk image, how do you pull out of that just the filesystem(s)? It’s easy with libguestfs tools:

$ virt-list-filesystems -al disk.img
/dev/sda1 ext4
/dev/vg_f12x32/lv_root ext4
/dev/vg_f12x32/lv_swap swap
$ virt-cat disk.img /dev/sda1 > boot.fs
$ file boot.fs
boot.fs: Linux rev 1.0 ext4 filesystem data (extents) (huge files)
$ virt-cat disk.img /dev/vg_f12x32/lv_root > root.fs

You can also use guestfish to examine the filesystem image:

$ guestfish -a boot.fs -m /dev/sda

Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.

Type: 'help' for help with commands
      'quit' to quit the shell

><fs> ll /
total 15941
dr-xr-xr-x.  5 root root     1024 Mar  8 19:37 .
dr-xr-xr-x  19 root root        0 Mar  8 13:40 ..
-rw-r--r--.  1 root root  1486532 Nov  7 21:38 System.map-
-rw-r--r--.  1 root root   103788 Nov  7 21:38 config-
drwxr-xr-x.  3 root root     1024 Mar  8 19:12 efi
drwxr-xr-x.  2 root root     1024 Mar  8 19:49 grub
-rw-r--r--.  1 root root 11253019 Mar  8 19:39 initramfs-
drwx------.  2 root root    12288 Mar  8 18:45 lost+found
-rwxr-xr-x.  1 root root  3454368 Nov  7 21:38 vmlinuz-

><fs> cat /grub/grub.conf 
# grub.conf generated by anaconda
# Note that you do not have to rerun grub after making changes to this file
# NOTICE:  You have a /boot partition.  This means that
#          all kernel and initrd paths are relative to /boot/, eg.
#          root (hd0,0)
#          kernel /vmlinuz-version ro root=/dev/mapper/vg_f12x32-lv_root
#          initrd /initrd-[generic-]version.img
title Fedora (
	root (hd0,0)
	kernel /vmlinuz- ro root=/dev/mapper/vg_f12x32-lv_root  LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=uk rhgb quiet
	initrd /initramfs-


1 Comment

Filed under Uncategorized

One response to “Tip: extract a filesystem from a disk image

  1. Pingback: Create a partitioned device from a collection of filesystems « Richard WM Jones

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.