Magic 'catch nearly all' for Linux rescue repair

Chances are that at some time, you’ll need to repair a corrupted filesystem, or worse, fix something you accidentally broke. Sometimes, your operating system will do this, especially if you are a fan of Linux. Such as the case with the Core2, today:

[    0.179209] Unpacking initramfs...
[    1.176420] ------------[ cut here ]------------
[    1.176514] WARNING: at arch/x86/mm/init.c:504 free_init_pages+0x53/0x11f()
[...]
[    1.177589] Call Trace:
[    1.177672]  [<ffffffff81734b42>] dump_stack+0x19/0x1f
[    1.177759]  [<ffffffff8104d6b6>] warn_slowpath_common+0x62/0x7b
[    1.177846]  [<ffffffff8104d6e4>] warn_slowpath_null+0x15/0x17
[    1.177933]  [<ffffffff81037181>] free_init_pages+05x3/0x11f
[    1.178025]  [<ffffffff81d32c4b>] free_initrd_mem+0x30/0x35
[    1.178112]  [<ffffffff81d1db2b>] populate_rootfs+0xeb/0x10c
[    1.178199]  [<ffffffff81d1da40>] ? unpack_to_rootfs+0x289/0x289
[    1.178286]  [<ffffffff8100209b>] do_one_initcall+0x9b/0x135
[    1.178373]  [<ffffffff81d1b8eb>] kernel_init_freeable+0x154/0x1ea
[    1.178461]  [<ffffffff81d1b981>] ? kernel_init_freeable+0x1ea/0x1ea
[    1.178550]  [<ffffffff81725900>] ? rest_init+0x74/0x74
[    1.178636]  [<ffffffff81725909>] kernel_init+0x9/0xd6
[    1.178723]  [<ffffffff8173d73c>] ret_from_fork+0x7c/0xb0
[    1.178810]  [<ffffffff81725900>] ? rest_init+0x74/0x74
[    1.178900] ---[ end trace ded000897d630586 ]---
[    1.179052] Freeing initrd memory: 11812k freed

Long story short, the kernel became unhappy with the latest update, and being a headless machine with no remote hands, I had to figure how to fix it.

Now, although I don’t have remote hands, I have a fairly dated (and limited) sysrescue image which I can boot the system from, and manipulate my installation from there.

Despite architectural and distribution differences, a 3.x kernel with most options available can get you back online with minimal effort.

Althought teaching you how to handle LVM/etc is not something for a quick little diary entry, I will offer this bit of advice: The following mounting heirarchy tends to work OK for Debian, CentOS, and almost any other Linux distribution I’ve thrown at it:

# fsck.{filesystem} /dev/{device}{partition} #root partition
# mount -t {filesystem} /dev/{device}{partition} /mnt
# mount -o bind /dev /mnt/dev
# mount -t sysfs sys /mnt/sys
# mount -t devpts pts /mnt/dev/pts
# mount -t proc proc /mnt/proc
# cd /mnt
# {mount/fsck any subpartitions here}
# chroot /mnt /bin/{dash|bash|ash}

Happy repairs!