initrd and initramfs

转载 2012年03月28日 15:26:01

Initrd

From Texas Instruments Embedded ProcessorsWiki

After kernel booted, it tries to mount a filesystem. Using Linux on DaVinci, there are several options wherethis file system can come from. Options are

The last option, an initial file system in a ram disk is calledinitrd (initialramdisk). Note that using an initrd with recentkernels is still possible and has some advantages, but isn't recommended any more.Using initramfs is the preferred way today.

initrd/initramfs (and NFS) is a file system option notpermanently stored at the target device and thus normally usedwhile development. initrd/initramfs is typically newinstalled/downloaded each time the target board is power cycled(using e.g. boot loader U-Boot). The two other options above (harddisk and flash file system) give the target system permanentlyaccess to its file system without any external debug connection(e.g. network download) and thus are used after developmentin production ready devices.

Contents

[hide]

initrd

Creation

To create an (initially empty) initrd use the followingsteps:

Note: Change count to your required filesystem size. E.g.with count=8192 you will get a 8MB ramdisk.

host > dd if=/dev/zero of=/dev/ram0 bs=1k count=<count>
host > mke2fs -vm0 /dev/ram0 <count>
host > tune2fs -c 0 /dev/ram0
host > dd if=/dev/ram0 bs=1k count=<count> | gzip -v9 > ramdisk.gz

Now, we have a (empty) gzipped ramdisk image with (extracted)size of <count>.

Filling

To fill empty ramdisk created above with all files needed forramdisk, mount the image and fill it. Content would be e.g.BusyBox and/or otherapplications and/or libraries.

host > mkdir mnt
host > gunzip ramdisk.gz
host > mount -o loop ramdisk mnt/
host > ... copy stuff you want to have in ramdisk to mnt...
host > umount mnt
host > gzip -v9 ramdisk

The resulting ramdisk.gz is now ready for usage. Note its sizeis smaller than <count> causeof compression.

Note: Don't forget to create/copy some basic /dev/xxx nodes toramdisk.

Note: If BusyBox or applications in ramdisk are linkeddynamically, don't forget to copy dynamic libraries (*.so) toramdisk (to correct directory) as well.

Kernel options

To make initrd work, you have to configure kernel properly:

#
# General setup
#
...
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE=""
...
#
# UBI - Unsorted block images
#
...
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=8192
CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
...

Note: The ramdisk size e.g. 8192 above has to be configured foryour individual setup.

Installation

Now, you can install the ramdisk via u-boot e.g. in NOR flash.For this copy filled ramdisk created above to your tftpbootdirectory on host (e.g. /tftpboot/ramdisk.gz). Then start targetand copy the data into RAM and flash:

UBOOT # tftp 0x87000000 ramdisk.gz
UBOOT # erase 0x2200000 +0x<filesize>
UBOOT # cp.b 0x87000000 0x2200000 0x<filesize>

Note: Replace filesize above by the value the tftpdownload command gives you as Bytes transferred.

Now, last step is to update kernel boot parameters and savethem

UBOOT # setenv bootargs ... root=/dev/ram0 rw initrd=0x87000000,8M
UBOOT # setenv bootcmd cp.b 0x2200000 0x87000000 0x<filesize>; bootm
UBOOT # saveenv

Note: In example above with "8M" we assume that your ramdisk is8MBytes. Adapt this to your needs.

Note: Your ramdisk filled above should have a /dev/ram0 node

brw-rw---- 1 root disk 1, 0 Sep 11 1999 /dev/ram0

to make this work properly.

Now you should be able to start your kernel and it should findand mount the initrd:

Linux version 2.6.23-davinci1 ...
...
checking if image is initramfs...it isn't (no cpio magic); looks like an initrd
Freeing initrd memory: 8192K
...
RAMDISK driver initialized: 1 RAM disks of 8192K size 1024 blocksize
...
RAMDISK: Compressed image found at block 0
VFS: Mounted root (ext2 filesystem).
Freeing init memory: ...
...

initramfs

To use initramfs a cpio archive is embedded directly into thekernel. I.e. you don't create an additional (ramdisk) image.Instead, the initial file system is directly incorporated into thekernel. With this, the kernel size increases by the file systemsize. It's like you embed above ramdisk directly into thekernel.

Creation

Cause initramfs is directly embedded in the the kernel, itscreation is simpler. No dd & mount& gzip stuff like with ramdisk above. You simplyhave to fill a directory on your host with the target filesystemyou like and then pass the path to this directory to the kernelbuild process.

Create target file system

host > mkdir target_fs
host > ... copy stuff you want to have in initramfs to target_fs...

Note: cpio system used for initramfs can't handle hardlinks. If you e.g. created your BusyBox using hard links, youwill get a quite large initramfs cause each command is taken withits size and not as hard link. In cpio initramfs use symbolic/soft links instead.

Note: To be able to detect initramfs by kernel properly, the toplevel directory has to contain a program called init. Thiscan be done by e.g. using a soft link from top level init to/bin/busybox

/init -> /bin/busybox

