Linkshare rotating banner
Showing posts with label backup. Show all posts
Showing posts with label backup. Show all posts

Thursday, October 4, 2012

Disk Cloning / Imaging over Network with SSH, Netcat, DD and XZ

Today we have affordable, ample storage and faster bandwidth to facilitate partition imaging and disk cloning over network. Nowadays, it's common and feasible to take the image of a whole partition for various reasons. Compared to file-based backups using tar, disk imaging provides the following advantages.




  • The boot sector is preserved so that it's easy to make it bootable after the restore.
  • Information such as UUID and LABEL is presered, which helps identify the partition in booting and mounting.
  • Information such as ACL and XATTR is preserved, which helps restrict file access and secure the system.
  • Every bit in the unused sectors is preserved, which may assist in digital forensics to uncover deleted or hidden information.


There are commercial programs for disk imaging and backup (Norton Ghost, Acronis True Image). However, Linux users can use readily available tools to get things done. For disk cloning/imaging, we can use ssh, netcat, dd and xz. Note that dd will fail on physically damaged disks. For such disks, use ddrescue instead.



For security and compression, we are going to use ssh and xz in this tutorial. If you don't like xz, feel free to substitute xz with gzip, bzip2 or lzop. Also, netcat is used to stream the dd output over the network. On Debian and Ubuntu derivatives, you need the following packages.




  • bzip2, gzip, lzop, lzma OR xz-utils
  • dd
  • netcat
  • ssh


We are making these assumptions in the following scenarios.




  • Sending computer S

    This computer has IP address 192.168.1.1 and needs to back up partition /dev/sda1.
  • Sending Port

    We'll send using port 5525.
  • Receiving computer T

    This computer has IP address 192.168.1.2 and needs to restore partition /dev/sda2.
  • Receiving Port

    We'll receive at port 7749.


Disk Cloning using dd, xz, netcat and ssh


In this scenario, we will clone a disk partition, simultaneously sending an image of the source partition /dev/sda1 from computer S (192.168.1.1) and restoring it at /dev/sda2 on computer T (192.168.1.2). Make sure that the source partition is not mounted or is mounted read-only. Also, make sure that the target partition size is greater than or equal to the source partition size.




  1. At the sending computer, compress the source partition /dev/sda1 with xz and set up netcat to send it at port 5525:

    dd if=/dev/sda1 bs=16M | xz | nc -l 5525

  2. At the receiving computer, set up a SSH tunnel to the sending computer (192.168.1.1):

    ssh -f -N -L 7749:127.0.0.1:5525 username@192.168.1.1

  3. At the receiving computer, type the following command to receive the partition image and restore it at /dev/sda2:

    nc 127.0.0.1 7749 | xz -d | dd of=/dev/sda2 bs=16M



Alternatively, we could take the following steps to achieve the same thing. However, we start at the receiving computer.




  1. At the receiving computer with the target partition /dev/sda2, type the following command to receive the partition image:

    nc -l 7749 | xz -d | dd of=/dev/sda2 bs=16M

  2. At the sending computer with the source partition /dev/sda1, set up a SSH tunnel to the receiving computer (192.168.1.2):

    ssh -f -N -L 5525:127.0.0.1:7749 username@192.168.1.2

  3. At the sending computer, type the following command to compress the source partition /dev/sda1 and transmit it over the SSH tunnel:

    dd if=/dev/sda1 bs=16M | xz | nc 127.0.0.1 5525

    Note that the transfer may take many hours for a large partition.




Disk Imaging using dd, xz, netcat and ssh


In this scenario, we will just send an image of the source partition /dev/sda1 to the receiving computer T (192.168.1.2) without restoring it. Make sure that the source partition is not mounted or is mounted read-only. A question remains whether to compress the image at the sending or receiving computer. The answer depends on which computer is more powerful. For this example, we'll compress at the sending computer (for network bandwidth reason).




  1. At the sending computer, compress the source partition /dev/sda1 with xz and stream it using netcat:

    dd if=/dev/sda1 bs=16M | xz | nc -l 5525

  2. At the receiving computer, set up a SSH tunnel to the sending computer (192.168.1.1):

    ssh -f -N -L 7749:127.0.0.1:5525 username@192.168.1.1

  3. At the receiving computer, type the following command to receive the file:

    nc 127.0.0.1 7749 > partimg.xz



Alternatively, we could take the following steps to achieve the same thing.




  1. At the receiving computer, set up netcat to listen at port 7749 and save the incoming data to a file partimg.xz.

    nc -l 7749 | dd of=partimg.xz bs=16M

  2. At the sending computer, establish a SSH tunnel to the receiving computer (192.168.1.2) first:

    ssh -f -N -L 5525:192.168.1.2:7749 username@192.168.1.2

  3. At the sending computer, type the following command to compress the source partition /dev/sda1 and transmit it over the SSH tunnel:

    dd if=/dev/sda1 bs=16M | xz | nc 127.0.0.1 5525

    Note that the transfer may take many hours for a large partiiton.




