Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Formatting ramdisks on boot
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Unsupported Software
View previous topic :: View next topic  
Author Message
pa4wdh
Guru
Guru


Joined: 16 Dec 2005
Posts: 301

PostPosted: Thu Jul 31, 2008 6:48 pm    Post subject: Formatting ramdisks on boot Reply with quote

Hi All,

I'm planning to use some ramdisks on my system, and as a result of that i need to format them before localmount can mount them.
As far as i could see Gentoo doesn't provide any standard way of handling this, so i wrote my own script and added it to the boot runlevel.

This is the script:
Code:

#!/sbin/runscript                                                               
                                                                               
depend() {                                                                     
        need checkfs                                                           
        before localmount                                                       
}                                                                               
                                                                               
start() {                                                                       
        ebegin "Starting ramdisks"                                             
        for DEV in $RAMDISK_DEV                                                 
        do                                                                     
                ebegin "Formatting $DEV with $RAMDISK_FS"                       
                mkfs.$RAMDISK_FS $RAMDISK_OPTS $DEV > /dev/null                       
                eend $?                                                         
        done                                                                   
        eend 0                                                                 
}                                                                               
                                                                               
stop() {                                                                       
        ebegin "Stopping ramdisks"                                             
        eend 0                                                                 
}                                                                               

And the variables RAMDISK_DEV RAMDISK_FS and RAMDISK_OPTS come from /etc/conf.d/ramdisk:
Code:

# Configuration file for ramdisks on boot                                       
                                                                               
# Filesystem to use                                                             
RAMDISK_FS="ext2"                                                               
                                                                               
# Devices to format                                                             
RAMDISK_DEV="/dev/ram1 /dev/ram2"                                               
                                                                               
# Extra options to give to mkfs.$RAMDISK_FS                                     
RAMDISK_OPTS="" 


As far as i understand "need checkfs" will make the script run *after* checkfs, and "before localmount" should ensure it runs before localmount.

However, on reboot, this is what i see:
Code:

 * Mounting local filesystems ...                                         [ ok ]
 * Mounting USB device filesystem (usbfs) ...                             [ ok ]
 * Activating (possible) swap ...                                         [ ok ]
 * Setting system clock using the hardware clock [UTC] ...                [ ok ]
 * Configuring kernel parameters ...                                      [ ok ]
 * Updating environment ...                                               [ ok ]
 * Cleaning /var/lock, /var/run ...                                       [ ok ]
 * Wiping /tmp directory ...                                              [ ok ]
 * Device initiated services: udev-postmount                                   
 * Starting ramdisks ...                                                       
 * Formatting /dev/ram1 with ext2 ...mke2fs 1.40.9 (27-Apr-2008)               
                                     [ ok ]                                     
 * Formatting /dev/ram2 with ext2 ...mke2fs 1.40.9 (27-Apr-2008)               
                                     [ ok ]                                     
                                                                          [ ok ]
 * Setting hostname to pc10 ...                                           [ ok ]
 * Loading key mappings ...                                               [ ok ]

The ramdisks are mounted after mounting the local filesystems ... what else can i do to change the order to what i need ?

Best regards,
pa4wdh

Ps.: Just in case someone wants to warn me: I know i'm playing with fire, putting /dev/sda1 in RAMDISK_DEV would effectively destroy my install ... i know :-)
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse world

Free as in Freedom is not limited to software only:
Music: http://www.jamendo.com
Recipes: http://www.opensourcefood.com
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2968
Location: Germany

PostPosted: Thu Jul 31, 2008 9:45 pm    Post subject: Reply with quote

Why does it have to be ramdisks? You could just use tmpfs?
Back to top
View user's profile Send private message
pa4wdh
Guru
Guru


Joined: 16 Dec 2005
Posts: 301

PostPosted: Fri Aug 01, 2008 5:41 am    Post subject: Reply with quote

Hi,

First of all i'm not too familiar with tmpfs :-)

However, i also like the way ramdisks work: A limited amount of memory to be used as disk space, so i'll also make them different in size.
The different ramdisks will serve different goals in the system. One being an anonymous ftp server which allows me to put them somewhere and pick them up later. An other one will be info that's generated on the fly (and i don't care losing it on reboot). Maybe there'll be even a third later, but not for this moment.
The basic goal is that the system will have almost no access to the HDD for regular tasks, so the harddrive and shut down as much as possible.

