Sunday, March 29, 2009

Kernel Recompilation

Well, there are a lot of complicated steps we need to follow, and this is what I usually do:
0. yast -i ncurses-devel     #ensure ncurses-devel is installed  
1. make mrproper #clean config
2. cp /boot/config-x.x.x ./.config (or: cp /boot/config-`uname -r` ./.config)
3. make menuconfig (or: make oldconfig)

For normal steps:
4. make dep; make clean         #clean compilation
5. make bzImage
6. make modules
7. cp src/arch/i386/boot/bZimage /boot/vmlinuz-x.y.z
8. make modules_install
9. mkinitrd

For SUSE steps:
4. make rpm
5. Secure the backup:
cp /usr/lib/rpm/find-provides.ksyms /usr/lib/rpm/find-provides.ksyms.orig
cp /usr/lib/rpm/find-requires.ksyms /usr/lib/rpm/find-requires.ksyms.orig
cp /usr/lib/rpm/find-supplements.ksyms /usr/lib/rpm/find-supplements.ksyms.orig
6. Change "kernel-*)" to "kernel *)"
#kernel-*) is_kernel_package=1 ;;
kernel-*) is_kernel_package=1 ;;
7. -
8. rpm -ivh kernel-x.x.x.rpm
9. make initrd

Saturday, March 21, 2009

Reviving the grub in the rsync's Backup Disk

Incremental backup with rsync is very effective for daily backup.
However, it cannot be used to boot the system after failure.

This is because the disk is just simply a storage without capability to boot the Linux.
In order to make it bootable, the boot loader has to be installed back.

Assuming the grub should be installed into MBR, the steps would be:

1. Boot the system with rescue CD

2. Invoke the following command:

# mount /dev/sda1 /mnt/ # Assuming the main disk resides on single partition
# mount –t proc none /mnt/proc
# mount –o bind /dev /mnt/dev
# chroot /mnt/ /bin/bash
# grub
At grub:
grub> root (hd0,1)
grub> setup (hd0)
grub> quit

3. Check (and adjust if necessary) the config files like menu.lst, device.map, fstab, and mtab.

4. If needed, run: "grub-install --recheck --root-directory=/mnt /dev/sda"

Still cannot boot?
Well, be happy with dd and just troubleshoot the MBR of your disk:
# dd if=/dev/sda count=1 bs=512 | xxd

Friday, March 13, 2009

Incremental Backup with rsync

There are few reasons I don't want to use dd for full backup:
- My HD is having 250GB data and I don't want to do daily backup for it
- My data do not change so frequently
- I don't want to burden my server with 250GB of daily thrashing just for backup only

To do incremental backup, we can make use of rsync:
rsync -azvr /mnt/localbind root@mystorages:/mybackup/

To simplify the life, just use single partition for each physical disks, and bind them in the fstab.

#!/bin/bash

TIMESTAMP=`date +%Y%m%d_%H%M%S`

mount -o bind,ro / /mnt/localbind
mount -o remount,rw /backup/mainbackup

nice -n 19 rsync -azvrb --suffix=.rsync_$TIMESTAMP /mnt/localbind/ /backup/mainbackup/
echo "Backup performed on $TIMESTAMP" >>/backup/backup.log
sync

umount /mnt/localbind
mount -o remount,ro /backup/mainbackup

Saturday, March 7, 2009

Simple Backup using dd

Backup the whole disk becomes easier with dd command:

1. Fill empty zero till full: "dd if=/dev/zero of=/tmp/delete.me bs=8M; rm delete.me"
2. Invoke the dd command combined with gzip: "dd if=/dev/sda bs=4096 | gzip > /mnt/nfs/diskboot.img.gz"

3. To restore the data from image into the disk, execute: "gzip -dc /mnt/nfs/diskboot.img.gz | dd of=/dev/xxx" (replace /dev/xxx with your target disk)

Warning: Be extra careful when invoking "dd of=/dev/xxx" command since it can wipe out all of your data on your disk if you are pointing to the wrong device.