FREEDOM. FRIENDS. FEATURES. FIRST. 페도라 한국 사용자 모임

NASH(linuxrc images interpreter)와 initrd조작법

게시판 Tech/Tip NASH(linuxrc images interpreter)와 initrd조작법

  • This topic has 2개 답변, 2명 참여, and was last updated 15 years, 1 month 전에 by
    인베인. This post has been viewed 737 times
  • #12106
    인베인
    참가자
      게시글147 댓글412 총합559
    @leemgs
     

    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
    EOF

    chmod +x /mnt/initrd/linuxrc

    # Finish up...
    umount /mnt/initrd
    gzip -9 /tmp/ramdisk.img
    cp /tmp/ramdisk.img.gz /boot/ramdisk.img.gz

    inital 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 & 윈윈전략을 도모할 지언정 절대 공짜(무료)임을 뜻하지 않는다.치

1 답변 글타래를 보이고 있습니다
    • #12711
      ELem
      참가자
        게시글74 댓글719 총합793
      @Bardisch
       

      순간 쉘인줄알았...ㄱ-
      BASH 동생뻘인줄..;;

       
    • #12712
      인베인
      참가자
        게시글147 댓글412 총합559
      @leemgs
       

      유난히 페도라 배포판쪽에서 종종 nash가 CPU 100%먹는게 자주 보입니다. ㅜㅜ ( 예를 들면 커널소스 빌드하고나서 mkimage 명령시.... ㅡ.ㅡ;;)

      * 오픈소스는 Open Innovationa & 윈윈전략을 도모할 지언정 절대 공짜(무료)임을 뜻하지 않는다.치

       
1 답변 글타래를 보이고 있습니다
  • 답변은 로그인 후 가능합니다.

지금 이 순간


페도라 한국 사용자 모임 오픈을 축하드립니다^.^
[tip-tech] 페도라 리눅스 세션 일시 중지 방지하기
백트랙 써보신분?
fedora 리눅스 gcc binary 설치 방법
큰일났어요..ㅠㅠ
가입 인사드립니다.
올해는 작년 만우절처럼 Hacked! 드립은 없는건가요
설치하기 빡시네요;;;
가입인사드립니다.
Fedora 12 x86_64용 Xen Dom0 커널 없나여? ㅠ