LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 12-06-2014, 11:49 AM   #1
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Rep: Reputation: 45
Install OS on a RAM disk


How would I install all of Slackware to a RAM disk, not just the kernel and modules with mkinitrd?

I know Porteus has an option which essentially seems to copy the root, "/", to a RAM disk. How does it do it?

Would I just need to make a huge initrd image? If so, how would I do that?

Specifically: What I would like to do is boot off the Slackware ISO, mount a RAM disk, run the Slackware installer to install to the RAM disk, and then pack the entire RAM disk into an initrd image. How would I do this?

thanks

Last edited by Geremia; 12-13-2014 at 04:17 PM. Reason: added more detail into a "specifically" section
 
Old 12-06-2014, 03:49 PM   #2
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by Geremia View Post
Would I just need to make a huge initrd image? If so, how would I do that?
That's a possibility.

Just unpack the initrd, let's assume the root of the tree be then /tmp/initrd, then to add the packages you want:
Code:
installpkg --root /tmp/initrd <list of /paths/to/the/packages>
Then repack the initrd, rebuild the ISO image and off you go.

PS Of course, check that you have enough RAM to host all that stuff

Last edited by Didier Spaier; 12-06-2014 at 03:52 PM.
 
2 members found this post helpful.
Old 12-06-2014, 06:41 PM   #3
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by Didier Spaier View Post
Just unpack the initrd, let's assume the root of the tree be then /tmp/initrd, then to add the packages you want:
Code:
installpkg --root /tmp/initrd <list of /paths/to/the/packages>
Then repack the initrd, rebuild the ISO image and off you go.
This is a really good idea, but how to I pack and unpack an initrd image?
merci

Last edited by Geremia; 12-06-2014 at 06:44 PM.
 
Old 12-06-2014, 08:35 PM   #4
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
The initrd.img file is a gzipped cpio archive.

# zcat initrd.img | cpio -i

