Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have built a home-grown Linux distribution, and I can make the complete disk image file as a non-root user with one exception -- installing the boot loader. I'm using syslinux (actually extlinux), and to install it I have to loop-back mount the boot partition, which requires root/sudo privileges. The commands are run from a makefile, and the variable names should clearly indicate what to replace them with.

sudo losetup -o $(BOOT_FS_PARTITION_OFFSET) $(LOOP_DEVICE) $(IMAGE_FILE_NAME)
sudo mount $(LOOP_DEVICE) $(LOOP_MOUNT_POINT)
sudo $(EXTLINUX) -S $(DISK_SECTORS) -H $(DISK_HEADS) -i $(LOOP_MOUNT_POINT)
sudo umount $(LOOP_MOUNT_POINT)
sudo losetup -d $(LOOP_DEVICE)

Is there a way to write syslinux or extlinux to the disk image file without requiring root privileges?

share|improve this question

migrated from embedded.stackexchange.com Jun 9 at 20:48

This question came from our site for designers and programmers of embedded devices.

    
Are you wondering if it is possible to do all those commands without root? Or just the extlinux command? –  BenjiWiebe May 20 at 19:37
    
@BenjiWiebe If there is another way, then whatever commands are required, but as I understand it you need a mounted file system in order to run extlinux, and then extlinux needs to run with root privileges when done this way. –  Patrick May 20 at 19:41
    
+1 for being the first to accept an answer ;) –  Johan Bezem May 21 at 16:35

2 Answers 2

up vote 8 down vote accepted

This is possible for syslinux:

syslinux ~/floppy.ima

The syslinux installer contains enough magic to be run on an unmounted filesystem. (In fact, it is designed to do that.) The extlinux installer expects to be run on a mounted filesystem, though.

It is almost certainly possible to split off the extlinux installer into a part that copies the files (something like mtools for FAT, which is rare but appears to exist, although one could just integrate them directly with genext2fs), and a part that installs the bootsector (I might be able to cobble this together).

I did something like this for GRUB 2, which installs into the space between the MBR and the first partition, for Grml; this was actually easier to do because GRUB, unlike SYSLINUX, does not require as much from the bootsector. It basically depends on your broader requirements. If the above part about SYSLINUX does not help you, contact me, so we can work something out.

share|improve this answer
    
Thank you for this info. I am using genext2fs, so your suggestion sounds like the best option. Is it simply a matter of dd'ing the extlinux code into the MBR and copying the files to the fs, or do the files need to go in certain blocks within the fs? –  Patrick May 21 at 14:33
    
I've not yet looked at EXTLINUX in detail (will do so and then delete this comment, but give me a bit of time) but for SYSLINUX, LILO, GRUB and other bootloaders, it's usually so that the code is copied into the PBR (partition boot record, vulgo bootsector, not MBR), and then the code is edited to have the position of the file hardcoded in it (hence the need for an installer). I'll cobble something together for you. –  mirabilos May 21 at 18:01
    
@Patrick I have some need for discussion on this, I opened a chat –  mirabilos May 24 at 15:55

If you add a line in /etc/fstab saying something like:

/dev/loop0      /mnt                                    ext4    defaults,user   0 0

you can then mount/unmount /dev/loop0 as a regular user.

And if you do chown youruser:youruser <MOUNTPOINT> <LOOPDEVICE> then extlinux , losetup, mkfs, etc can be done as youruser.

share|improve this answer
    
I want this to be part of a generic build process, and the location of the image file and mount point can vary from user to user. I would prefer not to require editing fstab for each user. –  Patrick May 21 at 14:35
    
@Patrick Editing fstab is global. –  BenjiWiebe May 21 at 16:15

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.