#!/bin/bash
#
# Create Working Area in ramdisk or use NFS mounts from other servers
# ------------------------------
#	/dev/ram0 was initrd.gz
#	/dev/ram1 is swap
#	/dev/ram2 is /var
#	/dev/ram3 is /usr/local
#	/dev/ram4 is /opt/home ( /home )
#
#
# 06-Nov-04 amo Date-of-Birth
# 26-Mar-05 amo Separate swap into ramdisks.swap.sh
# 26-Aug-05 amo Clean up ramdisk.sh file
# 01-Sep-05 amo Copy /root /home /var /tmp to the rw RamDisks 
# 02-Sep-05 amo Added 2> /dev/null for dd
# 03-Sep-05 amo Use BootMsg and bash.common.sh
# 05-Sep-05 amo Move link from /usr.local/tmp to /var/tmp, and make usr.local == /mnt/loop?/usr
# 30-Sep-05 amo Added .fvwm2rc-2.4.19
#
#
# --------------------------------------------------------------------
# Remember that /root /tmp /var is required BEFORE the system can boot
# --------------------------------------------------------------------
#	-
#	- use this script ramdisks.sh to "mv /var /ramdisk/var"
#	- and to restore the original /dev/loop0 version BEFORE
#	- we modified it in the previous system boot
#	-
# --------------------------------------------------------------------
#
#
# export PATH="/sbin:/bin:/usr/sbin:/usr/bin"
#
# Define docmd() BootMsg()
source /etc/bash.common.sh
#
DebugMsg="anything"
#
#
# Create /dev/ram1 for swap space
# -------------------------------
# sh ramdisks.swap.sh
#
#
BootMsg "#"
BootMsg "# ramdisks.sh: create some RW system area: /root /tmp /var "
BootMsg "#"
#
#
RD_WR="/RD_WR"
#
VAR=$RD_WR/var
#
LOCAL=$RD_WR/usr.local
#
HOME="$RD_WR/home"
#
#
#
# ===================================================
# Create /dev/ram2 for /var	for system log files
# ===================================================
#
# mkdir -p $RD_WR/var/{empty,spool,lock/subsys,log/setup/tmp,run,tmp}
#
# umount /dev/ram2
#
BootMsg "..Creating /dev/ram2 ( /var ).."
dd if=/dev/zero of=/dev/ram2 bs=1024 count=8192 2> /dev/null
sync
mke2fs -q -m 0 /dev/ram2
sync
#
mkdir -p $VAR
mount /dev/ram2 $VAR
#
touch $RD_WR/var.ram2
touch $RD_WR/var/...ram2
#
#
# Do this one, make sure the link to the rw /var exists each time
if [   -d /var ]; then mv /var /var.loop0 ; fi
if [ ! -s /var ]; then cd / ; ln -s ./$VAR . ; fi
#
if [   -d /tmp ]; then mv /tmp /tmp.loop0 ; fi
if [ ! -s /tmp ]; then cd / ; ln -s ./$VAR/tmp . ; fi
#
# ------------
# make /var rw 
# ------------
#	- the directories should be empty
cp -dpar /var.loop0/* $VAR
#
# there's nothing we need to copy (save) from /tmp
chmod 1777 /var/tmp
#
#
#
# ======================================
# Create /dev/ram3 for /usr/local
# ======================================
#
# umount /dev/ram3
#
BootMsg "..Creating /dev/ram3 ( /usr/local ).."
dd if=/dev/zero of=/dev/ram3 bs=1024 count=8192 2> /dev/null
sync
mke2fs -q -m 0 /dev/ram3
sync
#
mkdir -p $LOCAL
mount /dev/ram3 $LOCAL
#
#
# for /usr/local/share and from /mnt/loop2/usr
#
cd $RD_WR ; ln -s ./usr.local usr
#
touch $RD_WR/usr.local.ram3
touch $LOCAL/...ram3
#
if [ ! -s /usr/local ]; then cd /usr ; ln -s ../$LOCAL local ; fi
#
#
mkdir /usr/local/{src,sbin,bin,lib,share}
#
#
# ========================================
# Create /dev/ram4 for /opt/home ( /home)
# ========================================
#
# umount /dev/ram4
#
BootMsg "..Creating /dev/ram4 ( /home ).."
dd if=/dev/zero of=/dev/ram4 bs=1024 count=8192 2> /dev/null
sync
mke2fs -q -m 0 /dev/ram4
sync
#
mkdir -p $HOME
mount /dev/ram4 $HOME
#
touch $RD_WR/home.ram4
touch $HOME/...ram4
#
#
# Do this one, make sure the link to the rw /home exists each time
if [   -d /home ]; then mv /home /home.loop0 ; fi
if [ ! -s /home ]; then cd / ; ln -s ./$HOME . ; fi
#
if [   -d /root ]; then mv /root /root.loop0 ; fi
if [ ! -s /root ]; then cd / ; ln -s ./$HOME/root . ; fi
#
# ---------------------------
# make /home and /root is rw
# ---------------------------
cp -dpar /home.loop0/* $HOME
#
mkdir $HOME/root
cp -dpar /root.loop0/* /root.loop0/.{a,b,d,e,f,x}* $HOME/root
touch $HOME/root/...ram4
#
#
#
# Check what it looks like
# ------------------------
# ls -la /root /tmp /var /usr/local
# echo ""
#
#
# End of file

