转自:https://abcamus.github.io/2017/01/06/%E5%85%B3%E4%BA%8Einitrd%E5%92%8Cinitramfs/
ram disk中的file system叫做initrd,全名叫做initial ramdisk。
注意: 当下用initrams多
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
这段代码就创建了大小为count的ramdisk
还要添加一些必要的文件让他工作,可能是库,应用程序等。例如busybox。
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
#
# 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
...
UBOOT # tftp 0x87000000 ramdisk.gz
UBOOT # erase 0x2200000 +0x<filesize>
UBOOT # cp.b 0x87000000 0x2200000 0x<filesize>
UBOOT # setenv bootargs ... root=/dev/ram0 rw initrd=0x87000000,8M
UBOOT # setenv bootcmd cp.b 0x2200000 0x87000000 0x<filesize>; bootm
UBOOT # saveenv
注意: ramdisk 中要有ram0节点
brw-rw---- 1 root disk 1, 0 Sep 11 1999 /dev/ram0
initramfs相当于把initrd放进了内核,通过cpio(这是一个文件处理工具)实现。
比initrd简单多了
host > mkdir target_fs
host > ... copy stuff you want to have in initramfs to target_fs...
注意:
- initramfs中的cpio系统不能处理hard link,用soft link
- 顶层必须有个init程序,这是kernel要用的,可以这么做
/init -> /bin/busybox
接着
host > cd target_fs
host > find . | cpio -H newc -o > ../target_fs.cpio
#
# 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
然后执行make uImage的时候就被包含到kernel中了。
因为已经在kernel中了,不需要像initrd一样通过参数 root=/xxx rw initrd=xxx来告诉uboot了
原文:https://www.cnblogs.com/sky-heaven/p/13737350.html