how to mount a file on another file

If you want to mount a single file, so that the contents of that file are seen on the mount point, then what you want is a bind mount.

You can accomplish that with the following command:

# mount --bind /boot/config-4.14.90-v8 /usr/src/linux/.config

You can use -o ro to make it read-only on the /usr/src/linux/.config path.

For more details, look for bind mounts in the man page for mount(8).


Loop devices do something similar, yet different. They mount a filesystem stored into a regular file onto another directory.

So if you had a vfat or ext4 etc. filesystem stored into a file, say /vol/myfs.img, you could then mount it into a directory, say /mnt/myfs, using the following command:

# mount -o loop /vol/myfs.img /mnt/myfs

You can pass it -t vfat etc. to force the filesystem type.

Note that the -o loop is usually not needed, since mount will figure that out by you trying to mount a file and will do that for you automatically.

Also, mounting a file with -o loop (or automatically detected) is a shortcut to mapping that file to a /dev/loopX device, which you can also do using losetup, and then running the mount command, such as mount /dev/loop0 /mnt/myfs. See the man page for losetup(8) for details on loop devices.


While you cannot mount a normal file, you could create a symbolic link /usr/src/linux/.config pointing to the specific local kernel config file. As your configs differ, this method has its own traps as you also would have to maintain a symbolic link locally like /boot/config-default pointing to the actual config file which then can be used in the NFS share.

Better would be to use the environment variable KCONFIG_CONFIG to point to alternate kernel configuration file.

make menuconfig KCONFIG_CONFIG=/boot/config-4.14.90-v8

From kernel.org:

KCONFIG_CONFIG
--------------------------------------------------
This environment variable can be used to specify a default kernel config
file name to override the default name of ".config".

Tags:

Mount