Thursday, November 25, 2010

How to backup, restore and mount hard disk from RAW-image in Linux

Here is an example of how to create 'sda' compressed disk image, split by 2 gig chunks and move to remote server:

dmitry@lvm:~$ sudo -s
[sudo] password for dmitry:
root@lvm:~# mkdir /mnt/share
root@lvm:~# smbmount //remote_server_name_or_ip/share_name /mnt/share -o workgroup=your_domain,username=your_user_name,password=your_password
root@lvm:~# dd if=/dev/sda | gzip -c | split -b 2000m -

The following command will restore hard drive from image:

root@lvm:~# cat /mnt/share/sda.img.gz.* | gzip -dc | dd of=/dev/sda

To mount drive partition from the image we must have single image file, that can be created with:
root@lvm:~# dd if=/dev/sda of=/mnt/share/sda.img

To mount first drive partition from the image:
root@lvm:~# mkdir /mnt/disk
root@lvm:~# mount -o loop,offset=32256 /mnt/share/sda.img /mnt/disk

To unmount drive:
root@lvm:~# umount /mnt/disk

It's just a brief overview of how to deal with disk images in Linux. For more information see corresponding commands manuals.

No comments: