[TriLUG] non-root partial view of file?

Kevin Hunter Kesling hunteke at earlham.edu
Fri Jan 16 08:41:19 EST 2015


Hi List,

I'm having some version of fun playing with disk images.  If a disk 
image has multiple partitions (e.g., a raw read of a drive: dd 
if=/dev/sda of=./my_disk_img), it's relatively encapsulate access to 
each partition through the loopback interfaces.  Two methods here (for 
completeness or edification):

       # You happen to know the byte offset of the partitions
     $ sudo losetup -o 1M /dev/loop0 disk.img
     $ sudo losetup -o 128MiB /dev/loop1 disk.img

     $ sudo mount /dev/loop0 ./boot/
     $ sudo mount /dev/loop0 ./img_root/

       # or easier, utilize kpartx:
     $ sudo kpartx -a -v ./disk.img
     add map loop0p1 (252:0): 0 260096 linear /dev/loop0 2048
     add map loop0p2 (252:1): 0 18610176 linear /dev/loop0 262144

       # which are now accessible via /dev/mapper/loop0p{1,2}

Awesome.  Now my (perhaps academic) questions: why do I need root to 
work with only a section of these large files?  Well, I assume because 
that's how the partition-level tools (e.g., e2fsprogs) are written.  But 
is there not a method for encapsulating access like this that does *not* 
require root?  I mean, at the point I'm writing bits to a single file, 
why do I need special authority?

Thanks,

Kevin


More information about the TriLUG mailing list