게시물 1,376건
   
mkinitrd (make init ramdisk) 사용
글쓴이 : 최고관리자 날짜 : 2011-03-16 (수) 16:12 조회 : 15604
글주소 :
                                
1. mkinitrd
 - make init ramdis 약자로 초기화 램디스크 이미지를 만들어주는 명령어로 부팅시 블록디바이스 모듈을 이미지로 만들때 사용하는 명렁어이다.
 
MKINITRD(8)                                                        MKINITRD(8)
 
 
NAME
       mkinitrd - creates initial ramdisk images for preloading modules
 
 
SYNOPSIS
       mkinitrd [--version] [-v] [-f]
                [--preload=module] [--omit-scsi-modules]
                [--omit-raid-modules] [--omit-lvm-modules]
                [--with=module] [--image-version]
                [--fstab=fstab] [--nocompress]
                [--builtin=module] [--nopivot]
                [--with-fips]
                image kernel-version
 
 
DEscRIPTION
mkinitrd  creates  an  initial  image  used  by  the kernel for preloading the block device modules (such as IDE, SCSI or RAID) which are needed to access the root filesystem. mkinitrd automatically loads filesystem modules (such as ext3 and jbd), IDE modules, all scsi_hostadapter entries in /etc/modprobe.conf, and raid  modules if the system’s root partition is on raid, which makes it simple to build and use kernels using modular device drivers.
Any module options specified in /etc/modprobe.conf are passed to the modules as they are loaded by the initial ramdisk.
The  root  filesystem  used  by  the  kernel  is  specified in the boot configuration file, as always. The traditional root=/dev/hda1 style device specification is allowed. If a label is used, as in root=LABEL=rootPart the initrd will search all available devices for an ext2 or ext3 filesystem with the appropriate label,  and mount that device as the root filesystem.
 
 
FIPS
mkinitrd will add a number of checks to the created initrd if the system is running in fips mode. First the kernel gets integrity checked by running "sha512hmac -c 
/boot/.vmlinuz-kernel-version.hmac" from the initrd. Then all the crypto algorithm modules get loaded using the embedded signature to  integrity  check  them,  and last the tcrypt module gets loaded which runs self tests on all approved crypto algorithms. You can force mkinitrd to add these checks to a created initrd with the
       --with-fips commandline option.
 
       There are a number of limitations to mkinitrd’s fips support:
       /boot  Must be on a separate partition
       /boot  Must not be on nfs, dmraid or mdraid
 
 
OPTIONS
--builtin=module
모듈이 모듈형태가 아닌 커널내부에서 동작해야 하는 모듈이라면 이옵션 사용
Act as if module is built into the kernel being used. mkinitrd will not look for this module, and will not emit an error if it does not exist.  This  option may be used multiple times.
 
-f    
initrd-image 이미존재하는 이름이라면 덮어쓰기
Allows mkinitrd to overwrite an existing image file.
 
--fstab=fstab
기본적으로 /etc/fstab을 참조하지만 자신이 만든 fstab파일이 있을경우 사용
Use fstab to automatically determine what type of filesystem the root device is on. Normally, /etc/fstab is used.
 
--image-version
The kernel version number is appended to the initrd image path before the image is created.
 
--nocompress
Normally the created initrd image is compressed with gzip. If this option is specified, the compression is skipped.
 
--nopivot
Do  not  use the pivot_root system call as part of the initrd. This lets mkinitrd build proper images for Linux 2.2 kernels at the expense of some features.
In particular, some filesystems (such as ext3) will not work properly and filesystem options will not be used to mount root. This option is not recommended, and will be removed in future versions.
 
--omit-lvm-modules
Do not load any lvm modules, even if /etc/fstab expects them.
 
--omit-raid-modules
Do not load any raid modules, even if /etc/fstab and /etc/raidtab expect them.
 
--omit-scsi-modules
Do not load any scsi modules, including ’scsi_mod’ and ’sd_mod’ modules, even if they are present.  If the root partition is on a scsi device, mkinitrd will still include the necessary scsi modules to support that device.
 
--preload=module 
initrd 가 실행할 때 SCSI 모듈이 올라오는 것을 기준으로 SCSI 모듈전에 실행될 모듈을 지정할때 사용
Load the module module in the initial ramdisk image. The module gets loaded before any SCSI modules which are specified in /etc/modprobe.conf.  This  option may be used as many times as necessary.
 
-v    
Prints out verbose information while creating the image (normally the mkinitrd runs silently).
 
--version
Prints the version of mkinitrd that’s being used and then exits.
 
--with=module 
initrd 가 실행할때 SCSI 모듈이 올라오는 것을 기준으로 SCSI 모듈후에 실행될 모듈을 지정할때 사용
Load  the  modules module in the initial ramdisk image. The module gets loaded after any SCSI modules which are specified in /etc/modprobe.conf. This option may be used as many times as necessary.
 
---with-fips
Force adding kernel integrity checking to the created initrd.
 
 
FILES
/dev/loop*         
A block loopback device is used to create the image, which makes this script useless on systems without block loopback support available  (only used on kernels < 2.6)
 
