Sunday, October 9, 2011

Restoring your initramfs

So a couple of days ago I ran a system upgrade on my arch-box(also my primary laptop), it told me that I needed to upgrade to 3.0 kernel. Cool I thought and went through. And after fixing some driver problems, I accidentally crashed my initramfs - no booting for me. I guess you know the problem, since your here, so read on and get the answer.

I must say, this article wouldn't have been, if it weren't for the Archlinux wiki and the IRC channel. Thanks to falconindy, Hattara-pilvi, brain0. Andd thanks to d_garbage for finding them in his logs.

How you doing?

Once again I had some problems with my wireless driver, so I followed normal procedure. Copy old driver .so-file to new kernel folder. Everything was all dandy, so I rebooted and BAM! no wireless networks for me.

After fixing things and such, i recreated my initramfs, with mkinitcpio. Rebooted and wham bam thank you mam, "You have junk in your initramfs" - sorry to those of you who misses the original text, but I forgot to write it down.

So how am I going to rescue my computer? Well the obvious answer is recreate your initramfs. But how are you going to do this, when it doesn't even get to some console/tty.

Here's a short list with each step, explanations later:

  1. Make a bootable device with arch
  2. Mount the necessary partitions
  3. Run mkinitcpio

Bootable device - USB

# Naive way
dd if=image.iso of=\\?\Device\Name\Windows\Way\ugh
# More sophisticated, but slow. And --progress is specific for "dd for windows"
dd if=iamge.iso of=\\?\Device\Name\Windows\Way\ugh --progress
# Faster, more sophisticated, same comment as above
dd if=iamge.iso of=\\?\Device\Name\Windows\Way\ugh bs=4M --progress

Sadly my only available machine was a windows-box(But I trained it well). Reading the arch-wiki[1] I found out about "dd for windows"[2]. Made my bootable USB, but when booting from it, it said it didn't have isolinux.bin.

I was just about writing my query to google, booted it again to get the correct error message, and wham it started correctly. Morale, try more than once when you boot from USB's.

When you see the Arch menu - just choose install. This will get you to a console where you can do more than what is needed.

Mounting partitions

I'm not saying my setup is complicated, it just has some quirks :-)

The necessary partitions in this case is /(root) /dev /sys and /proc and in my case boot is on another device/partition, so that also needed some mounting. Also remeber that /dev, /sys and /proc should be bind mounts[3]

Remember that you don't need no sudo, since you already are logged in as root in the arch install.

mount /dev/sdb2 /mnt
mount --bind /dev /mnt/dev
mount --bind /proc /mnt/proc #TBH I'm not sure i used this
mount --bind /sys /mnt/sys
mount /dev/sda1 /mnt/boot

(Re)Running mkinitcpio

You have two options when it comes to this, either chroot, or don't. I chose to chroot, it seemed easier.

chroot /mnt

When running mkinitcpio - remember to specify a preset

mkinitcpio -p linux
# Below commands are untested, and used when not chrooting(as far as I understand)
mkinitcpio -b /mnt -p linux

If all succeeds, you should have a running system by now. Try rebooting(remember to remove the CD/USB - I know stupid warning, but it helps), if all works, celebrate. If it didn't work, please go to the nice and very friendly Archlinux IRC channel on freenode.


  1. =
  2. = (On the wiki page its under the cygwin section)
  3. = I'm sorry I can't explain what it(bind mount) means, but feel free to leave a comment.
Post a Comment

Choose a month: