Initrd/initramfs (am335x)

Source: Internet
Author: User
Tags creative commons attribution
InitrdTranslate this page to Initrd

After
Kernel booted, it tries to mount a file system. Using Linux on DaVinci, there are several options where this file system can come from. Options are

  • Harddisk or CompactFlash card
  • MMC/SD card
  • NFS (see

    DVEVM Getting Started Guide, sprue66c.pdf, section 4.3.4)
  • (Flash) file system in NOR or NAND
  • Ramdisk

The last option, an initial file system in a ram disk is calledInitrd(InitIal
RAmDIsk). Note that using an initrd with recent kernels 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 not permanently stored at the target device and thus normally used while development. initrd/initramfs is typically new installed/downloaded each time the target board is power cycled (using e.g. boot Loader
U-boot ). the two other options above (hard disk and FLASH file system) give the target system permanently access to its file system without any external debug connection (e.g. network download) and thus are used
AfterDevelopment in production ready devices.

Contents

[Hide]

  • 1
    Initrd

    • 1.1
      Creation
    • 1.2
      Filling
    • 1.3
      Kernel options
    • 1.4
      Installation
  • 2
    Initramfs

    • 2.1
      Creation
    • 2.2
      Kernel options
    • 2.3
      Installation
  • 3
    Initrd vs. initramfs
InitrdCreation

To create an (initially empty) initrd use the following steps:

Note: ChangeCountTo your required filesystem size. E. g. With Count = 8192 you will get a 8 Mb ramdisk.

host > dd if=/dev/zero of=/dev/ram0 bs=1k count=<count>host > mke2fs -vm0 /dev/ram0 <count>host > tune2fs -c 0 /dev/ram0host > 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 for ramdisk, mount the image and fill it. Content wocould be e.g.

BusyBox and/or other applications and/or libraries.

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

The resulting ramdisk.gz is now ready for usage. Note its size is smaller than <Count> Cause of compression.

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

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

Kernel options

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

## General setup#...CONFIG_BLK_DEV_INITRD=yCONFIG_INITRAMFS_SOURCE=""...## UBI - Unsorted block images#...CONFIG_BLK_DEV_RAM=yCONFIG_BLK_DEV_RAM_COUNT=1CONFIG_BLK_DEV_RAM_SIZE=8192CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024...

Note: The ramdisk size e.g. 8192 abve has to be configured for your 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 tftpboot directory on host (e.g. /tftpboot/ramdisk.gz ). then start target and copy the data into RAM and flash:

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

Note: ReplaceFilesizeAbove by the value the tftp download command gives you
Bytes transferred.

Now, last step is to update kernel boot parameters and save them

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

Note: In example abve with "8 M" we assume that your ramdisk is 8MBytes. Adapt this to your needs.

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

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

To make this work properly.

Now you shoshould be able to start your kernel and it shoshould find and mount the initrd:

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

To use initramfs
Cpio archive is embedded directly into the kernel. i. e. you don't create an additional (ramdisk) image. instead, the initial file system is directly ininitialized into the kernel. with this, the kernel size increases by the file system size. it's like you
Embed above ramdisk directly into the kernel.

Creation

Cause initramfs is directly embedded in the kernel, its creation is simpler. no dd & mount & gzip stuff like with ramdisk abve. you simply have to fill a directory on your host with the target filesystem you like and then pass the path to this directory
To the kernel build process.

Create target file system

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

Note: cpio system used for initramfs can't handle
Hard links. If you e.g. created your BusyBox using hard links, you will get a quite large initramfs cause each command is taken with its 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 top level directory has to contain a program called
Init. For example, this can be done by using a soft link from top level init to/bin/busybox (assuming you are using BusyBox in your initramfs ).

/init -> /bin/busybox

To create the cpio archive execute the following commands.

host > cd target_fshost > find . | cpio -H newc -o > ../target_fs.cpio
Kernel options

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

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

Then, if you compile the kernel, e.g. by make uImage, the cpio archive 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

NoSpecial installation like abve with initrd is necessary. The initramfs is already in the kernel. If you start the kernel, the initramfs is already there. Therefore, there is
No Root =/dev/ram0 rw initrd = 0x87000000,8 MBootargs option 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 is smaller.
  • Creating and modifying an initramfs is easier than with initrd (unzip & mount & unmount & zip)
  • Having one big image (kernel & initramfs) is easier to handle (e.g. download or flashing) than having two splitted images.
For technical support please post your questions
Http://e2e.ti.com. Please post only comments about the articleInitrdHere.
Links
ARM Microcontroller MCU ARM Processor Digital Media Processor Digital Signal Processing Microcontroller MCU Multi Core Processor
Ultra Low Power DSP 8-bit Microcontroller MCU 16-bit Microcontroller MCU 32 bit Microcontroller MCU
Category:
Linux

Leave a Comment

Comments

Noinitrd-Is it important to discuss this u-boot option as well? It is used in a number of places, including the OpenGL ES get1_started guide

Jsarao, 2 November 2009 (UTC)

  • Log in/create account
  • Page
  • Discussion
  • Read
  • View source
  • View history
Navigation
  • Main Page
  • All pages
  • All categories
  • Popular pages
  • Popular authors
  • Popular categories
  • Category stats
  • Recent changes
  • Random page
  • Help
  • Google Search
Print/export
  • Create a book
  • Download as PDF
  • Printable version
Toolbox
  • What links here
  • Related changes
  • Special pages
  • Permanent link
  • Browse properties
  • This page was last modified on 8 December 2010,.
  • This page has been accessed 48,447 times.
  • Content is available under
    Creative Commons Attribution-Share Alike 3.0 license.
  • Privacy policy
  • About Texas Instruments Embedded Processors Wiki
  • Disclaimers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.