LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1050|回复: 1

写 busybox 构建初始ram盘(initrd)脚本时出现的问题,谢谢大家

[复制链接]
发表于 2009-1-5 17:31:38 | 显示全部楼层 |阅读模式
在 IBM Developer Works 看到的文章 "Linux 初始 RAM 磁盘(initrd)概述"
http://www.ibm.com/developerworks/cn/linux/l-initrd.html
其中描述了在2.4内核下相关操作的方法,我也想在2.6下试试,但是出现了点问题,请大家帮助,谢谢!

脚本在下面

#!/bin/bash

#cleaning up!!
rm -rf  /tmp/ramdisk
rm -rf  /tmp/initrd-will

# Ramdisk Constants
RDSIZE=4000
BLKSIZE=1024

# Create an empty ramdisk image
dd if=/dev/zero of=/tmp/ramdisk  bs=$BLKSIZE count=$RDSIZE

# Make it an ext2 mountable file system
/sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk $RDSIZE

# Mount it so that we can populate
mount /tmp/ramdisk /mnt/initrd -t ext2 -o loop=/dev/loop0

# Populate the filesystem (subdirectories)
mkdir /mnt/initrd/bin
mkdir /mnt/initrd/sys
mkdir /mnt/initrd/dev
mkdir /mnt/initrd/proc

# Grab busybox and create the symbolic links
pushd /mnt/initrd/bin
#push $`pwd` into a directory stack && cd /initrd/bin
cp /usr/local/src/busybox-1.13.2/busybox .
ln -s busybox ash
ln -s busybox mount
ln -s busybox echo
ln -s busybox ls
ln -s busybox cat
ln -s busybox ps
ln -s busybox dmesg
ln -s busybox sysctl
popd

# Grab the necessary dev files
cp -a /dev/console /mnt/initrd/dev
cp -a /dev/ramdisk /mnt/initrd/dev
cp -a /dev/ram0 /mnt/initrd/dev
cp -a /dev/null /mnt/initrd/dev
cp -a /dev/tty1 /mnt/initrd/dev
cp -a /dev/tty2 /mnt/initrd/dev

# Equate sbin with bin
pushd /mnt/initrd
ln -s bin sbin
popd

# Create the init file
cat >> /mnt/initrd/linuxrc << EOF
#!/bin/ash
echo
echo "Simple initrd is active"
echo
mount -t proc /proc /proc
mount -t sysfs none /sys
/bin/ash --login
EOF

chmod +x /mnt/initrd/linuxrc

# Finish up...
#umount /mnt/initrd
echo `pwd`
#cd /mnt/initrd
find /mnt/initrd |cpio --quiet -H newc /temp/initrd-will
#cp /tmp/initrd-will /boot/initrd-will

出错的是
cpio : You must specify one of -oipt options
发表于 2009-1-5 21:26:45 | 显示全部楼层
很明显你的cpio命令用错了。按你给出的脚本的意思,大概应该是这样的:
  1. find /mnt/initrd |cpio --quiet -oH newc > /temp/initrd-will
复制代码
但是这里,打包文件的路径估计有问题,我感觉好像应该是先 cd 到 /mnt/initrd ,再用 find . 来列文件。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表