Alternative Simple Commands for Disk Cloning / Imaging


I don't like these methods for some reason, but here I show the simpler methods where netcat is not needed. For disk cloning, type something like this:



dd if=/dev/sda1 bs=16M | xz | ssh username@192.168.1.2 "xz -d | dd of=/dev/sda2 bs=16M"


Just to send an image file, run a command as follows:



dd if=/dev/sda1 bs=16M | xz | ssh username@192.168.1.2 "dd of=partimg.xz bs=16M"


Also Read:


Monday, July 26, 2010

Linux: Using dd To Back Up Hard Drive Partitions

I am going to use the omnipresent and omnipotent tool called dd to back up a hard drive partition. I am working with the drive /dev/sdb. First, I save a text file that has information on the partition table layout.



fdisk -l /dev/sdb > hdpt.txt
fdisk -l -u /dev/sdb >> hdpt.txt


Then, I choose the compression format to use for the backup archive.


  • gzip
  • bzip2
  • lzma
  • xz


My choice for the compression format is lzma which provides superior compression and faster decompression. The following command backs up a partition at /dev/sdb1 with dd and lzma.



dd if=/dev/sdb1 | lzma -9c > backup01.bin.lzma


To restore this backup later, use the following command:



lzcat backup01.bin.lzma | dd of=/dev/sdb1

Monday, July 6, 2009

Ripping a Bootable Acronis TrueImage Diskette

I am trying to incorporate Acronis TrueImage into my bootable Linux CD. Acronis TrueImage is backup software that saves the entire hard disk partition of Windows or Linux system. In short, I am going to use the Bootable Rescue Media Builder to turn my Zip100 or 128MB USB flash into a rescue media, rip it with WinImage and then copy it into my CD. Here's how I did step-by-step:


Start the Bootable Rescue Media Builder under Aronis Start menu.


Bootable_Rescue_Media_Builder_01

In the Rescue Media Contents Selection window, check Acronis True Image Home (Full version) at the left and check Start automatically after 10 sec. at the right. Then, click Next.


Rescue_Media_Contents_Selection

Plug in your USB flash. At the present, any media larger than 64MB will do. That means 128MB USB flash is the minimum. I am using 100MB Zip diskette. At the Bootable Media Selection window, choose a Removable Disk that's blank and more than 64MB, but not Floppy Diskette nor ISO image.


Bootable_Media_Selection

Acronis Media Builder says it's ready to start the media creation process.


Acronis_Media_Builder_Ready

Click Proceed. Acronis Media Builder formats the drive and copies files to it.


Acronis_Media_Builder_Processing

Upon completion, check your rescue media.


Acronis_Media_Builder_complete

Ripping the partition with Linux dd


Now, reboot to Linux and open xterm or your favorite terminal emulator. Plug in your USB flash if you haven't done so. Linux will automatically detect your USB drive. To find the device name of your USB drive, type:


dmesg | tail

dmesg will show the drive letter of the USB flash that was just plugged in. In case your USB flash is /dev/sdc1, type the following command:


dd if=/dev/sdc1 of=sdc1.bin bs=512

This saves the partition of Acronis rescue media as sdc1.bin. Copy it to your Windows partion. Then, reboot to Windows.



Using WinImage to Resize the Partition Image


Download and install WinImage.

Installing Acronis TrueImage Home 2009

Acronis True Image is a cross-platform backup solution for Windows and Linux. True Image is the right choice for regular Windows users besides Norton Ghost. Today I am installing True Image Home 2009 Demo. This download is good for only 15 days unless I purchase a serial. I downloaded the English-language installer (TrueImage2009_d_en.exe) and started it.


At first, clicking on any menu item wouldn't work. Finally I figured it out. I had to right-click on Install Acronis True Image Home and choose Install or Extract from the Right-click menu.


Acronis_True_Image_Home_2009

If it still doesn't work, bring up the Windows Task Manager by pressing Ctrl+Alt+Del and close the Acronis True Image Home Setup.


Korean Windows Vista Task Manager

A “Save As...” dialog will appear and ask for the location to save the installer in. Save the installer file AcronisTrueImage.msi in any folder you want. Then, double-click on AcronicTrueImage.msi to begin TrueImage installation.


Save AcronisTrueImage.msi installer

Just ignore the Serial Number window and continue. I chose Complete setup. Reboot is required after install.

About This Blog

KBlog logo This blog seeks to share useful information on hottest movies available on the Internet. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

icon
Powered By Blogger