Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Prune Gentoo to 192MB and run in RAM?
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Installing Gentoo
View previous topic :: View next topic  
Author Message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Fri Oct 12, 2012 11:44 am    Post subject: Prune Gentoo to 192MB and run in RAM? Reply with quote

I've installed Gentoo on the (256MB) Beaglebone and it's about 4GB and uses 35MB RAM or 53MB with buffers/cache. I'd like to try running entirely out of RAM by loading files or an image from the SD card to RAM at boot and then removing the SD card.

How can I prune the Gentoo install down to about 192MB? Can this be done with emerge -C or do I need to rm -rf? From a high-level perspective, the only stuff I need working is ALSA and jack.

How can I load the SD card to RAM at boot and run that way?
Back to top
View user's profile Send private message
Ant P.
Watchman
Watchman


Joined: 18 Apr 2009
Posts: 6920

PostPosted: Fri Oct 12, 2012 1:06 pm    Post subject: Reply with quote

You can put /usr/ in a squashfs and move portage to NFS. That should get it down to below 300MB or so, depending on how much stuff's installed.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Fri Oct 12, 2012 1:26 pm    Post subject: Reply with quote

Unfortunately NFS isn't an option as I need everything to run from RAM on the device, but I'm OK with deleting /usr/portage. I'm hoping to make everything run as quickly as possible. Will squashfs slow things down on a device with a 700Mhz CPU?
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Fri Oct 12, 2012 9:01 pm    Post subject: Reply with quote

I wonder why. Do you need the card slot for something else?
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Sat Oct 13, 2012 1:12 am    Post subject: Reply with quote

So you want everything, including the filesystem to fit into 256 Meg of RAM?

This is very difficult. The antiX-core system (no X) squeezes a 400 Meg file system down to a 127 Meg squashfs file. You could put this on an sdcard and use the "toram" option that will copy the squashfs file to tmpfs (RAM). It will also run AUFS to let you make modification to the filesystem. Since it is all in RAM there is no way to save changes but if you wanted to, changes could be saved to the sdcard if you re-insert it.

The antiX-core system uses very little RAM OOTB. This is one of the smallest Linux distros around. It's Debian based, not Gentoo based but I think it will just fit your needs OOTB without any extra work on your part. One of its strong points is it is extremely easy to remaster so you could run it Live on a larger system and tweak what packages you want included (or removed) then run remaster-me to make a new LiveUSB/CD master which you could then put on your sdcard.
Back to top
View user's profile Send private message
M
Guru
Guru


Joined: 12 Dec 2006
Posts: 432

PostPosted: Sat Oct 13, 2012 10:14 am    Post subject: Reply with quote

Take a look at tiny gentoo http://en.gentoo-wiki.com/wiki/Tiny_Gentoo , and look at ROOT=, you can target some other root and install packages without gcc, build tools etc.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sat Oct 13, 2012 2:45 pm    Post subject: Reply with quote

Quote:
I wonder why. Do you need the card slot for something else?

I want everything to run as fast as possible. I don't need the SD card slot for anything else, I only mentioned removing the card to stress that I didn't want it to be accessed during normal operation of the OS.

Quote:
Take a look at tiny gentoo http://en.gentoo-wiki.com/wiki/Tiny_Gentoo , and look at ROOT=, you can target some other root and install packages without gcc, build tools etc.

They have it down to 5MB??? I will definitely look into that.

What I'd ideally like to have is one SD card for development which boots conventionally and on which I make changes, updates, etc. Then a script which copies a pruned and slightly reconfigured version of that OS onto another SD card which I use for production. The production version would copy to RAM and run read-only.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sun Oct 14, 2012 8:22 pm    Post subject: Reply with quote

Everything runs from RAM anyway, that's how computers work, that's what RAM is for. There should be no SD card access after OS and application(s) are loaded.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Sun Oct 14, 2012 10:13 pm    Post subject: Reply with quote

