Interesting. Just found this. Very good tutorial.
I ended up doing the same thing with a loop device but I did that just to use a network-attached drive (storage box from Hetzner).
For attaching the drive I used SAMBA/CIFS.
So if anybody is interested in doing the same, before the tutorial above, just do this:
Install CIFS Utils:
sudo apt install cifs-utils
Create a folder to use as a link to the storage box:
sudo mkdir /data/storagebox
Prepare the CIFS connection. Add your credentials to the file and protect it:
sudo vim /etc/credentials.txt
sudo chmod 600 /etc/credentials.txt
Put your storage box SAMBA credentials in the /etc/credentials.txt
file in this format:
username=u123456
password=your_password_here
Add to /etc/fstab
: (this will auto-connect in case of reboot)
//u123456.your-storagebox.de/backup /data/storagebox cifs credentials=/etc/credentials.txt,cache=none,_netdev,x-systemd.automount,x-systemd.mount-timeout=30 0 0
Create the sparse file
sudo dd if=/dev/zero of=/data/storagebox/block.img bs=1 count=0 seek=900G
Create a device service:
sudo vim /etc/systemd/system/loop-storage.service
Add:
[Unit]
Description=Setup storage loop device
After=remote-fs.target
Requires=remote-fs.target
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/sbin/losetup -f /data/storagebox/block.img
ExecStop=/sbin/losetup -d $(losetup -j /data/storagebox/block.img | cut -d ':' -f1)
[Install]
WantedBy=multi-user.target
Enable and start service:
sudo systemctl daemon-reload
sudo mount -a
sudo systemctl enable loop-storage
sudo systemctl start loop-storage
Done!
The loop device will be available at /dev/loop0
for your backup service to use.