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.