I want to use a systemd --user .service to map an image file to a loop device at user login. The the service resides in /etc/systemd/user. The image in question resides in /home/$USER/my.img

Description=Setup loop device


ExecStart=/usr/sbin/losetup /dev/loop0 /home/john/my.img


The unit fails with

losetup: /dev/loop1: failed to set up loop device: Permission denied

I understand losetup can not be called by a user. Placing the unit in /etc/systemd/system works, but accessing the file prompts the sudo password, witch i want to avoid.

How should i proceed?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.