2014-06-07 161 views
1

我想編寫一個腳本,將執行以下命令:無法正確設置環境變量LD_PRELOAD在bash腳本

${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。 follwoing在這個論壇是我嘗試過其他的答案是這樣的:

更新的代碼

#!/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,但爲什麼這些錯誤?

+0

您的圖書館setuid?嘗試使用'chmod g + s libfakeroot-tcp.so' setgid –

+0

@MarkSetchell感謝您的評論。但是你認爲這個錯誤是否會影響輸出文件initramfs.cpio – user2799508

+0

@MarkSetchell [root @ xilinx /]#chmod g + s /usr/lib64/libfakeroot/libfakeroot-tcp.so,但即使如此也會出現相同的錯誤。 – user2799508

回答

2

當你說

LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" printenv "LD_PRELOAD" libfakeroot-tcp.so 

,設置了LD_PRELOAD變量的printenv命令的持續時間。請嘗試:

export LD_PRELOAD="/usr/lib64/libfakeroot/libfakeroot-tcp.so" 

arm-xilinx-linux-gnueabi-gcc -static echotest.c -o init 
... 
+0

這給出:libfakeroot:FAKEROOTKEY沒有在環境中定義..除了其他錯誤 – user2799508

+0

你需要'export FAKEROOTKEY = some_value'? –