Jaglover wrote:
Everything runs from RAM anyway, that's how computers work, that's what RAM is for. There should be no SD card access after OS and application(s) are loaded.

I wish it were so easy. Generally this is not the case. Generally there are a lot of reads and writes to the file system even after the OS and applications are loaded. Sure, you can minimize these by turning off logging and mounting /var and /tmp on tmpfs but zero hard disk access is certainly not normal.

The solution I suggested, which is what most LiveCD/USBs do nowadays, uses a squashfs file to hold the initial file system and then uses aufs to join that together with a tmpfs so the tmpfs can track the fs changes since squashfs is read-only.

For a system that is to reside entirely in RAM after boot, there is a range of choices:
  1. Minimal system based on BusyBox. This can reside entirely in initramfs. It can boot in less than a second and can take less than 10 MiB of RAM. This is CLI only, no X.

  2. The next step up is the BusyBox system plus a read-only squashfs file system that resides in RAM. The benefit of squashfs is that it usually compresses by better than a factor of 2:1. The downside is that it is read-only. Boot time is increased by the amount of time it takes to copy the squashfs file into RAM. The amount of extra RAM (and boot time) depends entirely on the size of the squashfs filesystem.

  3. The next step is to add an aufs file system and a tmpfs to the squashfs that magically makes the entire filesystem read-write. All changes are stored uncompressed. You need additional RAM to store the changes. The overhead compared to (2) is small as long as you don't make a lot of changes to the filesystem. This is the set up most LiveCD/USBs use although copying the squashfs to RAM is usually only available as an option if it is available at all. You can run a full-fledged Linux system this way.

Of course, these are not the only options but I think they outline the spectrum that is available.

You also have choices of how full-fledged or stripped down you want your system to be. As I said before, you can probably get a full-fledged Debian based distro to work entirely out of about 256 MiB RAM but it is going to be hard to get much smaller and keep it full-fledged.

I agree that for a dedicated stripped-down system, it would be possible to run without a filesystem. Just mount an SD based file system long enough to load the apps and then unmount it. I would consider this a variant of (1) above. It all depends in exactly what you want the system to be able to do.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 8291
Location: Saint Amant, Acadiana

PostPosted: Sun Oct 14, 2012 10:46 pm    Post subject: Reply with quote

Alright I simplified it a bit, but cached writes will not slow down your box. Certainly not worth occupying already limited RAM with static content which gets copied anyway.
_________________
My Gentoo installation notes.
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
cwr
Veteran
Veteran


Joined: 17 Dec 2005
Posts: 1969

PostPosted: Mon Oct 15, 2012 8:44 am    Post subject: Reply with quote

What about a different distribution, such as DSL, Puppy, or Tiny Core?
If you know exactly which apps you need from the start, they seem
quite a good choice.

Will
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sat Oct 20, 2012 2:37 pm    Post subject: Reply with quote

Quote:
Minimal system based on BusyBox. This can reside entirely in initramfs. It can boot in less than a second and can take less than 10 MiB of RAM. This is CLI only, no X.

This is really interesting. So I would basically build a GNU/Linux system from scratch by extracting busybox and compiling a kernel? All I really need is for ALSA and jackd to work.

EDIT: I'm looking at what it takes to put together a busybox system and I think it might be overkill for this. Do you think I could prune Gentoo to the point where it runs ALSA and jackd in 256MB RAM with no squashfs? I'm OK with no portage, no compiler, etc. I could run a full Gentoo install from one SD card and run a pruned copy of that system from another SD card which loads everything to RAM.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Sat Oct 20, 2012 5:31 pm    Post subject: Reply with quote

grant123 wrote:
This is really interesting. So I would basically build a GNU/Linux system from scratch by extracting busybox and compiling a kernel? All I really need is for ALSA and jackd to work.

EDIT: I'm looking at what it takes to put together a busybox system and I think it might be overkill for this. Do you think I could prune Gentoo to the point where it runs ALSA and jackd in 256MB RAM with no squashfs? I'm OK with no portage, no compiler, etc. I could run a full Gentoo install from one SD card and run a pruned copy of that system from another SD card which loads everything to RAM.

