我想编写一个脚本来执行以下命令:
${CROSS_COMPILE}gcc -static myinit.c -o myinit
cd initramfs
fakeroot # this is pure magic (it allows us to pretend to be root)
mkdir -p dev
mknod dev/console c 5 1
chown root init
find . | cpio -H newc -o > ../initramfs.cpio # <-- this is the actual initramfs
exit # leave the fakeroot shell
cd ..
截至目前,我每天必须手动执行此操作 200 次。所以我想它可以转换成一个 scipt 来自动化这个过程。按照这个论坛中的其他答案,我尝试的是:
更新代码
#!/bin/bash
LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" printenv "LD_PRELOAD" libfakeroot-tcp.so
printenv "LD_PRELOAD"
printenv "LD_PRELOAD"
arm-xilinx-linux-gnueabi-gcc -static echotest.c -o init
cp init initramfs
cd initramfs
fakeroot
mkdir -p dev
mknod dev/console c 5 1
chown root init
find . | cpio -H newc -o > ../initramfs.cpio
exit
cd ..
我将其保存在 test.sh 中,并使该文件可执行。这是我得到的输出:
更新输出
/usr/lib64/libfakeroot/libfakeroot-tcp.so
libfakeroot-tcp.so
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
ERROR: ld.so: object 'libfakeroot-tcp.so' from LD_PRELOAD cannot be preloaded: ignored.
fakeroot: FAKEROOTKEY set to 39730
fakeroot: nested operation not yet supported
1289 blocks
我得到了预期的文件 initramfs.cpio ,但为什么会出现这些错误?
最佳答案
当你说
LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" printenv "LD_PRELOAD" libfakeroot-tcp.so
在 printenv 命令期间仅设置 LD_PRELOAD 变量。尝试:
export LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so"
arm-xilinx-linux-gnueabi-gcc -static echotest.c -o init
...
关于linux - 无法在 bash 脚本中正确设置环境变量 LD_PRELOAD,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24096290/