LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2007, 01:30 AM   #1
jamtech
LQ Newbie
 
Registered: May 2007
Distribution: Suse 10 and 11
Posts: 25

Rep: Reputation: 15
Creating A Ramdisk using a Bash Script


Hello All,

Below are a list of steps that I take when I need to create a Ramdisk to start Working with encrypted and unencrypted data. I do not want the unencrypted or encrypted data to be written to my hard drive.

My question is can you help me with turning the listed steps below into a working Bash Script so that I can call the script when needed instead of typing all these commands.

Thank you for taking the time to help.

Steps:

I review what has already been created
ls -l /dev/ram*

I find out what size the ramdisks are
[root]# dmesg | grep RAMDISK

I then Format the ramdisk
[root]# mke2fs -m 0 /dev/ram0

I Create a mount point and mount the ramdisk
[root]# mkdir /mnt/skunk
[root]# mount /dev/ram0 /mnt/skunk

I then verify the new ramdisk mount
[root]# mount | grep ram0
[root]# df -h | grep ram0

To make sure everything is ok with the new ramdisk I get a detailed look at the new ramdisk with this command:
[root]# tune2fs -l /dev/ram0

In my case, I need the user "skunk" to be able to read and write to the ramdisk, so I must change the ownership and permissions of the /mnt/skunk directory:
[root]# chown skunk:root /mnt/skunk
[root]# chmod 0770 /mnt/skunk
[root]# ls -ald /mnt/skunk

I then use the ramdisk

once done I unmount the ramdisk
[root]# umount -v /mnt/skunk
 
Old 10-08-2007, 06:34 PM   #2
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Why don't you put those into a script and try it.
Come back to us when/if you get stuck.
One tip: after each cmd, check the val of env var $? . Zero is good, anything else is bad.
 
Old 10-09-2007, 01:41 AM   #3
jamtech
LQ Newbie
 
Registered: May 2007
Distribution: Suse 10 and 11
Posts: 25

Original Poster
Rep: Reputation: 15
Per your request chrism01
I am only able to run this script as root but that is okay is there any way to stream line this script or make it better please make changes as needed?

<---Code Begin--->
#!/bin/bash
##########################################################################
# Title : ramdisk.sh - Creates a Hard drive in system memory (RAM)
# Author : Jamtech Janus@cyberspace.org
# Date : 2007-10-08
# Requires : Root account needed to run this script
# Category : Open
# Version. : Ramdisk 1.0 10/08/2007
##########################################################################
# Description:
#
# Permission is granted to reproduce and distribute this program
# with the following conditions:
# 1) This copyright notice and the author identification below
# must be left intact in the program and in any copies.
# 2) Any modifications to the program must be clearly identified
# in the source file.
#
# Modifications:
#
##########################################################################
# ==> Comments added by author ==>
#
# Lists Ram devices and to see what the ramdisks are
ls -l /dev/ram*
dmesg | grep RAMDISK
# Format the ramdisk
mke2fs -m 0 /dev/ram0
# Create a mount point and mount the ramdisk I named it skunk but you can choose to name the directory what you want.
mkdir /mnt/skunk
mount /dev/ram0 /mnt/skunk
# Verify the new ramdisk mount
mount | grep ram0
df -h | grep ram0
# Verfiy the ramdisk with full details
tune2fs -l /dev/ram0
# Give user "skunk" rights to read and write to the ramdisk, You can use any user that has an account on your system. just change the user name
chown Skunk:root /mnt/skunk
chmod 0770 /mnt/skunk
# Clears the screen
clear
# Change into the Mount Directory and list files and folders
cd /mnt/
ls -s
<---Code End--->
 
Old 10-10-2007, 06:56 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Well, as I pointed out, after each cmd, you should really check to see if they succeeded ie check the '$?' env var: http://tldp.org/LDP/abs/html/exit-status.html

You don't use the results of the 1st 2 lines; why? (debugging info only?)
Please use code tags [ code ] your code here [ /code ] to show your code here.

Try running your prog and see if it works.

Last edited by chrism01; 10-10-2007 at 06:59 AM.
 
Old 10-11-2007, 07:59 PM   #5
jamtech
LQ Newbie
 
Registered: May 2007
Distribution: Suse 10 and 11
Posts: 25

Original Poster
Rep: Reputation: 15
chrism01
Thanks for the help.
I am off to convert another a few more of my tasks into scripts
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Urgent : creating folder using bash script prernasin Linux - Newbie 2 09-26-2007 01:58 AM
creating a ramdisk runtime from another ramdisk code123 Linux From Scratch 0 10-11-2004 08:59 AM
Creating switches in a bash script Moto_Jon Programming 2 07-28-2004 06:06 PM
Help creating a Bash script gothicreader Linux - Newbie 4 10-10-2003 01:36 PM
need help creating a bash script zibertron Linux - General 3 01-31-2003 09:23 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:56 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration