- This topic has 2개 답변, 2명 참여, and was last updated 15 years, 1 month 전에 by 인베인. This post has been viewed 737 times
-
-
nash(#>nash script)는 Redhat사에서 만든 mkinitrd-3.4.42-1.src.rpm 패키지에 구성되어 있다.
rh9#> rpm -ql mkinitrd-3.4.42-1
/sbin/grubby
/sbin/installkernel
/sbin/mkinitrd
/sbin/nash
/sbin/new-kernel-pkg
/usr/share/man/man8/grubby.8.gz
/usr/share/man/man8/mkinitrd.8.gz
/usr/share/man/man8/nash.8.gz
원래 initial RAM disk (initrd) image의 linuxrc 스크립트(이미지)를 실행하기 위해 작성된 매우 단순한 Script Interpretor이며, Shell(Command Interpreter)이 아니다.
nash가 modprobe처럼 호출이 되면, 0을 반환하면서 즉시 exit하게 될것이다. 이것은 부팅하는 동안 initrd가 몇몇 외래적인 커널 에러메세지가 방지하는 것을 허락학 된다.mkinitrd는 최초의 Ramdisk(initrd)으로 사용되기 위하여 파일시스템 이미지들을 생성한다. Ramdis 이미지들은 root 파일시스템을
처리하기위해 필요한 블락디바이스 모듈들(SCSI or RAID)을 미리 Load하기 위해 종종 사용된다. 예를 들어 커널의 파일시스템(ext3)을
모듈로 체크하는 경우에 SCSI 어뎁터를 주소화 할수 없기때문에 2.4커널의 경우 사용하는 파일시스템은 모듈이 아닌 Builtin(*)하였으나,
이러한 initial ramdisk를 통해 모듈로 파일시스템으로 체크하더라도 부팅을 정상적으로 할수 있게 된다.
initrd는 일반적으로 lilo 또는 grub와 같은 부트로더에 의해 적재된다. 그리고 ramdisk가 적재 되자마자 바로 커널이 사용가능하다.
ramdisk 이미지는 적당한 SCSI 어뎁터를 적재하고, 커널이 root파일시스템을 마운트하는 것을 허가한다. mkinitrd 프로그램은
/etc/modules.conf파일에서 찾은 정보를 사용하여 ramdisk처럼 생성한다.* Fedora Core 3/4 이상의 버젼에서 initrd 이미지를 압축해제하는 방법이다.
FC4#> mkdir temp ; cd temp
FC4#> cp /boot/initrd-2.6.14.2.img initrd-2.6.14.2.img.gz
FC4#> gunzip initrd-2.6.14.2.img.gz
FC4#> file initrd-2.6.14.2.img
initrd-2.6.14.2.img: Linux rev 1.0 ext2 filesystem data
FC4#> mkdir ./mnt
FC4#> mount -o loop initrd-2.6.12.3.img ./mnt
(cpio -i --make-directories < initrd-2.6.14.2.img)
FC4#>
FC4#> tree ./mnt
./mnt/
|-- bin
| |-- insmod
| |-- modprobe -> /bin/nash
| `-- nash
|-- dev
| |-- console
| |-- null
| |-- ram
| |-- systty
| |-- tty1
| |-- tty2
| |-- tty3
| `-- tty4
|-- etc
|-- lib
|-- linuxrc (/bin/nash script text executable)
|-- loopfs
|-- proc
|-- sbin -> bin
`-- sysroot
--------- ./linuxrc file info -----------------------
#!/bin/nash
echo Mounting /proc filesystem
mount -t proc /proc /proc
echo Creating root device
mkrootdev /dev/root
echo 0x0100 > /proc/sys/kernel/real-root-dev
echo Mounting root filesystem
mount --ro -t ext3 /dev/root /sysroot
umount /proc
pivot_root /sysroot /sysroot/initrd
--------------------------------------------------initial RAM disk 을 제작하는 스크립트를 아래와 같이 작성하면 편리하다.
#!/bin/bash# Housekeeping...
rm -f /tmp/ramdisk.img
rm -f /tmp/ramdisk.img.gz# Ramdisk Constants
RDSIZE=4000
BLKSIZE=1024# Create an empty ramdisk image
dd if=/dev/zero of=/tmp/ramdisk.img bs=$BLKSIZE count=$RDSIZE# Make it an ext2 mountable file system
/sbin/mke2fs -F -m 0 -b $BLKSIZE /tmp/ramdisk.img $RDSIZE# Mount it so that we can populate
mount /tmp/ramdisk.img /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
cp /usr/local/src/busybox-1.1.1/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
EOFchmod +x /mnt/initrd/linuxrc
# Finish up...
umount /mnt/initrd
gzip -9 /tmp/ramdisk.img
cp /tmp/ramdisk.img.gz /boot/ramdisk.img.gzinital RAM disk(initrd)을 테스트하기 위해 grub 프롬프트에서 아래와 같이 실행이 가능하다.
GNU GRUB version 0.95 (638K lower / 97216K upper memory)
[ Minimal BASH-like line editing is supported. For the first word, TAB
lists possible command completions. Anywhere else TAB lists the possible
completions of a device/filename. ESC at any time exits.]grub> kernel /bzImage-2.6.1
[Linux-bzImage, setup=0x1400, size=0x29672e]grub> initrd /ramdisk.img.gz
[Linux-initrd @ 0x5f2a000, 0xb5108 bytes]grub> boot
Uncompressing Linux... OK, booting the kernel
* 오픈소스는 Open Innovationa & 윈윈전략을 도모할 지언정 절대 공짜(무료)임을 뜻하지 않는다.치
- 답변은 로그인 후 가능합니다.