I have managed to get a Linksys MediaHub running on Debian using pivot_root, but I have a small question about the way it handles services:
It has a partition of 300MB (and may not be larger, else uBoot won't load the kernel off the disk), this contains a very basic Debian squeeze install with only the necessary options. I also have a larger 20GB partition where this same data stored on and there I have installed SSH, Samba etc on.
The problem is that I now have the pivot_root action in /etc/rc.local, where this is called at the end of the init process. What I would like to accomplish is that the pivot_root action is being handled before the system services like SSH and Samba are started, because they can only be started when the pivot_root has taken place.
I've search a while on Google and on the forums, but was not able to sort this out, anybody got a lead for me?
The script I've created is below should someone need it:
Code: Select all
#!/bin/bash
#
# Created by Jeffrey Langerak on 30-3-2013
#
# This script will pivot_root from the small 300MB
# partition to the bigger partition, allowing the
# installation of packages and configuration
#
# This script is delivered as is, no warranties are
# given and you should use this at your own risk!
#
# Version 1.0
#
# Setting colors and columns:
RED=$(tput setaf 1)
GREEN=$(tput setaf 2)
NORMAL=$(tput sgr0)
col=80 # change this to whatever column you want the output to start at
# Check for /overlay directory
echo -n "Checking for /overlay directory:"
if [ -d /overlay ];
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
echo -n "Creating /overlay directory:"
if mkdir /overlay > /dev/null 2>&1
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
exit
fi
fi
# Mount 3rd partition on /overlay
echo -n "Mounting /dev/sda3 on /overlay:"
if mount /dev/sda3 /overlay > /dev/null 2>&1
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
exit
fi
# Checking for old-root directory in /overlay
echo -n "Checking for /overlay/old-root directory:"
if [ -d /overlay/old-root ];
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
echo -n "Creating /overlay/old-root directory:"
if mkdir /overlay/old-root > /dev/null 2>&1
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL]" "$NORMAL"
exit
fi
fi
# Pivot_root to the new root filesystem mounted on /overlay
echo -n "Switching filesystem to overlay filesystem:"
if /sbin/pivot_root /overlay /overlay/old-root > /dev/null 2>&1
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL" "$NORMAL"
exit
fi
# Mount /proc
echo -n "Mounting /proc:"
if mount -t proc proc /proc > /dev/null 2>&1
then
printf '%s%*s%s' "$GREEN" $col "[OK]" "$NORMAL"
else
printf '%s%*s%s' "$RED" $col "[FAIL" "$NORMAL"
exit
fi
# Done
exit