LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Blogs > IsaacKuo
User Name
Password

Notices


Rate this Entry

tmpfs NFSroot - use one computer's RAM as an SSD for another computer

Posted 09-22-2016 at 04:48 PM by IsaacKuo
Updated 09-23-2016 at 08:44 PM by IsaacKuo

In a previous blog post, I described how to share one computer's SSD to host another computer's OS. With a gigabit ethernet connection, the result is almost as good as a local SSD in real life desktop performance.

But what if you don't have any SSD? You can still do it, if one of your computers has at least 2GB of RAM! The nfs server in this case creates a tmpfs ramdisk and copies the OS from a hard drive copy to the ramdisk. We then use rsync when we want to sync back changes to the hard drive. The client sees this nfs share just like any other.

This concept is a spiritual hybrid of my RAMBOOT how-to and my NFSROOT how-to, even if it doesn't really share much in common with RAMBOOT. The RAMBOOT concept only uses one computer, and it copies the entire OS partition into ram from a compressed image file. That's great if you've got one computer that's loaded up with plenty of RAM. But this how-to is better if you've got two computers with maxed out RAM (or even different RAM types).

For example, let's say you have a desktop computer maxed out at 4GB of RAM and a laptop maxed out at 3GB of RAM. Neither of them is a good candidate for RAMBOOT, and you just can't physically move some RAM sticks from the desktop into the laptop. But you can use the desktop as an "external SSD" for the laptop, or vice versa. And don't worry too much if the OS doesn't quite fit in the ram of the server. The tmpfs file system will automatically start using swap if necessary to offload less used files. In that sense, the nfs server kind of acts like one of those fancy "hybrid" drives.

STEP 1) CREATE NORMAL NFSROOT

First step is to set up NFSroot with a normal hard drive root directory. Follow the steps in my previous blog post:

http://www.linuxquestions.org/questi...-jessie-37127/

After confirming it works, shut down the client computer.

STEP 2) CONVERT /netroot TO TMPFS

Use the following code to stop the nfs server and move /netroot to /netSRC.
Code:
systemctl stop nfs-kernel-server
mv -vi /netroot /netSRC
mkdir /netroot
Now, create an /etc/fstab entry, so it looks like this:
Code:
none /netroot tmpfs size=125% 0 0
Note that the size can be bigger than 100%. Basically, set this smaller than 100% if you don't have swap. But if you do have swap, you probably want to set this limit bigger than 100%.

Now, edit /etc/exports so it looks something like this:
Code:
/netroot 10.42.0.0/24(rw,fsid=1,sync,no_root_squash)
no_root_squash is a requirement for any sort of nfs root share, and I determined the use of "fsid=1" by trial and error with stuff I found on the internet.

Now mount /netroot, share it, and copy over the contents of /netSRC:
Code:
mount /netroot
systemctl start nfs-kernel-server
cp -vax /netSRC/* /netroot/
Congrats! It's ready to test! No changes on the client side are needed. Simply power up the client and see if it works!

STEP 3) MODIFY /etc/rc.local BOOT SCRIPT

You'll want to copy over the contents of /netSRC to /netroot when you boot the server. Do this by editing /etc/rc.local so it looks something like this:

Code:
cp -vax /netSRC/* /netroot/

exit 0
Additionally, you'll want to sometimes rsync the contents of /netroot back to /netSRC with the following command:

Code:
rsync -vaxAX /netroot/* /netSRC/
Note that you can also rsync in the other direction if you want to revert. For example, you might want to use apt-get to try out some software for a bit. And if you decide to revert, you can just shut down the client and then use "rsync -vaxAX /netSRC/* /netroot" to revert back to the previously saved state.

The same basic maintenance notes from my previous blog entry still apply. If there's a kernel update, you'll still have to manually copy over the new initrd.img and vmlinuz files to /mnt/sda1/boot (on the client). Just remember to rsync netroot to netSRC first, so the updates are in line with each other. (It's okay to accidentally boot up with an older kernel, but it might not always be okay to boot up with a kernel newer than the rest of the OS.)
Posted in Uncategorized
Views 1449 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



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

Main Menu
Advertisement
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