Take the 2-minute tour ×

I am trying to build a disk image as an output from my build system (currently SCons). Creating disk images from a directory structure is very easy to do, for example with genext2fs (http://genext2fs.sourceforge.net/).

But what I would like to do is to create an image that contains several partitions from multiple directories. I am currently having to do this by gluing together dd, losetup, kpartx, mount and copying files over. This requires root access.

Is there any convenient way to do this as a non-root user? Any application out there, suitable for inclusion into a build system that can perform this task efficiently?

share|improve this question

6 Answers 6

I hate to say it, but I don't know of an easy way to do this.

It's quite probable you could make something work by creating an image file with dd, then partitioning it with fdisk, then creating a second image file with dd, and formatting it directly (or using something like genext2fs), then dd'ing the second filesystem image into the first partitioned image file at the correct offset. . . however, that's going to be difficult and complicated.

I'm afraid I don't know of any good way to accomplish this without root access, though.

share|improve this answer

Depending on why you want to avoid root access, sudo might be a solution.

Write a script that does all the stuff you need to do for the task, making sure users can't misuse it with "creative" input, and then give the user in question sudo rights for exactly that script and nothing else.

share|improve this answer

you can try with mkisofs...

mkisofs -l -iso-level 4 -o file.iso folder

share|improve this answer

I haven't tried this, but have you tried fakeroot? It's commonly used on Debian-based distributions to bootstrap the initial set of files needed for an install (or in the case of a 64-bit system, a chroot with 32-bit files). You didn't say what OS you're using, fakeroot might not work for you.

I've seen this problem solved another way, use a virtual machine in the build system. In the VM you can be root without messing up the OS on your actual build machine, you can snapshot it so everytime it powers on it's at the same clean state.

share|improve this answer

Are the various partitions that you're creating known sizes?

You could work around the problem by creating a template 'disk image' with the partitions at known byte offsets, then splice the real filesystems into that image using dd.

share|improve this answer
  1. http://serverfault.com/a/332114/100216;
  2. if ISO9660 is generally fine with you, see also isohybrid script in syslinux distribution.
share|improve this answer

Your Answer

