Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Most Busybox questions are related to the fact that users are dropped to a Busybox shell due to some unknown issues at boot time. This must make Busybox one of the most hated pieces of software.

My problem is the opposite. I want to deliberately start Busybox at boot time either from GRUB, or even before GRUB. Is this possible? How can I do it? The purpose is to execute some commands before the boot sequence is reinitiated. So basically I want to execute some commands to make some hardware available to the bootloader.

share|improve this question
up vote 1 down vote accepted

You will need to make a custom initrd.

Extract an initrd, note I use ~/initrd as a working directory

cp /boot/initrd_your_version ~
cd ~/initrd
gzip -dc ../initrd_your_version | cpio -imvd --no-absolute-filenames

You did not mention what you wanted to do, so I can only give general advice here.

Now, add any libs and/or binaries you need into the ~/initrd . Use ldd to identify dependencies.

Edit ~/initrd/init , it is a shell script, so add in what you need.

Package it up

cd ~/initrd
find . | cpio --quiet --dereference -o -H newc | gzip -9 > ../initrd-custom.img.your_version

See also:

Sure that link is gentoo, but I do not know of any such detailed document for Ubuntu.

See also :

share|improve this answer
Decompressing fails with the error: lzma: initrd.img-3.2.0-24-generic: File format not recognized cpio: premature end of archive I've had more success with: gzip -dc initrd.img-3.2.0-24-generic | cpio -imvd --no-absolute-filenames I'll see how this goes further. – user12681 Jun 11 '12 at 22:52
Ah, you are correct it is gziped, will update my post. – bodhi.zazen Jun 11 '12 at 23:51

I have used this way to unlock an encrypted partition remotely, so I guess it could work for your need.

  • Embed dropbear in the initramfs.

apt-get install openssh-server dropbear busybox

  • Copy the SSH key that has been automatically generated.

scp root@my.server.ip.addr:/etc/initramfs-tools/root/.ssh/id_rsa ~/id_rsa.initramfs

  • In case that you are not using DHCP edit /etc/default/grub and add a similar line with your config:


  • Reload grub configuration update-grub


  • reboot

Take care since different grub versions have different configuration options.

Now you should be able to connect remotely via your SSH key and pass some commands on the boot process.

You can find more info here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.