I need to do some maintenance on a bunch of Debian (Wheezy) systems, and it has to happen at run level 1. But not all machines have a keyboard and a screen; some are even located somewhere else. So I can't just go there and type in the root password to trigger the job.

So my question is how can I tell Debian to run a command right before the "Type root password or ^D" prompt?

I've tried to make a init script that only runs on run level 1, but still it was triggered before all processes where killed.

Is there a way to do this?

  • Why does it need to be done on runlevel 1?
    – jordanm
    Jul 15, 2014 at 15:11
  • 1
    I need to remount the root filesystem as ro Jul 15, 2014 at 17:36

1 Answer 1


I found a way, but it feels dirty... :)
So i'll leave this open and see if someone has a clean way.

My solution is to modify inittab to run a script instead of sulogin and restore the old inittab from within the script.

here is a 'cut and paste to the terminal' proof of concept version which i just used to compact some VM harddrives.

But: Don't just try this unless you know what it does!

mkdir -p /opt/single
cp -a /etc/inittab /opt/single/inittab
sed -i "s/\/sbin\/sulogin/\/opt\/single\/job.sh/" /etc/inittab
  #restore inittab
  mv -fv /opt/single/inittab /etc/inittab
  #make sure no one runs this by accident
  chmod -x /opt/single/job.sh
  #do your thing...
  mount -o remount,ro /dev/sda1
  fsck.ext4 -vfp /dev/sda1
  zerofree -v /dev/sda1
  mount -o remount,rw /dev/sda1
  #work done 
chmod +x /opt/single/job.sh
telinit 1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .