Image

Image

Search This Blog

Tuesday, February 04, 2014

Recover / from a full backup

If we have a nightly dd of the / partition and we need to put that on a new disk, we have to follow this procedure:
let's mount the image in /tmp/1 and the new disk in /media/sdb1:

fdisk -l media/server/disk2/backup/backup,img - note the start block and the sector size, then multiply them to obtain the mount offset.

Disk /media/server/disk2/backup/backup.img: 7.5 GiB, 8004304896 bytes, 15633408 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x0000d331

Device                              Boot Start   End  Blocks  Id System
/media/server/disk2/backup/backup.img 1 * 62  15633407 7816673 83 Linux

512*62=31744

mount -t ext4 -o loop,ro,noexec,noload,offset=31744 /media/server/disk2/backup/backup.img /tmp/1

mkfs.ext4 -O ^has_journal -E stride=2,stripe-width=1024 -b 4096 -l root /dev/sdb1

tune2fs -o journal_data_writeback /dev/sdb1
mount /dev/sdb1/ /media/sdb1

then we can copy the content of that image to the new disk:
cd /tmp/1 && find . -depth -print | cpio -padmV /media/sdb1

we need to sed the new UUID (blkid /dev/sdb1) into /media/sdb1/boot/grub/menu.lst and /media/sdb1/etc/fstab, then
mount --bind /dev /media/sdb1/dev
mount --bind /proc /media/sdb1/proc
mount --bind /sys /media/sdb1/sys
followed by chroot /media/sdb1 /bin/bash

in the chroot we need to check the value of the actual kernel in /lib/modules/xxxxxx.xx and run a mv /boot/initrd-xxxxxxx.xx.img /boot/old.img then
dracut /boot/initrd-xxxxxxx.xx.img xxxxxx.xx

As an alternative we can change the UUID of the new disk with tune2fs -U `old_uuid` /dev/device-name

Now we can run an /boot/grub/install-grub (or run grub, followed by find /boot/grub/stage1 then root (hd1,0) and  setup (hd1) ) and finally put the new disk in the machine and boot!

No comments:

Post a Comment

Blog Archive