/etc/modprobe.conf 
Specifies SCSI modules to be loaded and module options to be used.
 
/etc/modules.conf  
Specifies SCSI modules to be loaded and module options to be used.  (only used on kernels < 2.6)
 
 
2. mkinird <initrd-image> <kernel-version>
* initrd-image : initrd의 파일명
* kernel-version : 커널 버전
 
initrd-<kernel-version>.img의 내용 확인
># file initrd-2.6.18-194.el5.img
initrd-2.6.18-194.el5.img: gzip compressed data, from Unix, last modified: Fri Mar  4 01:25:38 2011, max compression
==> gzip 압축상태임
 
># cp initrd-2.6.18-194.el5.img initrd-mojily.gz
># gunzip initrd-mojily.gz
># ls -al initrd-mojily
-rw------- 1 root root 5803520  3월 16 16:59 initrd-mojily
># file initrd-mojily
initrd-mojily: ASCII cpio archive (SVR4 with no CRC)
==> cpio 압축되어있음
 
># cpio -idmv < initrd-mojily
==> 압축디렉토리 해제
sys
init
sbin
sysroot
proc
bin
bin/kpartx
bin/dmraid
bin/insmod
bin/nash
bin/modprobe
etc
lib
lib/dm-mem-cache.ko
lib/ohci-hcd.ko
lib/ext3.ko
lib/libata.ko
lib/uhci-hcd.ko
lib/dm-message.ko
lib/ata_piix.ko
lib/dm-log.ko
lib/jbd.ko
lib/firmware
lib/ehci-hcd.ko
lib/scsi_mod.ko
lib/dm-region_hash.ko
lib/dm-mod.ko
lib/sd_mod.ko
lib/dm-raid45.ko
dev
dev/console
dev/zero
dev/tty0
dev/null
dev/tty5
dev/ram0
dev/tty9
dev/tty2
dev/tty7
dev/tty
dev/systty
dev/ttyS3
dev/tty1
dev/ttyS0
dev/tty8
dev/ram1
dev/tty10
dev/tty11
dev/rtc
dev/ttyS2
dev/ram
dev/tty3
dev/ttyS1
dev/mapper
dev/tty4
dev/tty6
dev/tty12
dev/ptmx
11335 blocks

 
># tree
.
|-- bin
|   |-- dmraid
|   |-- insmod
|   |-- kpartx
|   |-- modprobe -> /sbin/nash
|   `-- nash
|-- dev
|   |-- console
|   |-- mapper
|   |-- null
|   |-- ptmx
|   |-- ram -> ram1
|   |-- ram0
|   |-- ram1
|   |-- rtc
|   |-- systty
|   |-- tty
|   |-- tty0
|   |-- tty1
|   |-- tty10
|   |-- tty11
|   |-- tty12
|   |-- tty2
|   |-- tty3
|   |-- tty4
|   |-- tty5
|   |-- tty6
|   |-- tty7
|   |-- tty8
|   |-- tty9
|   |-- ttyS0
|   |-- ttyS1
|   |-- ttyS2
|   |-- ttyS3
|   `-- zero
|-- etc
|-- init
|-- initrd-mojily
|-- lib
|   |-- ata_piix.ko
|   |-- dm-log.ko
|   |-- dm-mem-cache.ko
|   |-- dm-message.ko
|   |-- dm-mod.ko
|   |-- dm-raid45.ko
|   |-- dm-region_hash.ko
|   |-- ehci-hcd.ko
|   |-- ext3.ko
|   |-- firmware
|   |-- jbd.ko
|   |-- libata.ko
|   |-- ohci-hcd.ko
|   |-- scsi_mod.ko
|   |-- sd_mod.ko
|   `-- uhci-hcd.ko
|-- proc
|-- sbin -> bin
|-- sys
`-- sysroot
 
 
3. initrd 내 트리별 디렉토리
1)init : 이 파일은 nash에 있는 실행 파일로 우리 시스템의 /etc/rc.d/ 밑에 있는 파일들 처럼 최초에 실행되면 어떤 순서로 실행될 지가 정의 되어 있는 스크립트 파일이다. 이 파일이 없으면 linuxrc 파일이 있을 것이다.
[root@test initrd_mount]# file init
init: a /bin/nash script text executable
 

2) bin 디렉토리
  - insmod : /sbin/insmod.static 부분을 카피해서 가지고 있는 것이다.
최초로 부팅시에는 공유라이브러리를 사용하지 못하기 때문에 라이브러리가 필요없는 static 옵션을 주어 컴파일 한 insmod를 사용하여 필요한 모듈을 올리기 위하여 복사된 것이다.
 - nash : 이 파일은 명령어의 집합체라고 보는 것이 좋을 것이다.
여러가지의 명령어가 심볼릭 링크의 이름으로 동작하게끔 만들어진 명령이다. 쉘 역할을 하면서 몇 가지의 주요 명령어를 이용할 수 있다.
이것 또한 static으로 컴파일 된 것이다.
 - udev : 디바이스 관련 명령어로 어떤 디바이스가 연결되었는지 안되어 있는 지를 확인하여 올려주거나 삭제해 주는 역할을 한다.
/sbin/udev.static가 복사된 것이다.
 
 
3) dev 디렉토리
 - console : 시스템 콘솔에 있는 파일이나 디바이스 드라이버를 직접 입출력을 할 수 있도록 제공된 것이다.
 
 - null : 운영체제를 위하여 제공된 파일이며 null device를 실행하는 역할을 한다.
 - ram : ram 디바이스를 위하여 제공된 파일로 ram에 직접 입출력을 할 수 있게 해준다.
 -  tty1~4 : 일반적으로 virtual terminals로 알려진 걸로 시스템으로 부터 올라오는 메세지를 화면상에 뿌려주는 역할을 한다.
 - systty : 키보드나 모니터가 없는 환경에서 심볼릭 링크를 이용하여 디바이스를 사용할 수 있게 해준다.
 
 
4) lib 디렉토리
이 디렉토리는 모듈을 가지고 있는 것을 알 수 있을 것이다. 이 부분에 있는 모듈이 바로 initrd가 올려주는 모듈들이다.
 
 
5)나머지 디렉토리
 - proc : procfs의 정보를 마운트 해주는 디렉토리이다.
mount -t proc none proc 를 이용하여 현재 /proc에 있는 내용이랑 동일한 것을 마운트 시킨다.
 - sys : sysfs의 정보를 마운트 해주는 디렉토리이다.
mount -t sysfs none sys 를 이용하여 마운트하며 proc과는 다른 정보를 볼 수 있습니다.
 - loopfs : loop 장치를 마운트하기 위한 디렉토리이다.
losetup 명령어를 이용하여 루프 장치를 정규 파일 또는 블럭 장치와 연결, 루프 장치와 분리, 루프 장치의 상태파악을 위하여 마운트 시켜 디렉토리이다.
 - sysroot : 실제 우리가 사용하는 디스크를 마운트 시켜주기 위한 디렉토리이다. 모든 initrd에서의 설정 내용이 다 실행된 이후에 pivot_root 명령어를 사용하여 우리가 현재 보고 있는 디렉토리를 “/”로 보여주는 것이다.
 
 
4 .initrd는 램 디스크???
initrd를 풀어서 안의 내용을 보면 모듈을 올리는데 필요한 것과 시스템에 필요한 정보를 마운트할 파일 시스템을 가지고 있는 것을 볼 수 있다.
하지만 모듈들을 잘 살펴보면 파일 시스템과 관련된 ext3.ko, xfs.ko 파일을 볼 수 있을 것이다. 이것은 파일 시스템이 구동되기 위하여 올라가야 하는 모듈들이다.
그럼, 이 모듈을 올려주는 역할을 하는 initrd는 어떻게 동작하기에 이런 모듈을 파일 시스템이 올라오기도 전에 구동되게 하는 것일까?
이것은 바로 부트로더의 역할 때문이다. 부트로더는 최초에 grub.conf나 lilo.conf에 설정된 디스크의 위치와 디렉토리 위치에서 vmlinuz와 initrd 파일을 램으로 복사하는 역할을 해준다. 이것은 결국 부팅시 사용되는 initrd는 램으로 복사된 initrd를 이용하여 램상에서 동작을 하는 것이다. 결국 램을 디스크처럼 생각하고 그 곳에 tree에서 본 구조를 그대로 풀어서 init의 설정 내용대로 실행한 이후에 실제 우리가 사용하는 디스크로 넘어와 /sbin/init를 실행하게 된다.
결국 램에서 동작하면서 램을 디스크처럼 이용하기에 램 디스크라고 하는 것이다.
 
 
5.mkinitrd 명령어의 역할
가. initrd를 위한 파일 시스템을 구성한다.
나. 부팅시 필요한 모듈을 옮겨준다.
* 2.6 커널 : /etc/modprobe.conf 파일 참조
* 2.4 커널 : /etc/modules.conf 파일 참조
* modprobe.conf내의 usb-controller, scsi_hostadapter를 이용한 모듈만을 넘긴다.
* fstab를 검색하여 파일 시스템에 필요한 모듈을 올려준다.
다. initrd에서 필요한 파일 복사해 준다.
라. initrd에 있는 init를 생성 시켜준다.
 
 
6. 이미지 압축 (압축된 이미지 헤재된거 다시 압축)
># find ./ | cpio -H newc -o > ../initrd.mojily
11702 blocks
 

이름 패스워드
비밀글 (체크하면 글쓴이만 내용을 확인할 수 있습니다.)
왼쪽의 글자를 입력하세요.
   

 



 
사이트명 : 모지리네 | 대표 : 이경현 | 개인커뮤니티 : 랭키닷컴 운영체제(OS) | 경기도 성남시 분당구 | 전자우편 : mojily골뱅이chonnom.com Copyright ⓒ www.chonnom.com www.kyunghyun.net www.mojily.net. All rights reserved.