Skip to content

Instantly share code, notes, and snippets.

@OhMeadhbh
Created January 8, 2020 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OhMeadhbh/269a433c428498db37d390a6cec22605 to your computer and use it in GitHub Desktop.
Save OhMeadhbh/269a433c428498db37d390a6cec22605 to your computer and use it in GitHub Desktop.
Hosting a Remote FileSystem that can do Links over CIFS
Hosting a Remote FileSystem that can do Links over CIFS
I’m in the process of migrating from one machine to another and it turns out that my home directory has exploded past the size of my largest external drive.
But I have a commercial NAS box that I rather like. But it’s setup to export a CIFS / SMB file system. I sort of like this since Linux, Mac and Windows all have decent support for SMB. But… it has one problem: links. CIFS *does not* like symbolic links.
So the solution I came up with was to create an image file on the NAS and mount it with losetup. Believe it or not, you can actually do this. Losetup will mount an image that’s hosted on a remote filesystem.
First, create an image file on the remote filesystem. You’ll need to know how big you want it. In this example, I’m making it about 370G, and the remote filesystem is mounted on /mnt/remote:
export FSIMAGE=/mnt/remote/filesystem.img
export FSSIZE=$((1024 * 363161073))
dd if=/dev/zero of=$FSIMAGE bs=1 count=0 seek=$FSSIZE
Now, use losetup to map that file to a /dev/loop device.
sudo losetup --show -f /mnt/remote/filesystem.img
This should print out the name of the loopback device the file was associated with. If you’re thinking about scripting this process, you can do this to store the loopback device in the FSDEV environment variable:
export FSDEV=`sudo losetup --show -f $FSIMAGE`
echo $FSDEV
If you forget what loopback device you’re using, use this command to list the current loopback associations:
sudo losetup -l
Now create a filesystem on this new image. You can go crazy with options, but I’m just making a simple ext4 filesystem:
sudo mkfs.ext4 $FSDEV
And you have to figure out where you want to mount it. In this example, I’m going to use /mnt/phenomenology and store it in the environment variable FSMNT.
export FSMNT=/mnt/phenomenology
sudo mkdir -p $FSMNT
sudo mount $FSDEV $FSMNT
And there you have it. To reverse the process, follow these steps:
# Unmount the filesystem
sudo umount $FSMNT
# Unassociate the loopback device
sudo losetup -d $FSDEV
And you should be good.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment