Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to make RamDisk in Linux system

2025-02-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I will show you how to make RamDisk in Linux system. The content of the article is good. Now I would like to share it with you. Friends who feel in need can understand it. I hope it will be helpful to you. Let's read it along with the editor's ideas.

Virtual memory disk is a technology that simulates part of the memory (RAM) into a hard disk by software. Compared with the direct hard disk file access, this technology can greatly improve the speed of file access.

The concrete method of making RamDisk in Linux system.

Introduction to RamDisk:

As the name implies, Ram: memory, Disk: disk, RamDisk refers to the use of part of your memory space to simulate a hard disk partition. However, this does not seem to be very useful today when the hard drive is getting cheaper and cheaper, but now the memory is getting cheaper and cheaper. For some cases where we want its access speed to be very high, we can still try it.

I tested the operating environment with Red Hat 9, but this should apply to other Linux systems with 2.4 kernels, and I also assume that your Linux system has compiled RamDisk support into the kernel. My computer uses a Pentium 4 processor with 256 MB of memory. The exact kernel version is 2.4.20-20.9.

The specific steps of making RamDisk with Linux system are as follows: 1. See what your system has created.

RedHat creates 16 RamDisk by default, although they do not activate or use any Ram. The devices listed by the system are ram0ram19, but only ram0ram15 is available by default. Use the following command to check out these block devices:

[root] # ls-l / dev/ram* lrwxrwxrwx 1 root root 4 Jun 12 00:31 / dev/ram-> ram1 brw-rw---- 1 root disk 1, 0 Jan 30 2003 / dev/ram0 brw-rw---- 1 root disk 1, 1 Jan 30 2003 / dev/ram1 brw-rw---- 1 root disk 1 10 Jan 30 2003 / dev/ram10 brw-rw---- 1 root disk 1, 11 Jan 30 2003 / dev/ram11 brw-rw---- 1 root disk 1, 12 Jan 30 2003 / dev/ram12 brw-rw---- 1 root disk 1, 13 Jan 30 2003 / dev/ram13 brw-rw---- 1 root disk 1 14 Jan 30 2003 / dev/ram14 brw-rw---- 1 root disk 1, 15 Jan 30 2003 / dev/ram15 brw-rw---- 1 root disk 1, 16 Jan 30 2003 / dev/ram16 brw-rw---- 1 root disk 1, 17 Jan 30 2003 / dev/ram17 brw-rw---- 1 root disk 1 18 Jan 30 2003 / dev/ram18 brw-rw---- 1 root disk 1, 19 Jan 30 2003 / dev/ram19 brw-rw---- 1 root disk 1, 2 Jan 30 2003 / dev/ram2 brw-rw---- 1 root disk 1, 3 Jan 30 2003 / dev/ram3 brw-rw---- 1 root disk 1 4 Jan 30 2003 / dev/ram4 brw-rw---- 1 root disk 1, 5 Jan 30 2003 / dev/ram5 brw-rw---- 1 root disk 1, 6 Jan 30 2003 / dev/ram6 brw-rw---- 1 root disk 1, 7 Jan 30 2003 / dev/ram7 brw-rw---- 1 root disk 1 8 Jan 30 2003 / dev/ram8 brw-rw---- 1 root disk 1, 9 Jan 30 2003 / dev/ram9 lrwxrwxrwx 1 root root 4 Jun 12 00:31 / dev/ramdisk-> ram0 now Use grep to find out the size of RamDisk in the output of dmesg

[root] # dmesg | grep RAMDISK RAMDISK driver initialized: 16 RAM disks of 4096K size 1024 blocksize RAMDISK: Compressed image found at block 0 you can see, RamDisk defaults to 4MB. I want a RamDisk for 16MB, so the next step is to configure Linux to use a larger RamDisk during startup.

two。 Increase the size of * * RamDisk * *

The size of the RamDisk is controlled by a command line option that is passed to the kernel when the system boots. Since the default bootloader for RedHat9 is GRUB, I will modify the kernel option of / etc/grub.conf,RamDisk size with the new option: ramdisk_size=xxxxx, where xxxxx refers to the number of chunks of 1024-Byte size. Here's what I want to add to / etc/grub.conf, which configures RamDisk as 16MB:

# grub.conf generated by anaconda # # Note that you do not have to rerun grub after making changes to this file # NOTICE: You have a / boot partition. This means that # all kernel and initrd paths are relative to / boot/, eg. # root (hd0,0) # kernel / vmlinuz-version ro root=/dev/hda5 # initrd / initrd-version.img # boot=/dev/hda default=0 timeout=10 splashimage= (hd0,0) / grub/splash.xpm.gz title Red Hat Linux (2.4.20-20.9) root (hd0,0) kernel / vmlinuz-2.4.20-20.9 ro root=LABEL=/ hdc=ide-scsi ramdisk_size=16000 initrd / initrd-2. 4.20-after 20.9.img saves the file You need to restart the system. After restarting, check the output of dmesg to confirm that the modification has taken effect:

[root] # dmesg | grep RAMDISK RAMDISK driver initialized: 16 RAM disks of 16000K size 1024 blocksize RAMDISK: Compressed image found at block 03. Format * * RamDisk**

Instead of formatting RamDisk as a journaling file system, we will use the EXT2 file system. I only want to use one RamDisk, so I only format ram0.

[root] # mke2fs-M0 / dev/ram0 mke2fs 1.32 (09-Nov-2002) Filesystem label= OS type: Linux Block size=1024 (log=0) Fragment size=1024 (log=0) 4000 inodes, 16000 blocks 0 blocks (0.005%) reserved for the super user First data block=1 2 block groups 8192 blocks per group, 8192 fragments per group 2000 inodes per group Superblock backups stored on blocks: 8193 Writing inode tables: done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 22 mounts or 180 days, whichever comes first. The Use tune2fs-c or-I to override.-m 0 option specifies that the proportion of root user-reserved chunks on the file system is 0, which is the default feature. I hope the average user can use all the RamDisk space.

4. Create a new mount point and mount * * RamDisk**

Now that you have formatted RamDisk, you need to create a new mount point for it. Then you can mount your RamDisk and use it. We will use the / mnt/rd folder.

[root] # mkdir / mnt/rd [root] # mount / dev/ram0 / mnt/rd detect newly mounted RamDisk

[root] # mount | grep ram0 / dev/ram0 on / mnt/rd type ext2 (rw) [root] # df-h | grep ram0 / dev/ram0 16m 13K 16M1 / mnt/rd you can use the tune2fs command to view the details of the new RamDisk

[root] # tune2fs-l / dev/ram0 tune2fs 1.32 (09-Nov-2002) Filesystem volume name: none Last mounted on: not available Filesystem UUID: fbb80e9a-8e7c-4bd4-b3d9-37c29813a5f5 Filesystem magic number: 0xEF53 Filesystem revision #: 1 (dynamic) Filesystem features: filetype sparse_super Default mount options: (none) Filesystem state: not clean Errors behavior: Continue Filesystem OS type: Linux Inode count: 4000 Block count: 16000 Reserved block count: 0 Free blocks: 15478 Free inodes: 3989 First block: 1 Block size: 1024 Fragment size: 1024 Blocks per group: 8192 Fragments per group: 8192 Inodes per group: 2000 Inode blocks per group: 250 Filesystem created: Mon Dec 8 14:33:57 2003 Last mount time: Mon Dec 8 14:35:39 2003 Last write time: Mon Dec 8 14:35:39 2003 Mount count: 1 Maximum mount count: 22 Last checked: Mon Dec 8 14:33:57 2003 Check interval: 15552000 (6 months) Next check after: Sat Jun 5 14:33:57 2004 Reserved blocks uid: 0 ( User root) Reserved blocks gid: 0 (group root) First inode: 11 Inode size: 128in my system I need the 'var' user to be able to read and write RamDisk, so I have to modify the owner and permissions of the / mnt/rd folder.

[root] # chown van:root / mnt/rd [root] # chmod 0770 / mnt/rd [root] # ls-ald / mnt/rd drwxrwx--- 2 van root 4096 Dec 8 11:09 / mnt/rdRamDisk mount point owner and permissions should be modified according to your specific situation.

5. Use * * RamDisk**

Now that the RamDisk has been created, you can copy, move, delete, edit or list files on the RamDisk as you would on a physical hard disk partition. This is a good place to view encrypted GPG or OpenSSL files, and a good place to create encrypted files. When your host shuts down, all files created on RamDisk will disappear.

You can easily uninstall RamDisk with the following command:

[root] # umount-v / mnt/rd / dev/ram0 umountedNote**:** if you uninstall RamDisk, your data will still be there. Once memory is allocated to RamDisk, it is marked and then the kernel does not attempt to reuse the memory. Of course, you can also free up space after rebooting.

Automatically create * * RamDisk**

If you need to create and mount RamDisk after each system boot, you can automatically execute this process by adding commands to the / etc/rc.local startup script.

Here is the command I added:

# Formats, mounts, and sets permissions on my 16MB ramdisk

/ sbin/mke2fs-Q-M0 / dev/ram0

/ bin/mount / dev/ram0 / mnt/rd

/ bin/chown van:root / mnt/rd

/ bin/chmod 0750 / mnt/rd

What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.

These are all the contents of how to make RamDisk in Linux system. For more content related to how to make RamDisk in Linux system, you can search the previous articles or browse the following articles to learn! I believe the editor will add more knowledge to you. I hope you can support it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report