dawncold
dawncold

Reputation: 183

Can't make hard link for mounted host file in LXD container

I configed a host directory as a disk device in an unprivileged LXD container, like /opt/app/var, and I created a backup directory on container self filesystem, like /backup.

I used rsync to backup /opt/app/var files to /backup with hard link, but I got Invalid cross-device link

lxd container device config:

devices:
  var:
    path: /opt/app/var
    source: /opt/app/var
    type: disk

in container:

$ cat /proc/mounts | grep opt
/dev/sda2 /opt/app/var ext4 rw,relatime,stripe=64,data=ordered 0 0

$ cat /proc/mounts | grep "/ "
/dev/sda2 / ext4 rw,relatime,stripe=64,data=ordered 0 0

$ cat /etc/fstab
LABEL=cloudimg-rootfs   /    ext4   defaults    0 0

I found the mountpoint made by lxd is from /dev/sda2, and the root partition mountpoint is from /dev/sda2 too, so it should be on a same device.

Upvotes: 2

Views: 314

Answers (1)

MikeBergmann
MikeBergmann

Reputation: 419

This is not a container issue. You cannot create hard links across mount points, even when it’s the same device you (bind) mounted to different places in your FS hierarchy.

Try this on your system:

> cd /tmp/
> mkdir bar
> mkdir barm1
> mkdir barm2
> sudo mount --bind bar barm1 
> sudo mount --bind bar barm2
> cd barm1
> echo foo > foo
> ll ../barm2/ 

drwxr-xr-x   2 user users   4096 Jul 13 15:56 ./
drwxrwxrwt. 19 root root  147456 Jul 13 15:57 ../
-rw-r--r--   1 user users      4 Jul 13 15:56 foo

> cp --link foo ../barm2/foo2

cp: cannot create hard link '../barm2/foo2' to 'foo': Invalid cross-device link

Upvotes: 1

Related Questions