5

I have a whole-drive image file containing a partition table and some partitions. I would like to list and read files from an ext2/ext3 partition inside this file.

Using root priveleges, it is somehow complicatied but possible to mount into some offset of the image file, thus mounting a partition inside the image like a real one.

Is there any chance of accessing the data without root privileges?

dronus
  • 1,978

4 Answers4

2

e2tools

Ah, i knew there had to be a better way. On ubuntu:

$ sudo apt-get install e2tools

Then:

$ e2ls image.ext2
myfile foo bar baz
$ e2cp image.ext2:/myfile /tmp

etc

Of course if you're not root you can't use apt-get: download e2tools binary package from packages.ubuntu.com and install it in your home dir like in the fs-utils answer.

lemonsqueeze
  • 1,330
0

qemu

An easy (but heavy) way to do this is to use qemu to start a vm and access the files from there. You don't need root and this works even you only have read-only access to the image. It's going to be really slow though ...

Using your favorite mini distribution:

qemu -cdrom tomsrtbt.iso -hda disk_image -boot order=d
lemonsqueeze
  • 1,330
0

Other machine + network

If you are root on another machine and have network access to the server where the disk image is stored, there's a good chance you can use some kind of network filesystem (sshfs, httpfs, ftpfs, samba, nfs ...) to map the file locally, at which point you can mount it as root as usual.

lemonsqueeze
  • 1,330
0

fs-utils

Looks like fs-utils might be the generic solution here:

The aim of this project is to have a set of utilities to access and modify a file system image without having to mount it. To use fs-utils you do not have to be root, you just need read/write access to the image or device. The advantage of fs-utils over similar projects such as mtools is supporting the usage of familiar Unix tools ( ls , cp , mv , etc.) for a large number of file systems.

Linux is supported and there are binary packages available (make sure you also get the rump kernel components on which it is based). Since we're not root we need to install them in our home directory (~/usr for example):

$ mkdir ~/usr ; cd ~/usr
$ dpkg-deb --fsys-tarfile ../netbsd-rump_20140405_i386.deb | tar -xvf -
$ dpkg-deb --fsys-tarfile ../netbsd-fs-utils_1.10_i386.deb | tar -xvf -

Add this to ~/.bashrc:

export PATH="$HOME/usr/bin:$PATH"
export LD_LIBRARY_PATH="$HOME/usr/lib"

Then you can:

$ fsu_ls -t ext2fs image.ext2 -l
total 2
-rw-r--r--  1 0  0  12 Apr  9 12:45 a_file.txt
$ fsu_cat -t ext2fs image.ext2 a_file.txt
just a demo

The filesystem names are a little different than usual: msdos instead of vfat, ext2fs instead of ext2, cd9660 instead of iso9660 etc.

Notes:
- Somehow on my system it works with vfat but not ext2 images. I didn't do a full fs-tools build though, and instead tried a binary package which wasn't an exact match for my distro (which might be why...)
- It looks like the offset=... mount option isn't supported, so to access a partition inside a whole disk image there seems to be little choice but to copy it out first ...

lemonsqueeze
  • 1,330