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:
    /bin/bzip2
    /bin/cat
    /bin/chattr
    /bin/cp
    /bin/dash
    /bin/dd
    /bin/dmesg
    /bin/gzip
    /bin/ls
    /bin/lsattr
    /bin/mkdir
    /bin/mount
    /bin/mv
    /bin/rm
    /bin/tar
    /bin/umount
    /etc/modprobe.d
    /lib/ld-linux.so.2
    /lib/libacl.so.1
    /lib/libattr.so.1
    /lib/libblkid.so.1
    /lib/libbz2.so.1.0
    /lib/libc.so.6
    /lib/libcom_err.so.2
    /lib/libdevmapper.so.1.02.1
    /lib/libdl.so.2
    /lib/libe2p.so.2
    /lib/libext2fs.so.2
    /lib/libncurses.so.5
    /lib/libpthread.so.0
    /lib/librt.so.1
    /lib/libselinux.so.1
    /lib/libsepol.so.1
    /lib/libuuid.so.1
    /lib/modules/2.6.18.8/kernel/drivers/ide/ide-disk.ko
    /lib/modules/2.6.18.8/kernel/drivers/ide/ide-generic.ko
    /lib/modules/2.6.18.8/kernel/drivers/scsi/scsi_mod.ko
    /lib/modules/2.6.18.8/kernel/drivers/scsi/sd_mod.ko
    /lib/modules/2.6.18.8/kernel/drivers/usb/host/ehci-hcd.ko
    /lib/modules/2.6.18.8/kernel/drivers/usb/host/ohci-hcd.ko
    /lib/modules/2.6.18.8/kernel/drivers/usb/host/uhci-hcd.ko
    /lib/modules/2.6.18.8/kernel/drivers/usb/storage/usb-storage.ko
    /lib/modules/2.6.18.8/modules.dep
    /lib/terminfo/l/linux
    /sbin/fdisk
    /sbin/losetup
    /sbin/mke2fs
    /sbin/mkswap
    /sbin/modprobe
    /usr/bin/less
    /usr/lib/libz.so.1
    /usr/sbin/mkcramfs

    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-2.6.18.8 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
    pwd
  • Display the contents of the current directory.
    ls
  • 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