initramfs在编译内核的同时被编译并与内核生成一个映像文件,可以压缩也可以不压缩,但是目前只支持cpio包格式。它是根文件系统制作和制作的一种非常简单的方法,也可以通过执行这个文件系统中的程序引导真正的文件系统,这样加载根文件系统的工作就不是内核的工作,而是initramfs的工作。由于initramfs使用cpio包格式,所以很容易将一个单一的文件、目录、node编译链接到系统中去,这样很简单的系统中使用起来很方便,不需要另外挂接文件系统。
但是因为cpio包实际是文件、目录、节点的描述语言包,为了描述一个文件、目录、节点,要增加很多额外的描述文字开销,特别是对于目录和节点,本身很小额外添加的描述文字却很多,这样使得cpio包比相应的image文件大很多。
1、添加init程序
由于制作initramfs文件系统启动时会在根文件系统中执行第一个init程序,它对uboot传过来的参数init=/linuxrc不予理睬,所以需要在上面制作的根文件系统里的根目录加入init程序,否则无法启动。init程序和linuxrc程序一样都是符号链接文件,它们都是指向/bin/busybox程序。
[lingyun@localhost rootfs]$ ln -s bin/busyboxinit
2、在内核添加对initramfis的支持
[lingyun@localhostyangzheng]$ cd linux-3.0
[[email protected]]$ vt100
General setup --->
[*] Initial RAM filesystem and RAM disk (initramfs/initrd) support (../rootfs)Initramfs source file(s) //加入根文件系统的路径
编译内核:
[lingyun@localhost linux-3.0]$ sudo make
[lingyun@localhost linux-3.0]$ ls
arch crypto fs Kbuild MAINTAINERS modules.order REPORTING-BUGS sound usr
block Documentation include Kconfig Makefile Module.symvers samples System.map virt
COPYING drivers init kernel mm net scripts tools vmlinux
CREDITS firmware ipc lib modules.builtin README security uImage-s3c2440.gz vmlinux.o
[lingyun@localhost linux-3.0]$
[lingyun@localhost linux-3.0]$
[lingyun@localhost linux-3.0]$
[lingyun@localhost linux-3.0]$ cp uImage-s3c2440.gz /tftp/ //拷贝到tftp目录下
3、添加u-boot对initramfs的支持
因为文件系统和内核是集成在一起的,所以不需要制作文件系统映像。只需在u-boot跑起来以后,修改一下bootargs 和bootcmd就可以了。(跑不同的文件系统,设置的参数是不同的)
[ s3c2440@yangzheng ]# set bbl 'nand erase 0 100000;tftp 30008000 u-boot.bin;nand write30008000 0 100000'
[ s3c2440@yangzheng ]# set bkr 'tftp 30008000 yz_inituImage-2440.gz;nand erase 100000825030;nand write 30008000 100000 825030'
[ s3c2440@yangzheng ]# set bootcmd_initramdisk 'nand read 30008000 100000 825030;bootm30008000'
[ s3c2440@yangzheng ]# set bootcmd'run bootcmd_initramdisk'
[ s3c2440@yangzheng ]# set bootargs 'console=ttyS0,115200 mem=64M init=/linuxrc rw loglevel=7'
[ s3c2440@yangzheng ]# save
4、启动linux
[ s3c2440@yangzheng ]# bootm
resetting ...
U-Boot 2010.09-00000-g011794e-dirty (Sep 20 2012 - 21:46:38)
Modified by guowenxue for s3c2440/s3c2410 board.
DRAM: 64 MiB
## Unknown FLASH on Bank 0: ID 0xffff, Size = 0x00000000 = 0 MB
Flash: 0 Bytes
NAND: 256 MiB
In: serial
Out: serial
Err: serial
Net: dm9000
Hit any key to stop autoboot: 0
NAND read: device 0 offset 0x100000, size 0x825800
8542208 bytes read: OK
## Booting kernel from Legacy Image at 30008000 ...
Image Name: Linux Kernel
Created: 2013-06-03 13:54:42 UTC
Image Type: ARM Linux Kernel Image (uncompressed)
Data Size: 8540144 Bytes = 8.1 MiB
Load Address: 30008000
Entry Point: 30008040
Verifying Checksum ... OK
XIP Kernel Image ... OK
OK
OS entry point: 30008040
Image entry point=30008040
Starting kernel ...
Uncompressing Linux... done, booting the kernel.
Linux version 3.0.0([email protected]) (gcc version 4.5.4 (Buildroot 2012.08) ) #2 MonJun 3 21:54:37 CST 2013
CPU: ARM920T [41129200] revision 0 (ARMv4T), cr=c0007177
CPU: VIVT data cache, VIVT instruction cache
Machine: SMDK2440
Memory policy: ECC disabled, Data cache writeback
CPU S3C2440A (id 0x32440001)
S3C24XXClocks, Copyright 2004 Simtec Electronics
S3C244X:core 405.000 MHz, memory 101.250 MHz, peripheral 50.625 MHz
CLOCK: Slow mode (1.500 MHz), fast, MPLL on, UPLL on
Built 1 zonelists in Zone order, mobility grouping on. Total pages: 16256
Kernel command line: console=ttyS0,115200 mem=64M init=/linuxrc rw loglevel=7
PID hash table entries: 256 (order: -2, 1024 bytes)
Dentry cache hash table entries: 8192 (order: 3, 32768 bytes)
Inode-cache hash table entries: 4096 (order: 2, 16384 bytes)
Memory: 64MB = 64MB total
Memory: 44872k/44872k available, 20664k reserved, 0K highmem
Virtual kernel memory layout:
vector : 0xffff0000 - 0xffff1000 ( 4kB)
fixmap : 0xfff00000 - 0xfffe0000 ( 896 kB)
DMA : 0xffc00000 - 0xffe00000 ( 2MB)
vmalloc : 0xc4800000 -0xf6000000 ( 792 MB)
lowmem : 0xc0000000 - 0xc4000000 ( 64MB)
modules : 0xbf000000 -0xc0000000 ( 16 MB)
.init : 0xc0008000 -0xc0e71000 (14756 kB)
.text : 0xc0e71000 -0xc1335000 (4880 kB)
.data : 0xc1336000 -0xc1365b20 ( 191 kB)
.bss : 0xc1365b44 -0xc1391fa4 ( 178 kB)
NR_IRQS:85
irq: clearing pending ext status 00080000
irq: clearing subpending status 00000002
Console: colour dummy device 80x30
console [ttyS0] enabled
Calibrating delay loop... 201.52 BogoMIPS (lpj=503808)
pid_max: default: 32768 minimum: 301
Mount-cache hash table entries: 512
CPU: Testing write buffer coherency: ok
gpiochip_add: gpios 288..303 (GPIOK) failed to register
gpiochip_add: gpios 320..334 (GPIOL) failed to register
gpiochip_add: gpios 352..353 (GPIOM) failed to register
NET: Registered protocol family 16
S3C PowerManagement, Copyright 2004 Simtec Electronics
S3C2440:Initialising architecture
S3C2440:IRQ Support
S3C24XXDMA Driver, Copyright 2003-2006 Simtec Electronics
DMA channel 0 at c4804000, irq 33
DMA channel 1 at c4804040, irq 34
DMA channel 2 at c4804080, irq 35
DMA channel 3 at c48040c0,irq 36
S3C244X:Clock Support, DVS off
s3c-adc s3c24xx-adc: attached adc driver
bio: create slab <bio-0> at 0
SCSI subsystem initialized
usbcore: registered new interface driver usbfs
usbcore: registered new interface driver hub
usbcore: registered new device driver usb
s3c-i2c s3c2440-i2c: slave address 0x10
s3c-i2c s3c2440-i2c: bus frequency set to 98 KHz
s3c-i2c s3c2440-i2c: i2c-0:S3C I2C adapter
Advanced Linux Sound Architecture Driver Version 1.0.24.
cfg80211: Calling CRDA to update world regulatory domain
NET: Registered protocol family 2
IP route cache hash table entries: 1024 (order: 0, 4096 bytes)
TCP established hash table entries: 2048 (order: 2, 16384 bytes)
TCP bind hash table entries: 2048 (order: 1, 8192 bytes)
TCP: Hash tables configured (established 2048 bind 2048)
TCP renoregistered
UDP hash table entries: 256 (order: 0, 4096 bytes)
UDP-Lite hash table entries: 256 (order: 0, 4096 bytes)
NET: Registered protocol family 1
RPC: Registered named UNIX socket transport module.
RPC: Registered udp transport module.
RPC: Registered tcp transport module.
RPC: Registered tcp NFSv4.1 backchannel transport module.
NetWinder Floating Point Emulator V0.97 (extended precision)
NTFS driver 2.1.30 [Flags: R/W].
JFFS2 version 2.2. (NAND) (SUMMARY) 漏 2001-2006 Red Hat, Inc.
msgmni has been set to 87
io scheduler noop registered
io scheduler deadline registered
io scheduler cfq registered (default)
Console: switching to colour frame buffer device 60x34
fb0: s3c2410fbframe buffer device
s3c2440-uart.0:ttyS0 at MMIO 0x50000000 (irq = 70) is a S3C2440
s3c2440-uart.1:ttyS1 at MMIO 0x50004000 (irq = 73) is a S3C2440
s3c2440-uart.2:ttyS2 at MMIO 0x50008000 (irq = 76) is a S3C2440
brd: module loaded
loop: module loaded
at24 0-0050: 65536 byte 24c512EEPROM, writable, 128 bytes/write
S3C24XXNAND Driver, (c) 2004 Simtec Electronics
s3c24xx-nands3c2440-nand: Tacls=3,29ns Twrph0=7 69ns, Twrph1=3 29ns
s3c24xx-nands3c2440-nand: NAND softECC
NAND device: Manufacturer ID: 0xec, Chip ID: 0xda (Samsung NAND256MiB 3,3V 8-bit)
Scanning device for bad blocks
Bad eraseblock 421 at 0x0000034a0000
Bad eraseblock 1177 at 0x000009320000
Bad eraseblock 1727 at 0x00000d7e0000
Creating 11 MTD partitions on "NAND":
0x000000000000-0x000000100000 : "mtdblock0 u-boot 1MB"
0x000000100000-0x000000500000 : "mtdblock1 kernel 4MB"
0x000000500000-0x000000f00000: "mtdblock2 ramdisk 10MB"
0x000000f00000-0x000001e00000: "mtdblock3 cramfs 15MB"
0x000001e00000-0x000004600000 : "mtdblock3 jffs2 40MB"
0x000004600000-0x000006e00000 : "mtdblock4 yaffs2 40MB"
0x000006e00000-0x000009600000 : "mtdblock5 ubifs 40MB"
0x000009600000-0x000009700000 : "mtdblock6 info 1MB"
0x000009700000-0x00000bf00000 : "mtdblock7 apps 40MB"
0x00000bf00000-0x00000e700000 : "mtdblock8 data 40MB"
0x00000e700000-0x000010000000 : "mtdblock9 backup 25MB"
PPP generic driver version 2.4.2
PPP Deflate Compression module registered
PPP BSD Compression module registered
PPP MPPE Compression module registered
NET: Registered protocol family 24
dm9000 Ethernet Driver, V1.31
eth0: dm9000aat c4864300,c4866304 IRQ 51 MAC: 08:00:3e:26:0a:6b (chip)
usbcore: registered new interface driver rt2800usb
ohci_hcd: USB 1.1 'Open' Host Controller (OHCI) Driver
s3c2410-ohcis3c2410-ohci: S3C24XX OHCI
s3c2410-ohcis3c2410-ohci: new USB busregistered, assigned bus number 1
s3c2410-ohcis3c2410-ohci: irq 42, iomem 0x49000000
usb usb1: New USB device found, idVendor=1d6b, idProduct=0001
usb usb1: New USB device strings: Mfr=3, Product=2, SerialNumber=1
usb usb1: Product: S3C24XXOHCI
usb usb1: Manufacturer: Linux 3.0.0ohci_hcd
usb usb1: SerialNumber: s3c24xx
hub 1-0:1.0: USB hub found
hub 1-0:1.0: 2 ports detected
Initializing USB Mass Storage driver...
usbcore: registered new interface driver usb-storage
USB Mass Storage support registered.
usbcore: registered new interface driver usbserial
usbserial: USB Serial Driver core
USB Serial support registered for ch341-uart
usbcore: registered new interface driver ch341
USB Serial support registered for FTDI USB Serial Device
usbcore: registered new interface driver ftdi_sio
ftdi_sio: v1.6.0:USB FTDI SerialConverters Driver
USB Serial support registered for GSM modem (1-port)
usbcore: registered new interface driver option
option: v0.7.2:USB Driver for GSM modems
USB Serial support registered for pl2303
usbcore: registered new interface driver pl2303
pl2303: Prolific PL2303 USB to serial adaptor driver
mousedev: PS/2 mouse device common for all mice
samsung-ts s3c2440-ts:driver attached, registering input device
input: S3C24XXTouchScreen as /devices/virtual/input/input0
S3C24XXRTC, (c) 2004,2006 Simtec Electronics
s3c-rtc s3c2410-rtc: rtc disabled, re-enabling
s3c-rtc s3c2410-rtc: rtc core: registered s3c as rtc0
i2c /deventries driver
s3c-sdi s3c2440-sdi: mmc0 - using pio, sw SDIO IRQ
usbcore: registered new interface driver usbhid
usbhid: USB HID core driver
S3C24XX_UDA134XSoC Audio driver
UDA134X SoC Audio Codec
asoc: uda134x-hifi <-> s3c24xx-iismapping ok
ALSA device list:
#0: S3C24XX_UDA134X
Netfilter messages via NETLINK v0.30.
nf_conntrack version 0.5.0(701 buckets, 2804 max)
ctnetlink v0.93: registering with nfnetlink.
xt_time: kernel timezone is -0000
ip_set: protocol 6
IPVS: Registered protocols (TCP, UDP, AH, ESP)
IPVS: Connection hash table configured (size=4096, memory=32Kbytes)
IPVS: Creating netns size=1008 id=0
IPVS: ipvs loaded.
IPVS: [rr] scheduler registered.
IPVS: [wrr] scheduler registered.
IPVS: [lc] scheduler registered.
IPVS: [wlc] scheduler registered.
IPVS: [lblc] scheduler registered.
IPVS: [lblcr] scheduler registered.
IPVS: [dh] scheduler registered.
IPVS: [sh] scheduler registered.
IPVS: [sed] scheduler registered.
IPVS: [nq] scheduler registered.
ip_tables: (C) 2000-2006 Netfilter Core Team
ipt_CLUSTERIP: ClusterIP Version 0.8 loaded successfully
arp_tables: (C) 2002 David S. Miller
TCP cubic registered
NET: Registered protocol family 17
lib80211: common routines for IEEE802.11 drivers
Registering the dns_resolver key type
s3c-rtc s3c2410-rtc: setting system clock to2047-03-20 06:03:06 UTC (2436674586)
Freeing init memory: 14756K
usb 1-1: new full speed USB device number 2 using s3c2410-ohci
usb 1-1: New USB device found, idVendor=05e3, idProduct=0606
usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=0
usb 1-1: Product: USB Hub 2.0
hub 1-1:1.0: USB hub found
hub 1-1:1.0: 4 ports detected
dm9000 dm9000.0: eth0: link up, 100Mbps, full-duplex, lpa 0xCDE1
Copyright (C) 2013 yangzheng<[email protected]>
root login:root
>: ls
apps data etc init linuxrc proc sbin tmp var
bin dev info lib mnt root sys usr
>:
这样我的initramfis文件系统就跑起来了。