最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【整理】Buildroot生成的output/target下面的根文件系统rootfs不能直接使用:设备文件不是root权限

Buildroot crifan 11472浏览 0评论

【背景】

折腾:

【记录】尝试分析Buildroot在make menuconfig后make时的内部执行逻辑

期间,看到其中一行log是:

make[1]: Leaving directory `/home/CLi/develop/buildroot/buildroot-2013.05'
...
cp support/misc/target-dir-warning.txt /home/CLi/develop/buildroot/buildroot-2013.05/output/target/THIS_IS_NOT_YOUR_ROOT_FILESYSTEM

此时,想要去看看其中target-dir-warning.txt的内容,即:

D:\tmp\tmp_dev_root\cgwin\home\CLi\develop\buildroot\buildroot-2013.05\output\target\THIS_IS_NOT_YOUR_ROOT_FILESYSTEM

中的内容。

其内容如下:

Warning!

========

This directory does *not* contain the root filesystem that you can use

on your embedded system. Since Buildroot does not run as root, it

cannot create device files and set the permissions and ownership of

files correctly in this directory to make it usable as a root

filesystem.

For that reason, do *not* use the contents of this directory to mount

your root filesystem over NFS or copy the contents of this directory

to a SD card or USB key, thinking it will work as the root filesystem

for your embedded system. It will simply *not* work.

Instead, if you need a usable root filesystem, please select one of

the filesystem image formats available in the Buildroot configuration

interface (make menuconfig or others) in the "Filesystem images"

sub-menu. If you want to get a filesystem image that you can easily

extract to your SD card or to some directory exposed through NFS,

please use the "tar the root filesystem" option. It will generate a

images/rootfs.tar image in your Buildroot output directory, which you

can extract as root:

  sudo tar -C /destination/of/extraction -xf images/rootfs.tar

Those image files are created using the contents of the target/

directory, but there is a post-processing step to create device files

and set owernship/permissions properly even if Buildroot does not run

as root.

意思是:

由于Buildroot不是以root权限运行的

(而创建设备,然后保证能在嵌入式系统中,以rootfs使用的前提是:设备都是root创建的)

所以,此处这些文件夹

(虽然包含了bin,dev,等等文件夹)

但是不能直接拿到嵌入式系统中去用

即:

不能直接用NFS挂载

不能直接拷贝到SD卡(拿到嵌入式系统中去用)

而,想要从Buildroot中获得,可用的rootfs的正确的做法是:

根据你在Buildroot中menuconfig配置时,所选择的

"Filesystem images"

即,文件系统镜像

然后选上

"tar the root filesystem"

即,打包根文件系统

则Buildroot最后是可以生成对应的:

images/rootfs.tar

的,该文件内部的文件,才是root权限的(比如各种设备文件,才是root创建的,才可以正常在嵌入式系统中使用)

然后你可以将其解压:

sudo tar -C /destination/of/extraction -xf images/rootfs.tar

而得到,真正的是root权限的rootfs。

原因是:

虽然上述的images/rootfs.tar也是和当前target文件夹下的内容一样

但是是经过后续处理的:

创建了对应的设备文件,并且设置了文件的属于root(估计是用的chown)

如此,才使得此rootfs可以正常在嵌入式系统中使用。

 

然后,也想起来,之前就遇到类似的问题的:

【workaround】buildroot下面make编译,最后生成的rootfs中的特殊的设备文件,实际是普通文件

 

【总结】

其实人家Buildroot已经做得很好了,只是我们不是足够清楚,所以有时候才闹误会而已。

转载请注明:在路上 » 【整理】Buildroot生成的output/target下面的根文件系统rootfs不能直接使用:设备文件不是root权限

与本文相关的文章

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
83 queries in 0.173 seconds, using 22.99MB memory