# mount --move equivalent on FreeBSD?



## jyhpsycho (Mar 13, 2014)

On Linux, I can "move" the mountpoint of filesystem which is already mounted. But, there's no any mention about that on FreeBSD's mount(8) man page. Is FreeBSD not supports this? If it is possible, how to do this?


----------



## SirDice (Mar 13, 2014)

Can't you simply unmount it and mount it again where you want?


----------



## jyhpsycho (Mar 13, 2014)

Because it cannot be unmounted. I need to "move" /dev which is automatically mounted by FreeBSD kernel to another path, but it really possible?


----------



## asteriskRoss (Mar 13, 2014)

*Caveat: I am no expert on the Linux kernel!* The Linux kernel appears to have some functionality where filesystems can be mounted in multiple locations at the same time.  Mounting a filesystem in one location and using a symbolic link (described in ln(1)) to make it accessible by another path at the same time would feel more natural to me, but horses for courses.  I am wondering whether the `mount --move /oldmountpoint /newmountpoint` GNU/Linux command is part of that, thereby making "moving" a mounted filesystem different from unmounting and remounting.  Since you asked the question, you may know more about how this functionality has been implemented.  I would be intrigued know when it might be useful.

So, expanding on @SirDice's answer, I don't believe FreeBSD has a direct equivalent, though you can achieve the same end by unmounting and remounting.  For example, for a mounted UFS device /dev/example0 and desired new mountpoint /newmountpoint:
`# umount /dev/example0 && mount /dev/example0 /newmountpoint`


----------



## asteriskRoss (Mar 13, 2014)

@@jyhpsycho: I just saw your reply which was posted before mine.  Perhaps you should tell us what your end goal is, since redesigning the FreeBSD filesystem hierarchy just for your system strikes me as an onerous journey to your destination.

 Would creating a symbolic link to /dev be a viable alternative?  Something like: `# ln -s /dev /path/to/desired/location/dev`


----------



## jyhpsycho (Mar 13, 2014)

My goal is loading full filesystem hierarchy(root) into memory(mdX device in FreeBSD) and remove any dependency of disk stroage. I can replace any storage device even system disk if that works. I used Linux with that setting before - it can be used with traditional /dev/ramX device, tmpfs, zram(compressed block device like `mdconfig -o compress`).

Yes, I found that init supports init_script and init_chroot a while ago. I thought init process should be rewritten to achieve my goal before I know that. But there's still some issues what I posted question here.


```
# mount
/dev/md0 on / (ufs, local, read-only)
devfs on /dev (devfs, local, multilabel)
zroot in /zroot (zfs, local, nfsv4acls)
devfs on /zroot/dev (devfs, local, multilabel)
```

There's some unneeded entries - /dev/md0 and devfs on /dev. On Linux, /dev can be moved into chroot'd path, and used memory by rootfs(tmpfs-like root filesystem which cpio-style initrd image used by recent Linux kernel loads on) can be reclaimed by deleting all contents of rootfs during early-userspace booting process.
https://www.kernel.org/doc/Documentation/filesystems/ramfs-rootfs-initramfs.txt

But on FreeBSD, that's impossible for me to unmount /dev or unmount /dev/md0. After chroot, that just consumes system resources. Is there any way to deal with?


----------



## asteriskRoss (Mar 13, 2014)

An interesting project   I had vague memories of reading about "mfsroot" systems in relation to PXE boot.  Searching turned up Martin Matuška's mfsBSD project.  This may do what you need, or at least be a step in the right direction.  From this article on remote installation:


> The mfsBSD tool-set can be used to build a tiny FreeBSD image. As the name of mfsBSD suggests (“mfs” means “memory file system”), the resulting image runs entirely from a ramdisk.



The mfsBSD page does include the following warning:


> Your image should not exceed 45MB in total, otherwise kernel panic may occur on boot-time.



Given the limitation, I wonder whether it would be possible to have a initialisation script in the small image create another memory file system to hold anything else you might need, such as X.Org and desktop applications.  Someone may know (and post) or otherwise I would be interested to hear how you get on.


----------



## wblock@ (Mar 13, 2014)

The ZFS version of mfsBSD is larger than 45M anyway, so there are ways around the size limitation.


----------



## jyhpsycho (Mar 14, 2014)

Thanks, but there are some limitation...

Basically, mfsBSD uses mfsroot feature, which has space limitation related on kernel address space. That is adjustable, but isn't sufficient for me. I need to use very large image(over 2 GB) contains full system includes system sources and ports tree, thus it's impossible to load using mfsroot directly. I tried that before, but it just hangs.

I downloaded special edition image, and run it right now. It works similar way as I thought one - use small mfsroot image for loading system into another location. I implemented init script that create new md device, create zfs on it, and copy root file system to it a few hours ago. It consumes less than 2GB for full installed system because I turned on lz4 compression at some location such as /usr/ports, /usr/src. mfsBSD uses tmpfs instead of md device.

There's still issues that "There's NO way to cleanup unneeded parts" on mfsBSD too, even size of /dev/md0 is 32MB which is bigger than mine(<16MB)! Is it impossible which I want?


----------



## jyhpsycho (Mar 14, 2014)

Here how to increase the limit of mfsroot on i386.
http://www.michaelmiranda.org/software-development/articles/hawaiisidentitytheftlaw

But I use amd64, and there's no macro named NKPT and KVA_PAGES... I know there's practically no limitation on 64-bit architecture as of right now, thus that macros are not needed. But if so, why loading image around 2GB fail? My system has 48GB memory...


----------



## SirDice (Mar 14, 2014)

jyhpsycho said:
			
		

> Because it cannot be unmounted. I need to "move" /dev which is automatically mounted by FreeBSD kernel to another path, but it really possible?


No, that's not possible. It is however possible to mount devfs(5) multiple times.


```
dice@molly:~> mount | grep devfs
devfs on /dev (devfs, local, multilabel)
devfs on /jails/j-internetz/dev (devfs, local, multilabel)
```


```
dice@armitage:~ % mount | grep devfs
devfs on /dev (devfs, local, multilabel)
devfs on /jails/webtrees/dev (devfs, local, multilabel)
devfs on /jails/ports/dev (devfs, local, multilabel)
devfs on /jails/mysql/dev (devfs, local, multilabel)
```


----------



## jyhpsycho (Mar 19, 2014)

Hmm... It seems there's no better way; Thanks.


----------

