linux初始化脚本不能进目录,linux - busybox初始化脚本。 找不到挂载 - 堆栈内存溢出...

我正在尝试看似有点奇怪的东西。

基本计算机是Ubuntu 18.04。 我正在尝试创建一个自定义initramfs + init脚本,以与正与qemu实例一起使用的自定义编译内核一起使用。

从目录中,我将其用作initramfs的基础:

[~/initramfs] $ find .

.

./proc

./root

./dev

./dev/console

./dev/sda1

./dev/null

./dev/tty

./sbin

./init

./etc

./lib64

./mnt

./mnt/root

./lib

./bin

./bin/busybox

./sys

只是目前所需的基础知识。 busybox二进制文件来自busybox-static软件包,我已经确认它是静态遵从的:

[~/initramfs]$ ldd bin/busybox

not a dynamic executable

在初始化脚本中,我有:

#!/bin/busybox sh

mount -t proc none /proc

mount -t sysfs none /sys

echo "Hi there"

umount /sys

umount /proc

poweroff

从那里创建一个initramfs.gz:

find . -print0 | cpio --null --create --verbose --format=newc | pigz --best > ~/initramfs.gz

当我将其设置为qemu的目标initrd时,内核按预期启动,然后:

[ 0.777443] Run /init as init process

/init: line 3: mount: not found

/init: line 4: mount: not found

Hi there

/init: line 8: umount: not found

/init: line 9: umount: not found

/init: line 11: poweroff: not found

坐骑是busybox的一部分。 所以这很奇怪。

如果我修改init脚本并将/bin/busybox sh作为要执行的第一个命令,这将使我进入您期望的busybox shell。

[ 0.789949] Run /init as init process

BusyBox v1.27.2 (Ubuntu 1:1.27.2-2ubuntu3.2) built-in shell (ash)

Enter 'help' for a list of built-in commands.

sh: can't access tty; job control turned off

/ # [ 1.364618] input: ImExPS/2 Generic Explorer Mouse as /devices/platform/i8042/serio1/input/input3

[ 1.386482] tsc: Refined TSC clocksource calibration: 3392.105 MHz

[ 1.388387] clocksource: tsc: mask: 0xffffffffffffffff max_cycles: 0x30e52cb7a6c, max_idle_ns: 440795310382 ns

[ 1.391965] clocksource: Switched to clocksource tsc

/ #

然后帮助显示:

/ # help

Built-in commands:

------------------

. : [ [[ alias bg break cd chdir command continue echo eval exec[ 71.772009] random: fast init done

exit export false fg getopts hash help history jobs kill let

local printf pwd read readonly return set shift source test times

trap true type ulimit umask unalias unset wait [ [[ acpid adjtimex

ar arp arping ash awk basename blkdiscard blockdev brctl bunzip2

bzcat bzip2 cal cat chgrp chmod chown chpasswd chroot chvt clear

cmp cp cpio crond crontab cttyhack cut date dc dd deallocvt depmod

devmem df diff dirname dmesg dnsdomainname dos2unix dpkg dpkg-deb

du dumpkmap dumpleases echo ed egrep env expand expr factor fallocate

false fatattr fdisk fgrep find fold free freeramdisk fsfreeze

fstrim ftpget ftpput getopt getty grep groups gunzip gzip halt

head hexdump hostid hostname httpd hwclock i2cdetect i2cdump

i2cget i2cset id ifconfig ifdown ifup init insmod ionice ip ipcalc

ipneigh kill killall klogd last less link linux32 linux64 linuxrc

ln loadfont loadkmap logger login logname logread losetup ls

lsmod lsscsi lzcat lzma lzop md5sum mdev microcom mkdir mkdosfs

mke2fs mkfifo mknod mkpasswd mkswap mktemp modinfo modprobe more

mount mt mv nameif nc netstat nl nproc nsenter nslookup od openvt

partprobe passwd paste patch pidof ping ping6 pivot_root poweroff

printf ps pwd rdate readlink realpath reboot renice reset rev

rm rmdir rmmod route rpm rpm2cpio run-parts sed seq setkeycodes

setpriv setsid sh sha1sum sha256sum sha512sum shred shuf sleep

sort ssl_client start-stop-daemon stat static-sh strings stty

su sulogin svc swapoff swapon switch_root sync sysctl syslogd

tac tail tar taskset tee telnet telnetd test tftp time timeout

top touch tr traceroute traceroute6 true truncate tty tunctl

ubirename udhcpc udhcpd uevent umount uname uncompress unexpand

uniq unix2dos unlink unlzma unshare unxz unzip uptime usleep

uudecode uuencode vconfig vi w watch watchdog wc wget which who

whoami xargs xxd xz xzcat yes zcat

因此,我去寻找挂载,并发现找不到。 哦,但是如果我在/ bin / busybox前面加上它直接调用它,它就可以工作...

/ # type mount

mount is mount

/ # which mount

sh: which: not found

/ # /bin/busybox which mount

/ #

如果将/ bin / busybox添加到命令,则可以成功执行命令:

/ # /bin/busybox mount -t proc none /proc

/ #

看来从busybox可以正常工作的东西和不能正常工作的东西看起来真的是随机的,可以找到什么和没有发现什么,例如,find很好:

/ # find

.

./test

./sys

./bin

./bin/busybox

./lib

./mnt

./mnt/root

./lib64

./etc

./init

./sbin

./proc

./root

./dev

./dev/tty

./dev/null

./dev/sda1

./dev/console

我可以通过在初始化文件中的/bin/busybox之前添加每个命令来解决此问题,但是如果不需要的话,我真的不愿意!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值