Build ramdisk for Embedded Linux

Source: Internet
Author: User

1. Go to the working directory and create the desired directory.
$ Mkdir rdmnt // directory mounted to the new ramdisk
$ Mkdir rdimg // directory of the image file generated
$ Mkdir rdold // old ramdisk file directory
$ Mkdir rdold/tmp // directory for mounting the old ramdisk

2. Mount the old ramdisk
$ Mount-o loop rdold/ramdisk rdold/tmp

3. Create a New ramdisk and initialize it.
$ Dd If =/dev/Zero of = rdimg/ramdisk. img bs = 1 k count = 15360
// Creates a 15 m ramdisk image file and initializes it with the/dev/Zero device.

4. Create a file system for the image file
$ Mke2fs-F-v-M0 rdimg/ramdisk. img

5. mount a new ramdisk.
$ Mount-o loop rdimg/ramdisk. IMG rdmnt

6. Copy the required file to the new ramdisk.
$ CP-AV rdold/tmp/* rdmnt

7. unmount the old ramdisk
$ Umount rdold/tmp

8. unmount the new ramdisk.
$ Umount rdmnt

9. Make the new ramdisk into a compressed package.
$ Gzip-9 rdimg/ramdisk. IMG ramdisk.gz
Ramdisk.gz is the newly created ramdisk image.

To facilitate the establishment of the two shell scripts created by the author, it can quickly create the required ramdisk image.

Shell script: createrd creates a new ramdisk and mounts and copies the old file.
#! /Bin/sh
Rm rdimg /*
Mount-o loop rdold/ramdisk rdold/tmp
Dd If =/dev/Zero of = rdimg/ramdisk BS = 1 k count = 15360
Mke2fs-F-v-M0 rdimg/ramdisk
Mount-o loop rdimg/ramdisk rdmnt
CP-AV rdold/tmp/* rdmnt
Umount rdold/tmp

Shell script: completerd unmount ramdisk and compress it (and finally copy it to the target directory)
#! /Bin/sh
Umount rdmnt
Gzip-C-9 <rdimg/ramdisk> rdimg/ramdisk.gz
CP rdimg/ramdisk.gz/opt/linuxshare

[note] After the script is edited, remember to use chmod + x filename to make it executable.

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.