WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Free partition space when running in RAM  (Read 7327 times)

Offline roberts

  • Retired Admins
  • Hero Member
  • *****
  • Posts: 7361
  • Founder Emeritus
Re: Free partition space when running in RAM
« Reply #15 on: June 30, 2009, 10:29:38 AM »
Quoting the guru of initramfs, Rob Landley...
 
- When switching another root device, initrd would pivot_root and then
    umount the ramdisk.  But initramfs is rootfs: you can neither pivot_root
    rootfs, nor unmount it.  Instead delete everything out of rootfs to
    free up the space (find -xdev / -exec rm '{}' ';'), overmount rootfs
    with the new root (cd /newmount; mount --move . /; chroot .), attach
    stdin/stdout/stderr to the new /dev/console, and exec the new init.

    Since this is a remarkably persnickity process (and involves deleting
    commands before you can run them), the klibc package introduced a helper
    program (utils/run_init.c) to do all this for you.  Most other packages
    (such as busybox) have named this command "switch_root".

So I believe most memory should be reclaimed. The "extra" memory required during boot occurs while the copy takes place.

However, your idea is still interesting.
10+ Years Contributing to Linux Open Source Projects.

Offline helander

  • Full Member
  • ***
  • Posts: 183
Re: Free partition space when running in RAM
« Reply #16 on: June 30, 2009, 11:09:38 AM »
Thanks for pointing out the characteristics of switch_root.

Nice that you found my idea interesting :)

Looking at the kernel modules being part of the current rootfs, which ones do you see need to be available before tc-config executes? Which of the rootfs modules could be loaded during the current extension load performed by tc-config? Which modules needs to be loaded after tc-config start but before the current loading of extensions by tc-config?

As an example I guess the network driver modules needs to be loaded prior to starting the network (DHCP etc in tc-config), but maybe it would be possible for this case to reorder the code so that the network is not "started" unitil after tc-config has loaded the extensions?

A nice solution would be if one at the very beginning of tc-config could find out the path to the directory from where either the kernel or tinycore.gz where loaded from (typically both are loaded from the same directory) and from that very same directory load a file that contains the additional modules from today's rootfs. However I am not sure if it is possible to find this out, dou you have a clue? This file could for example be a tar or cpio (possibly gzipped) such that tc-config would load the modules to /lib/modules/...



/Lars

Offline SvOlli

  • Full Member
  • ***
  • Posts: 193
  • Linux Developer
Re: Free partition space when running in RAM
« Reply #17 on: July 01, 2009, 04:05:18 PM »
With this solution, I guess the memory used for the initramfs is not reclaimed (guess based on no explicit unmount in the init script and that mount command shows a rootfs mounted at /)?

That's not true. Run switch_root without any arguments to get the help message:
Code: [Select]
Usage: switch_root [-c /dev/console] NEW_ROOT NEW_INIT [ARGUMENTS_TO_INIT]

Use from PID 1 under initramfs to free initramfs, chroot to NEW_ROOT, and exec NEW_INIT
There's stated that initramfs will be freed.