First question – what is the purpose? Such fake loop device can be used as pv in lvm in case we want to play around and don’t want to add a new disk.
- Prepare a binary file with dd e.g. /srv/swift-disk.bin
- Create a script in e.g: /usr/lib/systemd/scripts and ensure that it is executable:
1 2 3 4 5 6 |
#!/bin/sh - do_loop() { losetup /dev/loop0 /srv/swift-disk.bin } do_loop |
- Create a service in: /usr/lib/systemd/system
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
[Unit] Description=Setup loop devices for swift DefaultDependencies=false ConditionFileIsExecutable=/usr/lib/systemd/scripts/swift-loop Before=local-fs.target After=systemd-udev-settle.service #Require=systemd-udev-settle.service [Service] Type=oneshot ExecStart=/usr/lib/systemd/scripts/swift-loop TimeoutSec=60 RemainAfterExit=yes [Install] WantedBy=local-fs.target Also=systemd-udev-settle.service |
- Enable and start a service:
1 2 |
systemctl enable swift-loop.service systemctl start swift-loop.service |