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.
阅读(928) | 评论(0) | 转发(0) |