Monday, June 21, 2010

Boot to single user mode in Ubuntu 10.04 Lucid Lynx

This is symptomatic of how often I break X.org but I often need to boot my Ubuntu 10.04 machine into single user mode and fix some configuration file before rebooting into the GUI. I forget how to do it every time so here is how:

  1. Hold the Shift key at boot to display the Grub boot menu.
  2. Select the top Grub entry, it will be similar to:
    Ubuntu, with Linux 2.6.32-22-generic-pae
  3. Hit e to edit the the Grub entry.
  4. Find the line that looks like this:
    linux /boot/vmlinuz-2.6.32-22-generic-pae
    root=UUID=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
    ro vga=794 quiet splash
  5. Change the line to:
    linux /boot/vmlinuz-2.6.32-22-generic-pae
    root=UUID=xxxxxxxx-xxxx-xxxx-xxxxxxxxxxxx
    init=/bin/bash rw
  6. Hit crtl+x to boot

Your machine will now do a one time boot into single user mode. Once you reboot the changes you just made to Grub will be reverted.

** /bin/sh corrected to /bin/bash thanks Hola2040.

Sunday, June 20, 2010

Activate the cron daemon on a DroboFS

I recently purchased a DroboFS NAS from DataRobotics. The device runs a minimal Marvell Linux OS on top of a low power ARM CPU (ARM926EJ-S).

The DroboFS supports third party development through the DroboApps platform. This allows end users to compile ARM applications using the GNU tool chain and run them on their DroboFS. On top of this these applications can be run as services using a small service API provided by DroboApps.

A number of DroboApps are available to enable dormant services on the DroboFS including the SSH, HTTP and FTP servers.

The DroboFS ships with a cron daemon tucked away at /usr/sbin/crond however there is no DroboApp available to enable the daemon. To rectify this I have written a small DroboApp script to activate the cron daemon at boot.

To get cron running as a service you'll need to do the following:
  1. Enable DroboApps on your DroboFS.
  2. Install the Dropbear SSH DroboApp.
  3. SSH into your DroboFS
  4. Create a directory for the cron DroboApp:
    mkdir /mnt/DroboFS/Shares/DroboApps/crond
  5. Save the following service.sh into your cron DroboApp directory
    #!/bin/sh
    # ------------------------------------------------------------
    # service.sh for cron DroboApp
    #
    # Exposes the crond binary existing on the DroboFS as a 
    # DroboApps service.
    # ------------------------------------------------------------
    
    # Binaries used
    AWK="/usr/bin/awk"
    GREP="/bin/grep"
    CROND="/usr/sbin/crond"
    DATE="/bin/date +%Y:%m:%d-%H:%M:%S" # Nicely formatted date
    ECHO="/bin/echo"
    PS="/bin/ps"
    
    # Load the DroboApps service functions
    . /etc/service.subr
    
    # Required DroboApps variables
    prog_dir=`dirname \`realpath $0\``
    name="crond"                    # service name
    version="1.14.2"                # program version
    pidfile=${prog_dir}/crond.pid # location of pid file
    logfile=${prog_dir}/crond.log # location of log file
    
    # Start crond
    start()
    {
      # Start the service
      $CROND
    
      # Create the pidfile
      pid=`$PS | $GREP $CROND | $GREP -v grep | $AWK '{print $1}'`
      $ECHO $pid > $pidfile
    }
    
    case "$1" in
      start)
        start_service
        $ECHO "`$DATE` Started cron service" >> $logfile    
        ;;
      stop)
        stop_service
        $ECHO "`$DATE` Stopped cron service" >> $logfile    
        ;;
      restart)
        stop_service
        sleep 3
        start_service
        $ECHO "`$DATE` Restarted cron service" >> $logfile    
        ;;
      status)
        status
        ;;
      *)
        $ECHO "Usage: $0 [start|stop|restart|status]"
        exit 1
        ;;
    esac
    
  6. Restart your DroboFS.
Now the cron daemon is running from boot on your DroboFS. To add tasks for the cron daemon to run you will need to SSH into your DroboFS and run the following:
mkdir -p /var/spool/cron/crontabs
crontab -e
I hope someone finds this helpful.


2010-06-24: Edit added "mkdir -p /var/spool/cron/crontabs" Thanks pimvanderzwet