9

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?

3
  • 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
    Commented Jan 19, 2018 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. Commented Jan 19, 2018 at 21:59
  • This is actually answered on another SE site: superuser.com/questions/799162/permanent-loop-device Commented Jul 21, 2020 at 13:18

1 Answer 1

4

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
3
  • 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 ?
    – user234701
    Commented Aug 22, 2019 at 21:19
  • 1
    Please, post here the complete command you issued. Commented Nov 8, 2019 at 11:04
  • You probably don't need the latter unit file if you use fstab fsck column, like in e.g. superuser.com/questions/799162/permanent-loop-device Commented Aug 27, 2020 at 10:24

You must log in to answer this question.

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