Sunday, November 15, 2009

Linux: Creating a Rescue Ramdisk Image

Here I write about a very simple and crude method of creating a rescue initrd image for the purpose of fixing or restoring Linux systems. I use this method when it's inconvenient to creating a sophisticated Rescue CD or when the CD-ROM is inaccessible. In short, this method involves creating a ramdisk image, saving it on a hard disk partition, and using a boot loader like GRUB to boot Linux into a Ramdisk system.

  1. Let's create an initrd image first. Create a text file that lists the contents of the ramdisk image. For example, my rescue.txt file has the following contents:

    Save this file as, for example, rescue.txt.

  2. Create a temporary directory, for example, /tmp/rescue.
    mkdir /tmp/rescue
  3. Use tar to copy files specified in rescue.txt.
    cd /
    tar cvhf - -T /home/jocelyn/rescue.txt | (cd /tmp/rescue; tar xf -)
  4. Create device files.
    cd /tmp/rescue
    mkdir dev mnt tmp
    cd dev
    MAKEDEV std hda sda consoleonly

    Create an InitRD image. I like to use mkcramfs for this purpose.

    mkcramfs /tmp/rescue /boot/rescue.bin
  5. When you start your computer, use GRUB commands like the following to boot Linux into the ramdisk system.
    kernel (hd0,5)/boot/vmlinuz- root=/dev/ram0 init=/bin/dash
    initrd (hd0,5)/boot/rescue.bin
    You'll arrive at a very simple rescue console.

Examples of Possible Commands in Rescue Console

  • Edit the partition table with fdisk.
    fdisk /dev/hda
  • Display the partition table.
    fdisk -l -u /dev/hda
  • Format a partition as Linux EXT2.
    mke2fs -L LINUX -I 128 /dev/hda6
  • Mount a Linux partition on /mnt.
    mount -n -t ext2 /dev/hda6 /mnt
  • Change the current directory and then display the current path.
    cd /mnt
  • Display the contents of the current directory.
  • Mount a FAT32 partition on /tmp.
    mount -n -t vfat -o codepage=437,iocharset=iso8859-1,shortname=winnt /dev/hda7 /tmp
  • Restore a backup from a tarball onto the current folder.
    tar xzf /tmp/backup-072499.tgz
  • Unmount a partition.
    umount /mnt

About This Blog

KBlog logo This blog seeks to provide useful information to people, based on the author's knowledge and experience. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Follow by Email

Total Pageviews