Chinaunix首页 | 论坛 | 博客
  • 博客访问: 416116
  • 博文数量: 99
  • 博客积分: 65
  • 博客等级: 民兵
  • 技术积分: 1012
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-20 16:30
个人简介

linux kernel 工程师

文章分类

全部博文(99)

文章存档

2018年(5)

2017年(12)

2016年(27)

2015年(10)

2014年(43)

2012年(2)

我的朋友

分类: LINUX

2018-01-31 16:20:19

How to create a ramdisk image using existing FS

1. Regular method
=================

Create an empty ramdisk image
-----------------------------

Enter your working directory, excute
#dd if=/dev/zero of=./ramdisk bs=1M count=2000
This command create a image named ramdisk about 2000M

Then format it to be a ext2 FS
#mke2fs -F -v ramdisk

Now ramdisk is formatted to an ext2 ramdisk image, even there is almost nothing in it.


Mount the empty ramdisk to a dir
--------------------------------

In your working directory , create a directory,
#mkdir tmp

Then mount the ramdisk image to this directory,
#sudo mount -o loop ramdisk tmp

Now the tmp directory is your rootfs, you can copy your real rootfs to it.
For example:

cp -r /media/wr8/realfs/* tmp/


Finish your ramdisk creating
----------------------------
#sync
#umount tmp

Now the ramdisk image holds your real fs in it.
You can compresss it at this time:
gzip -v9 ramdisk

After this command, a file named ramdisk.gz is gernerated.

2. CPIO method
=================
For a directory which hold a rootfs, using the following command to
create a ramdisk:


#cd path_to_working_dir/root_dir
#sudo find . | cpio -o -H newc > ../ramdisk
#cd ..
#gzip -v9 ramdisk

Here path_to_working_dir/root_dir holds the rootfs.
The ramdisk.gz is generated in path_to_working_dir.

when you boot ramdisk generated by cpio, there are two point to emphasize:
1. If there is no "init" file in "path_to_working_dir/root_dir", you should add
   "rdinit=xxx", e.g. "rdinit=/sbin/init" to the boot command line.
2. The "root=/dev/ram0" and "ramdisk_size=xxx" in the boot command line are not necessary.


another method for creating cpio format ramdisk:
#cd working_dir
#cp linux_souce/scripts/gen_initramfs_list.sh ./
#mkdir usr
#cp linux_build/usr/gen_init_cpio ./usr/
#./gen_initramfs_list -o cpio.gz -u 0 -g 0 root_dir

Here root_dir is the directory holding the rootfs , and the cpio.gz is the generated initramfs image
in gzipped format.









阅读(873) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~