You may want to do this in an empty subdirectory, since it will create the /* files in the pwd.

Last edited by ttk; 12-06-2014 at 08:35 PM. Reason: oops .. typed -f instead of -i
 
1 members found this post helpful.
Old 12-06-2014, 08:56 PM   #5
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by ttk View Post
# zcat initrd.img | cpio -i
My cpio doesn't have an "-i" option...

This site says:

to unpack:
Code:
gzip -dc < /boot/initrd.img  | cpio -i
to pack:
Code:
find . -print -depth | cpio -o -H newc > initrd.img

Last edited by Geremia; 12-06-2014 at 09:02 PM.
 
Old 12-07-2014, 02:11 PM   #6
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by Geremia View Post
My cpio doesn't have an "-i" option...
Wrong, if it comes from Slackware.

FWIW; here are the small scripts i use:
Code:
#!/bin/sh
if [ ! "$#" = "2" ]; then
  echo "unpack an initrd in /tmp/initrd-<suffix>
  usage: ./unpack_initrd.sh <path/to/initrd> <suffix>"
  exit
fi
if [ ! $UID -eq 0 ]; then
  gettext "Please execute this script as root."
  echo
  exit
fi  
TMP=/tmp/initrd-$2
if [ -e $TMP ]; then
  echo "$TMP already exists."
  exit
fi
mkdir $TMP
( cd $TMP
  gunzip -cd $1 | \
  cpio -i -d -m -H newc --no-absolute-filenames
) 1>>${TMP}/log.txt 2>>${TMP}/log.txt
Code:
#repack
( cd /root/of/the/unpacked/initrd
  find . -print | cpio -o --owner root:root -H newc | gzip -9 > /path/to/initrd.gz
)
Of course this is very simplistic: that works for gzipped initrds only (all Slackware initrds are gzipped).

A more general solution would be to do a "file <name of the initrd>", parse the output and select the compression program accordingly.

Also, sometimes no compression program is used. In that case you can just cat the initrd through a pipe to cpio.

There also the possibility that tar be used instead of cpio.

In short: if the initrd is an alien, always do a "file" on it first.

But, I digress it seems

Last edited by Didier Spaier; 12-07-2014 at 02:45 PM.
 
1 members found this post helpful.
Old 12-07-2014, 02:46 PM   #7
ttk
Senior Member
 
Registered: May 2012
Location: Sebastopol, CA
Distribution: Slackware64
Posts: 1,038
Blog Entries: 27

Rep: Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484Reputation: 1484
Just an addendum: Checking the Linux source code, initramfs.c appears to error out unless the initrd file is, very specifically, a "newc" (SRV4 sans CRC) formatted file, optionally compressed.

/usr/src/linux-3.10.17/init/initramfs.c on my machine, line 231. Haven't checked newer kernels to see if they've expanded to accept other formats for initramfs.

That's specific to the initramfs method; using the initrd method, a filesystem image may be used instead, formatted to any filesystem supported in the kernel (ext2, ext3, fat, etc).

http://en.wikipedia.org/wiki/Initrd does a pretty good job of explaining the differences between initramfs method (used by Slackware) and initrd method.
 
1 members found this post helpful.
Old 12-08-2014, 02:05 AM   #8
MDKDIO
Member
 
Registered: Mar 2004
Location: Sweden
Distribution: Slackware 15
Posts: 521

Rep: Reputation: 187Reputation: 187
This won't answer the question, but might give you an idea on how one can make it work

http://www.slax.org/

And yes, Slax can be installed to RAM as well. And it's based on Slackware.

Checkout the documentation, some nice reading there
 
Old 12-09-2014, 09:37 AM   #9
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by MDKDIO View Post
This won't answer the question, but might give you an idea on how one can make it work

http://www.slax.org/

And yes, Slax can be installed to RAM as well. And it's based on Slackware.

Checkout the documentation, some nice reading there
Yes, thank you
I mentioned Porteus, which is similar to Slax, in the OP. I should look into the documentation to see how they do it. thanks
 
Old 12-10-2014, 11:32 AM   #10
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by Didier Spaier View Post
FWIW; here are the small scripts i use:
Code:
#!/bin/sh
if [ ! "$#" = "2" ]; then
  echo "unpack an initrd in /tmp/initrd-<suffix>
  usage: ./unpack_initrd.sh <path/to/initrd> <suffix>"
  exit
fi
if [ ! $UID -eq 0 ]; then
  gettext "Please execute this script as root."
  echo
  exit
fi  
TMP=/tmp/initrd-$2
if [ -e $TMP ]; then
  echo "$TMP already exists."
  exit
fi
mkdir $TMP
( cd $TMP
  gunzip -cd $1 | \
  cpio -i -d -m -H newc --no-absolute-filenames
) 1>>${TMP}/log.txt 2>>${TMP}/log.txt
Code:
#repack
( cd /root/of/the/unpacked/initrd
  find . -print | cpio -o --owner root:root -H newc | gzip -9 > /path/to/initrd.gz
)
Couldn't you use rsync to just copy over the modified files to the ramdisk archive?
 
Old 12-13-2014, 04:16 PM   #11
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by Didier Spaier View Post
Code:
installpkg --root /tmp/initrd <list of /paths/to/the/packages>
What I would like to do is boot off the Slackware ISO, mount a RAM disk, run the Slackware installer to install to the RAM disk, and then pack the entire RAM disk into an initrd image. How would I do this? thanks
 
Old 12-13-2014, 05:28 PM   #12
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
Quote:
Originally Posted by Geremia View Post
What I would like to do is boot off the Slackware ISO, mount a RAM disk, run the Slackware installer to install to the RAM disk, and then pack the entire RAM disk into an initrd image. How would I do this? thanks
That's what you stated in your first post. But re-reading it I don't understand what you mean by "mount a RAM disk". Could you give an example? I'm puzzled because somehow, once loaded in memory the initrd from the installer (file /syslinux/initrd.gz) is a RAM disk, or I misunderstand what a RAM disk is (which is very possible). Why would you need another one?

Also, out of curiosity: why do you want to do all that?

PS Having seen a similar thread you created, I assume you want to speed up you Slackware. Then you can just do this:
Code:
DIRS=$(ls /) 
mkdir /ram
find $DIRS -print | cpio -o --owner root:root -H newc | gzip -9 > /ram/initrd.gz
Then write for instance a relevant file isolinux.cfg in /ram alongside a kernel then use the mkisofs command to write a bootable iso file with the content of /ram and make it bootable off USB using the isohybrid command.

PS Bear in mind that as soon as you reboot or shutdown all will be lost

Last edited by Didier Spaier; 12-13-2014 at 06:36 PM.
 
Old 12-14-2014, 04:17 PM   #13
Geremia
Member
 
Registered: Apr 2011
Distribution: slackware64-current
Posts: 496

Original Poster
Rep: Reputation: 45
Quote:
Originally Posted by Didier Spaier View Post
That's what you stated in your first post. But re-reading it I don't understand what you mean by "mount a RAM disk". Could you give an example? I'm puzzled because somehow, once loaded in memory the initrd from the installer (file /syslinux/initrd.gz) is a RAM disk, or I misunderstand what a RAM disk is (which is very possible). Why would you need another one?

Also, out of curiosity: why do you want to do all that?
To speed things up
Quote:
Originally Posted by Didier Spaier View Post
PS Having seen a similar thread you created, I assume you want to speed up you Slackware. Then you can just do this:
Code:
DIRS=$(ls /) 
mkdir /ram
find $DIRS -print | cpio -o --owner root:root -H newc | gzip -9 > /ram/initrd.gz
Then write for instance a relevant file isolinux.cfg in /ram alongside a kernel then use the mkisofs command to write a bootable iso file with the content of /ram and make it bootable off USB using the isohybrid command.

PS Bear in mind that as soon as you reboot or shutdown all will be lost
I think you have misunderstood my question. I don't want to store an initrd on a RAM disk. By "mount a RAM disk" I mean use some of my RAM as a filesystem (e.g., as described here, although I don't know how he mounts a RAM disk is the best way in Slackware). I want to copy the contents of the RAM disk (not the initrd image) to my hard disk whenever the machine reboots or shuts down. So, your script above should read something like this:
Code:
DIRS=$(ls /) 
mkdir /ram
find $DIRS -print | cpio -o --owner root:root -H newc | gzip -9 > /mnt/internal_hard_drive/initrd_image

Last edited by Geremia; 12-15-2014 at 12:57 PM.
 
Old 12-14-2014, 04:43 PM   #14
Didier Spaier
LQ Addict
 
Registered: Nov 2008
Location: Paris, France
Distribution: Slint64-15.0
Posts: 11,057

Rep: Reputation: Disabled
OK, then just follow the answers to the post you linked to.

You'll have to find by yourself what are the appropriate places to insert the codes snippets in the Slackware init scripts.

But I strongly advise you against doing that, as if your systems hangs or halt without executing the shutdown script for any reason - and believe me, things like that happen -, all you'll have done in RAM will be lost. The speed gain is not worth the risk, IMO.

But it's your machine, so do what you want
 
Old 12-15-2014, 09:03 AM   #15
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
I have to second what Didier says. The likelihood of you losing something is quite high. Also, the copy process on startup/shutdown would be enormous if you're copying several GBs worth of data from hard drive to the RAM or vice versa. And unless you have a lot of RAM, you could be limiting the available RAM to Slackware, which could seriously hinder your performance.

A better option is probably spending some money on a decent SSD (if you want to go even faster, you could get a second drive and use RAID) and then selectively mounting certain things into RAM, like the /tmp directory, or your firefox profile.

However, I am more than willing to give you the warnings to not shoot yourself in the foot, and then hand you the gun... If you really want to look at doing this, you could probably use the basics of loading the firefox profile into RAM and branch out from there. They cover using rsync to sync things with the hard drive to minimize loss. Hopefully you can pull it off without losing any toes
 
1 members found this post helpful.
  


Reply

Tags
initrd, mkinitrd, ramdisk, slackware, slackware 14.1



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
Anyone know of something like a disk-backed RAM disk? dchicks Linux - Kernel 2 11-04-2009 04:21 PM
Kernel build, install and boot question on ram disk image wdli Programming 58 10-22-2008 11:42 AM
How do I install ram disk on redhat linux RajG Linux - Software 2 11-15-2006 08:54 AM
ram disk quiron Linux From Scratch 3 07-20-2005 02:43 AM
Ram disk consty Red Hat 1 05-11-2005 07:06 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:49 AM.

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