User Tools

Site Tools


losetup

This is an old revision of the document!


losetup for LVM

When using a loop file for backing LVM, it is necessary to start `losetup` before LVM can start. This is easily done using systemd and putting it into startup. This example service unit uses Ubuntu 24.04

Create the file /etc/systemd/system/loops-setup.service

[Unit]
Description=Setup loopback devices

DefaultDependencies=no
Conflicts=umount.target

Requires=-.mount
Before=local-fs.target umount.target
After=-.mount

[Service]
ExecStart=/sbin/losetup /dev/loop0 /data-disk.img
ExecStop=/sbin/losetup -d /dev/loop0

RemainAfterExit=yes
Type=oneshot

[Install]
WantedBy=local-fs-pre.target

Add the service to startup and start it

systemctl enable --now loops-setup.service

losetup --list
NAME       SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE      DIO LOG-SEC
/dev/loop0         0      0         0  0 /data-disk.img   0     512
losetup.1761928775.txt.gz · Last modified: 2025/10/31 12:39 by ian

free spam filter