2

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

[Unit]
Description=Setup loop device

[Service]

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

[Install]
WantedBy=default.target

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?

1 Answer 1

0

From https://giorgos.sealabs.net/systemd-unit-to-activate-loopback-devices-before-lvm.html

 [Unit]
 Description=Activate loop device
 DefaultDependencies=no
 After=systemd-udev-settle.service
 Before=lvm2-activation-early.service
 Wants=systemd-udev-settle.service

 [Service]
 ExecStart=/sbin/losetup /dev/loop0 /volume.img
 Type=oneshot 

 [Install]
 WantedBy=local-fs.target

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .