4

I like to create a LVM device where physical volumes are loopback devices.

I have read lot of documents and tutorials, like this. Unfortunately all of them are based on the losetup command, which loses its configuration at next reboot.

I would make the LVM settings using FSTAB in place of the RC.LOCAL (where the losetup maybe scripted) in order to get my LVM running before some services startup, but I don't know how to reproduce into the FSTAB the command: "losetup /dev/loop0 /opt/my-data-file-0" and so on...

How could I accomplish this?

  • You may use your startup system to sort starting order of services to make them start after your LVM (I guess you use systemd ) example Wants=applications.service After=yourownLVMscript.service ( if an fstab solution exists I m also interested ) – francois P Jan 19 '18 at 21:24
  • @francoisP Maybe a solution, thank you very much! Further I should know if there is a way to implement the losetup command by the fstab setup, as stated in my post. – Antonio Petricca Jan 19 '18 at 21:59
2

I have found a convenient way to do this: two SystemD services:

/mnt/systemd/system/loops-setup.service

[Unit]
Description=Setup loopback devices

DefaultDependencies=no
Conflicts=umount.target

Requires=lvm2-lvmetad.service mnt-host.mount
Before=local-fs.target umount.target
After=lvm2-lvmetad.service mnt-host.mount

[Service]
ExecStart=/sbin/losetup /dev/loop0 <LOOPBACK_FILE>
ExecStop=/sbin/losetup -d /dev/loop0

RemainAfterExit=yes
Type=oneshot

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

/mnt/systemd/system/loops-fsck.service

[Unit]
Description=Loopback devices filesystem check

DefaultDependencies=no
Conflicts=umount.target

Requires=loops-setup.service
Before=local-fs.target umount.target mnt-loops-loop0.mount
After=loops-setup.service

[Service]
ExecStart=/sbin/fsck -pfv /dev/loop0

Type=oneshot

[Install]
WantedBy=local-fs-pre.target
  • I get that: Aug 21 04:06:42 node-b losetup[1077]: losetup: /dev/loop0: failed to set up loop device: No such file or directory.. Any idea why ? – dctremblay Aug 22 at 21:19
  • Please, post here the complete command you issued. – Antonio Petricca Nov 8 at 11:04

Your Answer

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

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