linux – 任何不起作用的相对路径(从initramfs运行时)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了linux – 任何不起作用的相对路径(从initramfs运行时),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含5941字,纯文字阅读大概需要9分钟。
内容图文
![linux – 任何不起作用的相对路径(从initramfs运行时)](/upload/InfoBanner/zyjiaocheng/957/f50d1880d89048f0aaf0f4b6a9782ecd.jpg)
我正在使用嵌入式Linux系统,试图让它使用initramfs在ram中启动它的根文件系统.系统大部分都出现了,但是在init脚本中遇到了麻烦.我把问题缩小到以下几点.
系统无法识别任何相对路径.让我解释一下……
符号链接不仅指向相对位置的文件被破坏,而且只是运行这样的简单命令也不起作用:
$pwd
/etc/network
$cat ../inittab
cat: can't open '../inittab': No such file or directory
但这很好用:
$cat /etc/inittab
<inittab output ...>
知道会发生什么吗?
UPDATE1
标准ls ..命令似乎按预期运行.另外,我认为inode引用看起来不错?
$ls ..
default/ inputrc moduli random-seed ssh_config sshd_config
dhcp/ issue mtab@ resolv.conf@ ssh_host_dsa_key ssl/
fstab ld.so.conf network/ rsyslog.conf ssh_host_dsa_key.pub sysconfig/
fstab.bak ld.so.conf.d/ nsswitch.conf rsyslog.d/ ssh_host_ecdsa_key ts.conf
group logrotate.conf os-release screenrc* ssh_host_ecdsa_key.pub udev/
hostname logrotate.d/ passwd securetty ssh_host_key
hosts ltrace.conf passwd- services ssh_host_key.pub
init.d/ memstat.conf profile shadow ssh_host_rsa_key
inittab mke2fs.conf protocols shadow- ssh_host_rsa_key.pub
$cd / ; ls -lid /etc
1547 drwxr-xr-x 12 root root 0 Jan 1 00:49 /etc/
$cd /etc ; ls -lid .
1547 drwxr-xr-x 12 root root 0 Jan 1 00:49 ./
$cd /etc/network ; ls -lid ..
1547 drwxr-xr-x 12 root root 0 Jan 1 00:49 ../
通过更多的挖掘,我发现相对路径的工作时间很长,因为您没有跨越文件系统根的“边界”:
$cd usr/
$ls ../etc
ls: ../etc: No such file or directory
$cd ../etc
$cd network/
$ls ..
default/ inputrc moduli random-seed ssh_config sshd_config
dhcp/ issue mtab@ resolv.conf@ ssh_host_dsa_key ssl/
fstab ld.so.conf network/ rsyslog.conf ssh_host_dsa_key.pub sysconfig/
fstab.bak ld.so.conf.d/ nsswitch.conf rsyslog.d/ ssh_host_ecdsa_key ts.conf
group logrotate.conf os-release screenrc* ssh_host_ecdsa_key.pub udev/
hostname logrotate.d/ passwd securetty ssh_host_key
hosts ltrace.conf passwd- services ssh_host_key.pub
init.d/ memstat.conf profile shadow ssh_host_rsa_key
inittab mke2fs.conf protocols shadow- ssh_host_rsa_key.pub
$ls ../../usr
ls: ../../usr: No such file or directory
这让我相信我没有正确安装根文件系统.也许这个输出是最有说服力的?
$df
Filesystem Size Used Available Use% Mounted on
devtmpfs 204.2M 0 204.2M 0% /dev
tmpfs 251.7M 0 251.7M 0% /dev/shm
tmpfs 251.7M 76.0K 251.6M 0% /tmp
UPDATE2
经过额外的搜索,我相信the following最能描述我的场景:
2) The newer initial ramfs image, initramfs. Here one populates a
directory, and then creates a compressed cpio archive which is
expanded into ramfs upon boot and becomes the root filesystem. The
kernel must be configured with CONFIG_BLK_DEV_INITRD=y but one does
not need to set CONFIG_BLK_DEV_RAM_SIZE, nor does one need to set
CONFIG_TMPFS=y. When the system is up, “df” does not report the root
filesystem and one cannot interact with it by doing things like “mount
–bind / dir”. Also the distinction between what RAM is set aside for the filesystem and what RAM is used for processes is blurred. “df”
reports nothing and “free” reports total usage without distinction,
ie. used RAM = RAM used for files (as reported by “du”) plus RAM used
for processes.
但是,我对此感到有些惊讶.这是否暗示我在使用initramfs时无法在文件系统的根目录之间进行交互?
UPDATE3
This post表明我想要完成的事情并非不合理:
Now normally an initramfs is temporary, only used to run some programs
extremely early in the boot process. After those programs run, control
is turned over to the real filesystem running on a physical disk.
However you do not have to do that. There is nothing stopping you from
running out of the initramfs indefinitely
如何无限期地用完initramfs但又能够遍历文件系统的根目录?
解决方法:
阅读this post后,问题解决了!
我注意到在运行mount命令时出现了两个条目/:
rootfs on / type rootfs (rw,relatime)
devtmpfs on /dev type devtmpfs (rw,relatime,size=209064k,nr_inodes=52266,mode=755)
proc on /proc type proc (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,relatime,mode=777)
tmpfs on /tmp type tmpfs (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
none on / type tmpfs (rw,relatime)
我添加了一个我需要删除的fstab条目:
# /etc/fstab: static file system information.
#
# <file system> <mount pt> <type> <options> <dump> <pass>
none / tmpfs defaults 0 0
proc /proc proc defaults 0 0
devpts /dev/pts devpts defaults,gid=5,mode=620 0 0
tmpfs /dev/shm tmpfs mode=0777 0 0
tmpfs /tmp tmpfs defaults 0 0
sysfs /sys sysfs defaults 0 0
删除条目(并执行重新启动)后:
none / tmpfs defaults 0 0
问题消失了!
内容总结
以上是互联网集市为您收集整理的linux – 任何不起作用的相对路径(从initramfs运行时)全部内容,希望文章能够帮你解决linux – 任何不起作用的相对路径(从initramfs运行时)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。