LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions
User Name
Password
Linux - Distributions This forum is for Distribution specific questions.
Red Hat, Slackware, Debian, Novell, LFS, Mandriva, Ubuntu, Fedora - the list goes on and on... Note: An (*) indicates there is no official participation from that distribution here at LQ.

Notices


Reply
  Search this Thread
Old 12-23-2011, 06:03 PM   #16
romagnolo
Member
 
Registered: Jul 2009
Location: Montaletto
Distribution: Debian GNU/Linux
Posts: 107

Rep: Reputation: 5

Quote:
Originally Posted by alaios View Post
Dear all,
I am looking for a small distro that can do the following
...
You are really bringing me to light. I have accomplished this by personally modifying debian.

I'm currently running full in RAM with harddisk turned off in a whole graphic environment, with 0 noise, high speed and longer battery life (about 80 minutes against 50); this with only 2 giga.

For you and anyone interested my system works this way:

1) boot a monolithic linux which holds the I/O disk drivers in built-in, to save the need to load them from the initrd

2) boot a custom initrd which really does the job: it loads a filesystem image of 1.2 GB from disk and clones it to a /dev/ram0 block device. Then boots from this ram device containing the loaded filesystem.
The filesystem is a compressed reiser4 which currently can hold my 4GB of desktop system into just 800 MB of ram. This leaves me with other 800 MB as regular paging RAM, which proved to be much enough.
Compressed reiser4 is know to hold 3 to 5 times the volume occupied.

3) the system then runs smoothly and does an automated shut down of harddisk after 2 minutes if not mounted.

4) at the end of runlevels 0 and 6 (shutdown and reboot) it performs a "synchronization": unmounts root then copies the /dev/ram0 block device in its new state to hard disk, making backups.

This way at each boot the filesystem image in its latest state is loaded, so acts transparently as a regular harddisk.

It requires no maintenance and no special modification to adapt to an other system. You have to customize the kernel to your machine and probably increase the disk image size, as I describe below.
Linux is limited to 2.6.38 because of reiser4 shortage for newer versions.

Also worth to mention, this is a regular debian in every detail, with APT and no special concerns with drivers, daemons, packages or other things.

I think this is the right place to publish my system scripts finally, or I feel I'll never do (these scripts are packaged at bottom):

------------------ /init in init ramdisk --------------------
Code:
#!/bin/sh

echo "Loading initrd..."

runsh_c=0
runsh() {
    runsh_c=$((runsh_c + 1))
    echo "run sh --${runsh_c}--..."
    sh
}

[ -d /dev ] || mkdir -m 0755 /dev
[ -d /root ] || mkdir -m 0700 /root
[ -d /sys ] || mkdir /sys
[ -d /proc ] || mkdir /proc
[ -d /tmp ] || mkdir /tmp
mkdir -p /var/lock
mount -t sysfs -o nodev,noexec,nosuid none /sys
mount -t proc -o nodev,noexec,nosuid none /proc

# Note that this only becomes /dev on the real filesystem if udev's scripts
# are used; which they will be, but it's worth pointing out
tmpfs_size="10M"
if [ -e /etc/udev/udev.conf ]; then
        . /etc/udev/udev.conf
fi
if ! mount -t devtmpfs -o mode=0755 none /dev; then
        echo "W: devtmpfs not available, falling back to tmpfs for /dev"
        mount -t tmpfs -o size=$tmpfs_size,mode=0755 udev /dev
        [ -e /dev/console ] || mknod -m 0600 /dev/console c 5 1
        [ -e /dev/null ] || mknod /dev/null c 1 3
fi
mkdir /dev/pts
mount -t devpts -o noexec,nosuid,gid=5,mode=0620 none /dev/pts || true
> /dev/.initramfs-tools
mkdir /dev/.initramfs

# Export the dpkg architecture
export DPKG_ARCH=
. /conf/arch.conf

# Set modprobe env
export MODPROBE_OPTIONS="-qb"

export ROOTRD=/dev/sda1
export FINALRD=/boot/RAMdebian.reiser4
export ROOT=
export ROOTDELAY=
export ROOTFLAGS=
export ROOTFSTYPE=
export IP=
export BOOT=
export BOOTIF=
export UBIMTD=
export break=
export init=/sbin/init
export quiet=n
export readonly=y
export rootmnt=/root
export debug=
export panic=
export blacklist=
export resume=
export resume_offset=

