2011/04/01

loopback magic

First you used dd to grab the entire contents of a disk. Now you want to copy that disk to another one. Only the new disk isn't the exact same size as the old one, and probably doesn't have the same geometery. In which case you would be better off doing an rsync then dd to the new disk. The following trick will also work if you just want to read a partition.

First we need the offset of each partition:
#sfdisk -uB -l fulldump

last_lba(): I don't know how to handle files with mode 81a4
Disk fulldump: cannot get geometry

Disk fulldump: 17 cylinders, 255 heads, 63 sectors/track
Warning: The partition table looks like it was made
for C/H/S=*/224/56 (instead of 17/255/63).
For this listing I'll assume that geometry.
Units = blocks of 1024 bytes, counting from 0

Device Boot Start End #blocks Id System
fulldump1 28 144255 144228 83 Linux
fulldump2 144256 39080831 38936576 8e Linux LVM
fulldump3 0 - 0 0 Empty
fulldump4 0 - 0 0 Empty
We ignore the warning messages, because we see that the first partition starts at 28*1024=28672 bytes. So we can mount that easily.
# mount -o loop,offset=$((28*1024)) fulldump /mnt

# ls /mnt
config-2.6.18-164.el5 message
config-2.6.18-194.11.3.el5 symvers-2.6.18-164.el5.gz
grub/ symvers-2.6.18-194.11.3.el5.gz
initrd-2.6.18-164.el5.img System.map-2.6.18-164.el5
initrd-2.6.18-194.11.3.el5.img System.map-2.6.18-194.11.3.el5
initrd-2.6.18-194.11.3.el5-PG1.img t/
initrd-2.6.18-194.11.3.el5-PG2.img vmlinuz-2.6.18-164.el5
initrd-2.6.18-194.11.3.el5-SSD1.img vmlinuz-2.6.18-194.11.3.el5
lost+found/
I used $((28*1024)) because this way bash does the calculation for us.

No comments: