Shell script for creating Virtual Disks in linux

Source: Internet
Author: User
The shell script for creating Virtual Disks in linux-general Linux technology-Linux programming and kernel information. The following is a detailed description. #! /Bin/bash
# Ramdisk. sh
# A "ramdisk" is a segment of system RAM memory
# + That acts as if it were a filesystem.
# Its advantage is very fast access (read/write time ).
# Disadvantages: volatility, loss of data on reboot or powerdown.
# Less RAM available to system.
#
# What good is a ramdisk?
# Keeping a large dataset, such as a table or dictionary on ramdisk
# + Speeds up data lookup, since memory access is much faster than disk access.
E_NON_ROOT_USER = 70 # Must run as root.
ROOTUSER_NAME = root
MOUNTPT =/mnt/ramdisk
SIZE = 2000 #2 K blocks (change as appropriate)
BLOCKSIZE = 1024 #1 K (1024 byte) block size
DEVICE =/dev/ram0 # First ram device
Username = 'id-nu'
If ["$ username "! = "$ ROOTUSER_NAME"]
Then
Echo "Must be root to run \" 'basename $0 '\"."
Exit $ E_NON_ROOT_USER
Fi
If [! -D "$ MOUNTPT"] # Test whether mount point already there,
Then # + so no error if this script is run
Mkdir $ MOUNTPT # + multiple times.
Fi
Dd if =/dev/zero of = $ DEVICE count = $ SIZE bs = $ BLOCKSIZE # Zero out RAM device.
Mke2fs $ DEVICE # Create an ext2 filesystem on it.
Mount $ DEVICE $ MOUNTPT # Mount it.
Chmod 777 $ MOUNTPT # So ordinary user can access ramdisk.
# However, must be root to unmount it.
Echo "\" $ MOUNTPT \ "now available for use ."
# The ramdisk is now accessible for storing files, even by an ordinary user.
# Caution, the ramdisk is volatile, and its contents will disappear
# + On reboot or power loss.
# Copy anything you want saved to a regular directory.
# After reboot, run this script again to set up ramdisk.
# Remounting/mnt/ramdisk without the other steps will not work.
Exit 0
Related Article

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.