# Bring in the main config
. /conf/initramfs.conf
for conf in conf/conf.d/*; do
        [ -f ${conf} ] && . ${conf}
done
. /scripts/functions

# Parse command line options
for x in $(cat /proc/cmdline); do
        case $x in
        rootrd=*)
                ROOTRD=${x#rootrd=}
                ;;
        finalrd=*)
                FINALRD=${x#finalrd=}
                ;;
        init=*)
                init=${x#init=}
                ;;
        rootflags=*)
                ROOTFLAGS="-o ${x#rootflags=}"
                ;;
        rootfstype=*)
                ROOTFSTYPE="${x#rootfstype=}"
                ;;
        rootdelay=*)
                ROOTDELAY="${x#rootdelay=}"
                case ${ROOTDELAY} in
                *[![:digit:].]*)
                        ROOTDELAY=
                        ;;
                esac
                ;;
        nfsroot=*)
                NFSROOT="${x#nfsroot=}"
                ;;
        ip=*)
                IP="${x#ip=}"
                ;;
        boot=*)
                BOOT=${x#boot=}
                ;;
        ubi.mtd=*)
                UBIMTD=${x#ubi.mtd=}
                ;;
        resume=*)
                RESUME="${x#resume=}"
                ;;
        resume_offset=*)
                resume_offset="${x#resume_offset=}"
                ;;
        noresume)
                noresume=y
                ;;
        panic=*)
                panic="${x#panic=}"
                case ${panic} in
                *[![:digit:].]*)
                        panic=
                        ;;
                esac
                ;;
        quiet)
                quiet=y
                ;;
        ro)
                readonly=y
                ;;
        rw)
                readonly=n
                ;;
        debug)
                debug=y
                quiet=n
                exec >/dev/.initramfs/initramfs.debug 2>&1
                set -x
                ;;
        debug=*)
                debug=y
                quiet=n
                set -x
                ;;
        break=*)
                break=${x#break=}
                ;;
        break)
                break=premount
                ;;
        blacklist=*)
                blacklist=${x#blacklist=}
                ;;
        netconsole=*)
                netconsole=${x#netconsole=}
                ;;
        BOOTIF=*)
                BOOTIF=${x#BOOTIF=}
                ;;
        esac
done

if [ -n "${noresume}" ]; then
        export noresume
        unset resume
else
        resume=${RESUME:-}
fi

[ -n "${netconsole}" ] && modprobe netconsole netconsole="${netconsole}"

maybe_break top

# Don't do log messages here to avoid confusing usplash
run_scripts /scripts/init-top

maybe_break premount
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-premount"
run_scripts /scripts/init-premount
[ "$quiet" != "y" ] && log_end_msg

wait_for_udev 10 # can be executed only after /script/init-premount/udev
[ -d /mnt/ROOTRD ] || mkdir -p /mnt/ROOTRD
mount $ROOTRD /mnt/ROOTRD
dd if="/mnt/ROOTRD/${FINALRD}" of=/dev/ram0
#bzip2 -cd /mnt/ROOTRD/${FINALRD} > /dev/ram0
umount $ROOTRD

maybe_break mount
log_begin_msg "Mounting root file system"
. /scripts/${BOOT}
parse_numeric ${ROOT}
maybe_break mountroot
mountroot
log_end_msg

maybe_break bottom
[ "$quiet" != "y" ] && log_begin_msg "Running /scripts/init-bottom"
run_scripts /scripts/init-bottom
[ "$quiet" != "y" ] && log_end_msg

# Move virtual filesystems over to the real filesystem
mount -n -o move /sys ${rootmnt}/sys
mount -n -o move /proc ${rootmnt}/proc

if [ ! -x "${rootmnt}${init}" ]; then
    panic "No init found. Try passing init= bootarg."
fi

maybe_break init

# don't leak too much of env - some init(8) don't clear it
# (keep init, rootmnt)
unset debug
unset MODPROBE_OPTIONS
unset DPKG_ARCH
unset ROOTFLAGS
unset ROOTFSTYPE
unset ROOTDELAY
unset ROOT
unset IP
unset BOOT
unset BOOTIF
unset UBIMTD
unset blacklist
unset break
unset noresume
unset panic
unset quiet
unset readonly
unset resume
unset resume_offset

# Chain to real filesystem
exec run-init ${rootmnt} ${init} "$@" <${rootmnt}/dev/console >${rootmnt}/dev/console
panic "Could not execute run-init."


------------------ /scripts/local in init ramdisk --------------------
Code:
# Local filesystem mounting                     -*- shell-script -*-

pre_mountroot()
{
        [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-top"
        run_scripts /scripts/local-top
        [ "$quiet" != "y" ] && log_end_msg

        wait_for_udev 10

        # Load ubi with the correct MTD partition and return since fstype
        # doesn't work with a char device like ubi.
        if [ -n "$UBIMTD" ]; then
                modprobe ubi mtd=$UBIMTD
                return
        fi

        # Don't wait for a root device that doesn't have a corresponding
        # device in /dev (ie, mtd0)
        if [ "${ROOT#/dev}" = "${ROOT}" ]; then
                return
        fi

        # If the root device hasn't shown up yet, give it a little while
        # to deal with removable devices
        if [ ! -e "${ROOT}" ] || ! $(get_fstype "${ROOT}" >/dev/null); then
                log_begin_msg "Waiting for root file system"

                # Default delay is 30s
                slumber=${ROOTDELAY:-30}

                if [ -x /sbin/usplash_write ]; then
                        /sbin/usplash_write "TIMEOUT ${slumber}" || true
                fi

                slumber=$(( ${slumber} * 10 ))
                while [ ! -e "${ROOT}" ] \
                || ! $(get_fstype "${ROOT}" >/dev/null); do
                        /bin/sleep 0.1
                        slumber=$(( ${slumber} - 1 ))
                        [ ${slumber} -gt 0 ] || break
                done

                if [ ${slumber} -gt 0 ]; then
                        log_end_msg 0
                else
                        log_end_msg 1 || true
                fi
                if [ -x /sbin/usplash_write ]; then
                        /sbin/usplash_write "TIMEOUT 15" || true
                fi
        fi

        # We've given up, but we'll let the user fix matters if they can
        while [ ! -e "${ROOT}" ]; do
                # give hint about renamed root
                case "${ROOT}" in
                /dev/hd*)
                        suffix="${ROOT#/dev/hd}"
                        major="${suffix%[[:digit:]]}"
                        major="${major%[[:digit:]]}"
                        if [ -d "/sys/block/sd${major}" ]; then
                                echo "WARNING bootdevice may be renamed. Try root=/dev/sd${suffix}"
                        fi
                        ;;
                /dev/sd*)
                        suffix="${ROOT#/dev/sd}"
                        major="${suffix%[[:digit:]]}"
                        major="${major%[[:digit:]]}"
                        if [ -d "/sys/block/hd${major}" ]; then
                                echo "WARNING bootdevice may be renamed. Try root=/dev/hd${suffix}"
                        fi
                        ;;
                esac
                echo "Gave up waiting for root device.  Common problems:"
                echo " - Boot args (cat /proc/cmdline)"
                echo "   - Check rootdelay= (did the system wait long enough?)"
                echo "   - Check root= (did the system wait for the right device?)"
                echo " - Missing modules (cat /proc/modules; ls /dev)"
                panic "ALERT!  ${ROOT} does not exist.  Dropping to a shell!"
        done
}

mountroot()
{
        pre_mountroot

        # Get the root filesystem type if not set
        if [ -z "${ROOTFSTYPE}" ]; then
                FSTYPE=$(get_fstype "${ROOT}")
        else
                FSTYPE=${ROOTFSTYPE}
        fi

        [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-premount"
        run_scripts /scripts/local-premount
        [ "$quiet" != "y" ] && log_end_msg

        if [ "${readonly}" = "y" ]; then
                roflag=-r
        else
                roflag=-w
        fi

        # FIXME This has no error checking
        modprobe ${FSTYPE}

        mount -t reiser4 /dev/ram0 ${ROOTFLAGS} ${rootmnt}

        [ "$quiet" != "y" ] && log_begin_msg "Running /scripts/local-bottom"
        run_scripts /scripts/local-bottom
        [ "$quiet" != "y" ] && log_end_msg
}

--------- /etc/init.d/synchronize.sh in reiser4 session disk ----------
Code:
#!/bin/sh
echo -n "Synchronyzing..."

img="/media/sda1/boot/RAMdebian.reiser4"

[ -d /media/sda1 ] || mkdir -p /media/sda1
mount -n /dev/sda1 /media/sda1

apt-get clean
rm -fr /tmp/*

[ -f "${img}.bk1" ] && { echo -n " bk2"; mv "${img}.bk1" "${img}.bk2"; }
[ -f "${img}" ]     && { echo -n " bk1"; mv "${img}" "${img}.bk1"; }
echo -n " img";
mount -n -o remount,ro /
dd if=/dev/ram0 of="${img}" bs=$((2**20)) count=1200 > /dev/null
#bzip2 -cz /dev/ram0 > /media/sda1/boot/RAMdebian.reiser4.bz2

umount /media/sda1
echo " done"


---------- /etc/init.d/lownoise.sh in reiser4 session disk -----------
Code:
#!/bin/sh


function do_start() {
    echo -n "Lowering CPU freq to 800 MHz..."
    fail=0
    for i in 0 1; do
        cpufreq-set -c $i -f 800000 || fail=1
    done
    [ $fail = 0 ] && echo "Done"

    echo "Shutting down HD if not mounted in 2 minutes."
    { mount=0
        for s in {1..120}; do
            sleep 1
            egrep -q '/dev/sda' /proc/mounts && mount=1
        done

        [ $mount = 0 ] && hdparm -Y /dev/sda > /dev/null
    } &
}

function do_stop() {
    # quietly activate drive for synchronyze on shutdown
    hdparm -C /dev/sda 2>&1 > /dev/null
}

case "$1" in
    start|restart|force-reload)
        do_start
        ;;
    stop)
        do_stop
        ;;
    *)
        echo "Usage: start|restart|force-reload|stop"
        ;;
esac


---------- utility script to decompress and open the initrd -----------
#!/bin/bash
mkdir -p /media/ram1
mount -t ramfs none /media/ram1
cd /media/ram1
gunzip -c /boot/ramdiskOK1.img.gz | cpio -id
exit 0

---------- utility script to compress and close the initrd -----------
#!/bin/bash
mkdir -p /media/ram2
cd /media/ram1

#mount -t ramfs none /media/ram2
find . | cpio -H newc -o > /boot/ramdiskOK1.img

cd /boot
gzip -c -6 ramdiskOK1.img > ramdiskOK1.img.gz
rm ramdiskOK1.img
umount /media/ram1
#umount ram2
exit 0


------ special content of /etc/rc0.d in reiser4 session disk ---------
lrwxrwxrwx 1 root root 22 Sep 3 17:27 K10low_noise -> ../init.d/low_noise.sh
lrwxrwxrwx 1 root root 24 Sep 3 09:46 S60synchronyze -> ../init.d/synchronyze.sh
lrwxrwxrwx 1 root root 20 Sep 7 00:02 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root 14 Sep 3 09:45 S90halt -> ../init.d/halt

----- special content of /etc/rc2.d (session rl) in reiser4 session disk -------
lrwxrwxrwx 1 root root 22 Sep 3 17:27 S10low_noise -> ../init.d/low_noise.sh

------ special content of /etc/rc6.d in reiser4 session disk ---------
lrwxrwxrwx 1 root root 22 Sep 3 17:27 K10low_noise -> ../init.d/low_noise.sh
lrwxrwxrwx 1 root root 24 Sep 3 09:46 S60synchronyze -> ../init.d/synchronyze.sh
lrwxrwxrwx 1 root root 20 Sep 7 00:02 S60umountroot -> ../init.d/umountroot
lrwxrwxrwx 1 root root 16 Sep 3 09:44 S90reboot -> ../init.d/reboot


Probable modifications you're gonna need:

1) kernel customization: Kernel must me customized upon a 2.6.38 base version patched with reiser4 with boot drivers built-in. I provide linux sources and it's configuration in attachment.

2) filesystem size increase: change virtual disk size is a preliminary one-time operation. You can manage to change it later, though.
It must be changed for the ramdisk /dev/ram0 to fit the image during boot, and for the synchronization scripts during reboot/shutdown.

The size to consider now is the physical volume seized in RAM by reiser4 image and each its backup on disk. Available size for OS will be about 3 to 5 times larger due to compression.
Chose the X size in MB; in kernel configuration menu device drivers -> block devices -> default ramdisk size (kbytes) put the exact number X*2^10. My case is 1200 MB so ramdisk size = 1228800. Also you should set to 1 the "default number of ram disks" to avoid ram leak.
For the synchronization script, open /etc/init.d/synchronize.sh and in the line
Code:
dd if=/dev/ram0 of="${img}" bs=$((2**20)) count=1200 > /dev/null
change count=1200 to count=X.
Consider that linux uses a big chunk of ram only for caching.

3) harddisk device change: if your support harddisk isn't /dev/sda1, you have to change initrd and synchronize script as follows:
open /init file inside initrd (first script posted). You can use the support script above.
In the file you'll find a list of variable configured with default parameters; change the line
Code:
export ROOTRD=/dev/sda1
with the device you'll use.
In the synchronize script /etc/init.d/synchronize.sh adjust
Code:
img="/media/sda1/boot/RAMdebian.reiser4"
and
Code:
mount -n /dev/sda1 /media/sda1
to your device. Don't modify the image name (/boot/RAMdebian.reiser4) unless you use the new name in all the system scripts.

Notes:
1) Reiser4 is accused to be unreliable. This is true as long as you crash the system or reboot while filesystem is working on a real time OS/disk device; that way the filesystem will be unusable the next boot.
In a RAM system, instead, the filesystem is saved to disk only when all the I/O operations are concluded and fs is unmounted. This way no corruption is possible and, more, the synchronize script saves the 3 most recent ramdisk statuses so that you can restore the system if you install something bad or delete a file, but no, no data corruption is possible this way.

2) The default name of booting image must be /boot/RAMdebian.reiser4 on the harddisk. Pay attention if you want to change this name (at least you will need to look at /init in initrd and synchronize.sh in ramdisk)

Attachments
I provide these files thru my current ftp server. I don't think it will be available in long future with same domain/paths, so if someone is interested, please be a mirror!

full directory is ftp://freeciv-debian.ns0.it/RAMdebian/
linux patched with reiser4 (includes my current .config to ease up things)
linux as above, compiled
modified initrd to boot kernel with, thru boot loader
my current full-system reiser4 image of 1200 MB with kde, kdm, iceweasel, basic stuff and freeciv! root password is abc. you can replace this with any reiser4 image of size X (see above) with a base system within it. see man page for debootstrap debian's tool.

decompress all the .bz2 files, not the ramdisk*.gz (as it's never done).

Put all the files in /boot/ of harddisk, update your GRUB, and it will just work as is if you have one sata HD (root in sda1), intel chipset with integrated video and audio, broadcom bcm4312 wireless, and if 1200 MB is ok.
But likely you'll need a kernel check.

Last edited by romagnolo; 12-26-2011 at 04:53 PM.
 
Old 12-24-2011, 12:43 AM   #17
Ahau
Member
 
Registered: Jun 2011
Location: USA
Distribution: Porteus, Slackware
Posts: 58

Rep: Reputation: 19
Hi alaios -- sorry, one more thing you'll have to do to get skype up and running on 32-bit porteus with the modules I posted a link to...your system won't see the qt libs right away once you add the module. So, after you download and activate both modules, do this:

echo "/usr/lib/qt4" >> /etc/ld.so.conf
ldconfig

typically that would be addressed before a module is added to our official repo (this one is coming from the fidoslax repo, so you've got the one extra step). I've tested it now and have skype up and running. Happy skyping!
 
  


Reply



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
Newbie Distro Question 1: Reasons for inter-distro pkg incompatibility. Wombat Pete Linux - Distributions 20 04-05-2010 01:59 PM
[rant] DIstro frustration and alienation/suggestions for stable distro Draciron Linux - Distributions 3 10-16-2009 10:27 AM
math distro....? music distro...? small distro....? jasonparent Linux - Newbie 11 02-11-2008 09:57 AM
LXer: DistroWatch Weekly: Distro hopping, Linux Format's distro mega-test LXer Syndicated Linux News 0 06-11-2007 04:47 AM

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

All times are GMT -5. The time now is 12:01 PM.

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