IMO, if this is the direction you want to go in then you should start with something like Tiny Core (as cwr already suggested) and then add whatever else you need. It is usually easier to add things to a system than to strip one down.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sat Oct 20, 2012 11:00 pm    Post subject: Reply with quote

I'd like to stick with Gentoo if at all possible. I'm still holding on to the 1-distro dream.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Sun Oct 21, 2012 1:10 am    Post subject: Reply with quote

This raises the question "what is a distro?". IMO a distro like Gentoo is characterized by its install system, its init system, and its package management system. For this small project of yours you don't need any of these so the idea of using one distro versus another distro is a bit meaningless.

Since you seem intent on rolling your own, I suggest you take a look at how to make a (Gentoo) initramfs. You will almost certainly need one of these. It is a compressed CPIO filesystem that gets loaded directly by the boot loader. Legacy Grub uses a line like:
Code:
initrd /initramfs.gz

Inside the CPIO filesystem there is usually a script at /init. This script is automatically run by the boot loader. In order to be able to run the script, you need a shell program. This is normally the Ash shell provided by busybox so you will have a /bin directory that contains the busybox program and a bunch of symlinks to the busybox program. For example /bin/sh is a symlink to /bin/busybox. The /init script should start out with something like:
Code:
#!/bin/sh

PATH=/bin; export PATH

mkdir -p /proc /sys /dev/pts

mount -t proc   proc   /proc
mount -t sysfs  sys    /sys
mount -t devpts devpts /dev/pts

echo > /dev/mdev.seq
echo /bin/mdev /proc/sys/kernel/hotplug
mdev -s

This gives you a very minimal system. If you want to continue to boot like normal then you would mount the root filesystem and do something like:
Code:
exec switch_root /mnt/root /sbin/init
Alternatively you could just drop into a shell with something like:
Code:
exec /bin/sh

The question is: what more do you need that is not already available in the simple initramfs system? ALSA can be built into the kernel. ISTM all that is left is possibly a network connection and jackd. You can use busybox to establish the network connection so all that is really left is running jackd.

I don't know if jackd needs other programs available but if not then all you need do is copy jackd and the libraries it depends on into CPIO filesystem. You can find the libraries with:
Code:
$ ldd `which jackd`
I think busybox lets you just dump all the libraries into /lib. You would then just add a few more lines to your /init script to bring up the network connection and start jackd in the background.

I would suggest making a bootable ISO file with the genisoimage program from app-cdr/cdrkit and then debug in VirtualBox. The ISO filesystem only needs the kernel, the initramfs file and the bootloader files. Once that works, copy the ISO filesystem to your install media and make it bootable.

You might save yourself some work and some grief if you started off with a working initramfs but maybe that would feel like cheating.
Back to top
View user's profile Send private message
grant123
Veteran
Veteran


Joined: 23 Mar 2005
Posts: 1080

PostPosted: Sun Oct 21, 2012 4:54 pm    Post subject: Reply with quote

BitJam, this is great stuff. You're really focusing my thinking. As I learn more about this I can see that Tiny Core would make a great choice as you said before. I think I would use MicroCore in Copy Mode with an application extension for jackd. Should that work well?

EDIT: I just noticed that the Gentoo ARM stage3 extracts to 534M. If I can prune that just a bit and squashfs will do 2:1, I will be under 256M. Should that work too?

EDIT AGAIN: I realize now that I can't fill up all memory with the squashfs image so it's going to be Tiny Core.
Back to top
View user's profile Send private message
BitJam
Advocate
Advocate


Joined: 12 Aug 2003
Posts: 2508
Location: Silver City, NM

PostPosted: Thu Nov 01, 2012 10:40 am    Post subject: Reply with quote

You might also be interested in TinyGentoo.
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Installing Gentoo 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