if you use BusyBox in your initramfs.

Kernel options

The only difference from creating an initrd is to give thekernel the path to the target file system you like to embed:

#
# General setup
#
...
CONFIG_BLK_DEV_INITRD=y
CONFIG_INITRAMFS_SOURCE="<path_to>/target_fs>"
...
#
# UBI - Unsorted block images
#
...
CONFIG_BLK_DEV_RAM=y
CONFIG_BLK_DEV_RAM_COUNT=1
CONFIG_BLK_DEV_RAM_SIZE=8192
CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
...

Then, if you compile the kernel, e.g. by make uImage, the cpioarchive is generated and embedded into the kernel:

 ...
 CHK     include/linux/compile.h
 GEN     usr/initramfs_data.cpio.gz
 AS      usr/initramfs_data.o
 LD      usr/built-in.o
 ...

Installation

No special installation like above with initrd isnecessary. The initramfs is already in the kernel. If you start thekernel, the initramfs is already there. Therefore, there isno root=/dev/ram0 rw initrd=0x87000000,8M bootargsoption necessary. Remove this if you still have it!

initrd vs. initramfs

  • Using initrd, kernel and initial file system are splitted.Making changes to kernel or filesystem doesn't touch the other one.The download size (e.g. while development) of one component issmaller.
  • Creating and modifying an initramfs is easier than with initrd(unzip & mount & unmount& zip)
  • Having one big image (kernel & initramfs) iseasier to handle (e.g. download or flashing) than having twosplitted images.

initrd和initramfs 解析

这个两个都是在内核启动之后的boot加载的临时文件系统,一般制作的内核很多的驱动并没有编译进去,如:硬盘相关驱动等, 由于rootfs存储在硬盘中,没有这些驱动,则无法加载真正的rootfs(root...
  • u011774239
  • u011774239
  • 2016年01月23日 11:17
  • 633

《Linux启动过程分析》之区别Initramfs与initrd

一、简介 1.initrd   在早期的linux系统中,一般只有硬盘或者软盘被用来作为linux根文件系统的存储设备,因此也就很容易把这些设备的驱动程序集成到内核中。但是现在的嵌入式系统中可能将根文...
  • tankai19880619
  • tankai19880619
  • 2013年11月22日 15:32
  • 14799

Initramfs和initrd uboot中的bootargs参数传给内核

initramfs概述 initramfs与initrd类似,也是初始化好了且存在于ram中的,可以压缩也可以不压缩。但是目前initramfs只支持cpio包格式,它会被populate_...
  • androidstar_cn
  • androidstar_cn
  • 2016年11月14日 22:42
  • 1180

ramdisk initrd ramfs initramfs区别与联系

问题: 当Linux内核启动时,必须找到并执行第一个用户程序,通常是init。用户程序存放在文件系统,故Linux必须找到并挂载第一个文件系统。 通常,可用的文件系统都列在/etc/fstab,所...
  • fickyou
  • fickyou
  • 2016年05月06日 15:19
  • 1706

从读手册开始让zynq板卡跑起linux(二)----利用initrd和initramfs分别制作根文件系统

initrd 与 initramfs根文件系统的制作
  • yuhaojin
  • yuhaojin
  • 2016年11月05日 16:59
  • 758

Linux INITRAMFS 与 INITRD

1. INITRAMFS 和INITRD(INITRAMDISK) 是什么?        RAMFS 和 RAMDISK 都是内存文件系统,他们有着小巧快速的特点。INIT前缀表示其包含有...
  • yuesichiu
  • yuesichiu
  • 2013年02月22日 09:49
  • 1675

mini2440 nfs+ramdisk+initramfs三种方法引导根文件系统

1.nfs (1)创建实验目录 # mkdir -p /home/chen/guoqian/4-3-3 将国嵌光盘的linux-2.6.29(在源代码4-3-1目录下)内核拷贝到当前目录 #p...
  • dragon101788
  • dragon101788
  • 2012年11月15日 18:39
  • 1158

利用busybox制作initramfs (2011-12-02 00:16)

标签:  initramfs  分类: Linux 《精通initramfs构建step by step》一文对initramfs进行了精彩的讨论,边读边做,将过程做如下记录: ...
  • mirkerson
  • mirkerson
  • 2012年12月24日 23:22
  • 5888

解压vmlinuz和解压initrd(initramfs)

原文网址: http://smilejay.com/2013/06/extract-vmlinuz-and-initrd/ ----------- 有时就算只得到一个Linux kernel...
  • junmuzi
  • junmuzi
  • 2014年03月26日 15:56
  • 3206

嵌入式Linux移植之initramfs

Linux可以将根文件系统编译进内核,称作initramfs。加载内核的时候,真实的内核和根文件系统都加载到内存。这在嵌入式系统中非常普遍,我们通常制作一个最小根文件系统initramfs,并把他编译...
  • huangbin0709
  • huangbin0709
  • 2016年10月01日 22:40
  • 704
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:initrd and initramfs
举报原因:
原因补充:

(最多只允许输入30个字)