I'll also take a closer look at tmpfs ....

Best regards,
pa4wdh
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse world

Free as in Freedom is not limited to software only:
Music: http://www.jamendo.com
Recipes: http://www.opensourcefood.com
Back to top
View user's profile Send private message
pigeon768
l33t
l33t


Joined: 02 Jan 2006
Posts: 675

PostPosted: Fri Aug 01, 2008 1:53 pm    Post subject: Reply with quote

I definitely think tmpfs is better suited to your goals. Just need to make a service that will copy the data you need to be persistent into and out of your tmpfs on boot and shutdown.
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 5618
Location: Removed by Neddy

PostPosted: Fri Aug 01, 2008 2:25 pm    Post subject: Reply with quote

that is what the size= option to tmpfs is for

Code:

grep /tmp /etc/fstab
tmpfs         /tmp         tmpfs      defaults,nosuid,size=1024M,mode=1777   0 0

tmpfs is the best choice here
_________________
The best argument against democracy is a five-minute conversation with the average voter
Great Britain is a republic, with a hereditary president, while the United States is a monarchy with an elective king
Back to top
View user's profile Send private message
pa4wdh
Guru
Guru


Joined: 16 Dec 2005
Posts: 301

PostPosted: Fri Aug 01, 2008 5:00 pm    Post subject: Reply with quote

Hi All,

Thanks for all responses. I've read and learned about tmpfs, and it's the way to go ! It's much more flexible than the ramdisk setup, not as risky (mkfs in a script), and i don't need to mkfs at all ... when the goal is to build a functioning system in a 8 or 16 MB image, that's wonderful (mkfs.ext2 + libs is over 1 MB in size !).

I've added tmpfs lines to my fstab and it immediately worked, so i removed the ramdisk script from the boot sequence.

Thanks for the tips.

Best regards,
pa4wdh
_________________
The gentoo way of bringing peace to the world:
USE="-war" emerge --newuse world

Free as in Freedom is not limited to software only:
Music: http://www.jamendo.com
Recipes: http://www.opensourcefood.com
Back to top
View user's profile Send private message
pigeon768
l33t
l33t


Joined: 02 Jan 2006
Posts: 675

PostPosted: Sat Aug 02, 2008 8:55 am    Post subject: Reply with quote

Also, tmpfs' size= option is maximum size, not how much it will always use- if you set size=10240M, but all you have in it is a 2kB file, it will only use 2k ram, not 10 gigs.
Back to top
View user's profile Send private message
asturm
Developer
Developer


Joined: 05 Apr 2007
Posts: 6929
Location: Austria

PostPosted: Sat Aug 02, 2008 9:26 am    Post subject: Reply with quote

Hm, is there a way to dump a tmpfs image to the HDD at shutdown and reload it from there again at boot-time?
_________________
backend.cpp:92:2: warning: #warning TODO - this error message is about as useful as a cooling unit in the arctic
Back to top
View user's profile Send private message
Naib
Watchman
Watchman


Joined: 21 May 2004
Posts: 5618
Location: Removed by Neddy

PostPosted: Sat Aug 02, 2008 10:20 am    Post subject: Reply with quote

genstorm wrote:
Hm, is there a way to dump a tmpfs image to the HDD at shutdown and reload it from there again at boot-time?


short of a tar of the folder pre-shutdown and untar after mount I don't think so
_________________
The best argument against democracy is a five-minute conversation with the average voter
Great Britain is a republic, with a hereditary president, while the United States is a monarchy with an elective king
Back to top
View user's profile Send private message
frostschutz
Advocate
Advocate


Joined: 22 Feb 2005
Posts: 2968
Location: Germany

PostPosted: Sat Aug 02, 2008 10:28 am    Post subject: Reply with quote

Naib wrote:
tar of the folder pre-shutdown and untar after mount


That's how it's usually done (by udev et al). tmpfs does not have a fixed size (at most it has a quota like size limit) so it's not possible to dd an image of it.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Unsupported Software All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum