how to mount a file on another file












2















I am trying to mount /boot/config-4.14.90-v8 on to /usr/src/linux/.config. I've tried:



rpi-4.14.y:linux Necktwi$ sudo mount -o loop,ro -t vfat /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: cannot mount /dev/loop0 read-only.


notice the error cannot mount /dev/loop0 read-only.



rootfs is btrfs
/boot is vfat
/usr/src is nfs (I mounted remote server's /usr/src)





I tried mount --bind but it failed.



rpi-4.14.y:linux Necktwi$ sudo mount --bind /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: bind /boot/config-4.14.90-v8-g6d68e517b3ec failed.









share|improve this question

























  • What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

    – Thomas
    Jan 19 at 9:41











  • I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

    – neckTwi
    Jan 19 at 9:46


















2















I am trying to mount /boot/config-4.14.90-v8 on to /usr/src/linux/.config. I've tried:



rpi-4.14.y:linux Necktwi$ sudo mount -o loop,ro -t vfat /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: cannot mount /dev/loop0 read-only.


notice the error cannot mount /dev/loop0 read-only.



rootfs is btrfs
/boot is vfat
/usr/src is nfs (I mounted remote server's /usr/src)





I tried mount --bind but it failed.



rpi-4.14.y:linux Necktwi$ sudo mount --bind /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: bind /boot/config-4.14.90-v8-g6d68e517b3ec failed.









share|improve this question

























  • What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

    – Thomas
    Jan 19 at 9:41











  • I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

    – neckTwi
    Jan 19 at 9:46
















2












2








2


1






I am trying to mount /boot/config-4.14.90-v8 on to /usr/src/linux/.config. I've tried:



rpi-4.14.y:linux Necktwi$ sudo mount -o loop,ro -t vfat /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: cannot mount /dev/loop0 read-only.


notice the error cannot mount /dev/loop0 read-only.



rootfs is btrfs
/boot is vfat
/usr/src is nfs (I mounted remote server's /usr/src)





I tried mount --bind but it failed.



rpi-4.14.y:linux Necktwi$ sudo mount --bind /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: bind /boot/config-4.14.90-v8-g6d68e517b3ec failed.









share|improve this question
















I am trying to mount /boot/config-4.14.90-v8 on to /usr/src/linux/.config. I've tried:



rpi-4.14.y:linux Necktwi$ sudo mount -o loop,ro -t vfat /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: cannot mount /dev/loop0 read-only.


notice the error cannot mount /dev/loop0 read-only.



rootfs is btrfs
/boot is vfat
/usr/src is nfs (I mounted remote server's /usr/src)





I tried mount --bind but it failed.



rpi-4.14.y:linux Necktwi$ sudo mount --bind /boot/config-4.14.90-v8-g6d68e517b3ec /usr/src/linux/.config
mount: /usr/src/linux/.config: bind /boot/config-4.14.90-v8-g6d68e517b3ec failed.






mount






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 19 at 12:11







neckTwi

















asked Jan 19 at 9:20









neckTwineckTwi

3363615




3363615













  • What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

    – Thomas
    Jan 19 at 9:41











  • I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

    – neckTwi
    Jan 19 at 9:46





















  • What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

    – Thomas
    Jan 19 at 9:41











  • I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

    – neckTwi
    Jan 19 at 9:46



















What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

– Thomas
Jan 19 at 9:41





What are you actually trying to do? /boot/config-4.14.90-v8-g6d68e517b3ec is normally a ASCII file which does not hold a filesystem and cannot be mounted therefore.

– Thomas
Jan 19 at 9:41













I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

– neckTwi
Jan 19 at 9:46







I'm trying to maintain single /usr/src across network for different machines of different architectures. their kernel config differ but have same source files. so i want to mount respective kernel config on to /usr/src/linux/.config. some one at #linux suggested me to use loop to mount files.

– neckTwi
Jan 19 at 9:46












2 Answers
2






active

oldest

votes


















9














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.






share|improve this answer



















  • 1





    Nice one, didn't consider that one can bind-mount files.

    – Thomas
    Jan 19 at 10:42











  • I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

    – neckTwi
    Jan 19 at 12:05











  • mount --bind failed. edited the question with its output.

    – neckTwi
    Jan 19 at 12:15











  • @neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

    – filbranden
    Jan 19 at 16:21






  • 1





    don't know why it didn't work before!

    – neckTwi
    19 hours ago



















3














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".





share|improve this answer
























  • implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

    – neckTwi
    Jan 19 at 12:53











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495421%2fhow-to-mount-a-file-on-another-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









9














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.






share|improve this answer



















  • 1





    Nice one, didn't consider that one can bind-mount files.

    – Thomas
    Jan 19 at 10:42











  • I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

    – neckTwi
    Jan 19 at 12:05











  • mount --bind failed. edited the question with its output.

    – neckTwi
    Jan 19 at 12:15











  • @neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

    – filbranden
    Jan 19 at 16:21






  • 1





    don't know why it didn't work before!

    – neckTwi
    19 hours ago
















9














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.






share|improve this answer



















  • 1





    Nice one, didn't consider that one can bind-mount files.

    – Thomas
    Jan 19 at 10:42











  • I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

    – neckTwi
    Jan 19 at 12:05











  • mount --bind failed. edited the question with its output.

    – neckTwi
    Jan 19 at 12:15











  • @neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

    – filbranden
    Jan 19 at 16:21






  • 1





    don't know why it didn't work before!

    – neckTwi
    19 hours ago














9












9








9







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 19 at 10:03









filbrandenfilbranden

7,7552938




7,7552938








  • 1





    Nice one, didn't consider that one can bind-mount files.

    – Thomas
    Jan 19 at 10:42











  • I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

    – neckTwi
    Jan 19 at 12:05











  • mount --bind failed. edited the question with its output.

    – neckTwi
    Jan 19 at 12:15











  • @neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

    – filbranden
    Jan 19 at 16:21






  • 1





    don't know why it didn't work before!

    – neckTwi
    19 hours ago














  • 1





    Nice one, didn't consider that one can bind-mount files.

    – Thomas
    Jan 19 at 10:42











  • I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

    – neckTwi
    Jan 19 at 12:05











  • mount --bind failed. edited the question with its output.

    – neckTwi
    Jan 19 at 12:15











  • @neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

    – filbranden
    Jan 19 at 16:21






  • 1





    don't know why it didn't work before!

    – neckTwi
    19 hours ago








1




1





Nice one, didn't consider that one can bind-mount files.

– Thomas
Jan 19 at 10:42





Nice one, didn't consider that one can bind-mount files.

– Thomas
Jan 19 at 10:42













I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

– neckTwi
Jan 19 at 12:05





I always use --bind to mount one directory on to another. Damn, I should have just tried with files!

– neckTwi
Jan 19 at 12:05













mount --bind failed. edited the question with its output.

– neckTwi
Jan 19 at 12:15





mount --bind failed. edited the question with its output.

– neckTwi
Jan 19 at 12:15













@neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

– filbranden
Jan 19 at 16:21





@neckTwi Bind mount should have worked. As soon as both source and target are regular files (or both are directories, but not mixed one regular file and one directory), it should work. If that's really the case, can you check whether there is something else on your system (like SELinux or AppArmor perhaps) which might be blocking the mount? Check dmesg, audit and system logs... Otherwise, try running the command under strace to see if you find the actual errno of the mount failure, that might be helpful too.

– filbranden
Jan 19 at 16:21




1




1





don't know why it didn't work before!

– neckTwi
19 hours ago





don't know why it didn't work before!

– neckTwi
19 hours ago













3














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".





share|improve this answer
























  • implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

    – neckTwi
    Jan 19 at 12:53
















3














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".





share|improve this answer
























  • implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

    – neckTwi
    Jan 19 at 12:53














3












3








3







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".





share|improve this answer













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".






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 19 at 10:01









ThomasThomas

3,77661326




3,77661326













  • implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

    – neckTwi
    Jan 19 at 12:53



















  • implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

    – neckTwi
    Jan 19 at 12:53

















implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

– neckTwi
Jan 19 at 12:53





implemented your solution. I hope those software that check for kernel config, check the KCONFIG_CONFIG.

– neckTwi
Jan 19 at 12:53


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f495421%2fhow-to-mount-a-file-on-another-file%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

William S. Burroughs

Eda skans

1924