Access data from a linux partition inside an image without root privileges

4

2

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

Posted 2014-10-14T22:01:47.210

Reputation: 1 482

Permission to mount is a root privilege because mounting can impact security (for example where you might mount something over /etc/ containing your own password files). There are a bunch of ways to give a normal user mount rights though, but the admin must give them. Is this possible? – Paul – 2014-10-14T22:59:23.837

Wouldn't mounting over something be denied by the users access right? And whats wrong with an user mounting over folders he owns? – dronus – 2014-10-15T00:52:23.773

Nothing. But you can't do this without permission from a root admin - via fstab, udisks, polkit or some other method. – Paul – 2014-10-15T01:52:07.017

Maybe there is any way doing this via FUSE ? – dronus – 2014-11-01T12:15:18.923

Yes, by FUSE too, but once you get authorisation from the admin. The best bet is the answer below, just extract the contents of the ISO if you need the contents, rather than trying to mount it – Paul – 2014-11-02T00:56:09.600

Answers

1

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

Posted 2014-10-14T22:01:47.210

Reputation: 1 151

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

Posted 2014-10-14T22:01:47.210

Reputation: 1 151

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

Posted 2014-10-14T22:01:47.210

Reputation: 1 151

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

Posted 2014-10-14T22:01:47.210

Reputation: 1 151