initrd and initramfs

Initrd

From Texas Instruments Embedded ProcessorsWiki

Jump to: navigation, search

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.

利用 TensorFlow 训练自己的目标识别器。本文内容来自于我的毕业设计,基于 TensorFlow 1.15.0,其他 TensorFlow 版本运行可能存在问题。.zip项目工程资源经过严格测试可直接运行成功且功能正常的情况才上传,可轻松复刻,拿到资料包后可轻松复现出一样的项目,本人系统开发经验充足(全领域),有任何使用问题欢迎随时与我联系,我会及时为您解惑,提供帮助。 【资源内容】:包含完整源码+工程文件+说明(如有)等。答辩评审平均分达到96分,放心下载使用!可轻松复现,设计报告也可借鉴此项目,该资源内项目代码都经过测试运行成功,功能ok的情况下才上传的。 【提供帮助】:有任何使用问题欢迎随时与我联系,我会及时解答解惑,提供帮助 【附带帮助】:若还需要相关开发工具、学习资料等,我会提供帮助,提供资料,鼓励学习进步 【项目价值】:可用在相关项目设计中,皆可应用在项目、毕业设计、课程设计、期末/期中/大作业、工程实训、大创等学科竞赛比赛、初期项目立项、学习/练手等方面,可借鉴此优质项目实现复刻,设计报告也可借鉴此项目,也可基于此项目来扩展开发出更多功能 下载后请首先打开README文件(如有),项目工程可直接复现复刻,如果基础还行,也可在此程序基础上进行修改,以实现其它功能。供开源学习/技术交流/学习参考,勿用于商业用途。质量优质,放心下载使用。
initrd、rootfsinitramfs是在Linux系统中用于引导和初始化的概念,它们之间有一些区别和作用。 1. initrdInitial RAM Disk)是一个临时的根文件系统,它是在系统引导过程中由内核加载到内存中的。它通常包含一些必要的驱动程序和工具,用于在真正的根文件系统(rootfs)加载之前进行一些初始化操作。initrd最初是为了解决早期Linux系统在引导过程中无法识别硬件的问题而设计的。它的作用是提供一个临时的根文件系统,以便在引导过程中加载必要的驱动程序和模块,从而能够识别和访问硬件设备。 2. rootfs(Root File System)是Linux系统中的根文件系统,它是系统中所有其他文件系统的基础。rootfs包含了操作系统的核心文件和目录结构,它是系统引导后的第一个文件系统。在引导过程中,initrd会被加载到内存中,然后解压缩到rootfs中。一旦rootfs加载完成,系统将切换到rootfs作为根文件系统,并执行init程序来完成系统的初始化和启动。 3. initramfsInitial RAM File System)是initrd的一种改进版本,它是一个压缩的文件系统映像,也是在系统引导过程中由内核加载到内存中的。与initrd不同,initramfs不需要解压缩到内存中的临时文件系统中,而是直接在内存中解压缩并挂载为根文件系统。initramfs的作用与initrd类似,它提供了一个临时的根文件系统,用于在引导过程中加载必要的驱动程序和模块。 总结: - initrd是早期Linux系统中使用的临时根文件系统,用于在引导过程中加载必要的驱动程序和模块。 - rootfs是Linux系统中的根文件系统,包含了操作系统的核心文件和目录结构。 - initramfsinitrd的改进版本,它是一个压缩的文件系统映像,直接在内存中解压缩并挂载为根文件系统。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值