LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 04-02-2012, 01:56 PM   #1
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Rep: Reputation: 15
Clone/restore disk with dd


i'm trying to clone my CentOS 5 VM. Now I've read some tutorials on dd and it looked pretty straight forward.

I've booted my VM i'm cloning into rescue mode, mounted my NAS to place my image file, and used the following dd to clone the disk:

Code:
dd if=/dev/sda of=/path/to/my/nas/sda.img bs=64K conv=noerror,notrunc
Now I created a new VM, booted it in rescue mode, mounted my NAS, I ran the following command to restore the image to this new VM:

Code:
dd if=/path/to/my/nas/sda.img of=/dev/sda
its my understanding that when you dd the entire disk (/dev/sda) that this copies the MBR/partition table but when i run fdisk -l on the new VM, there is no partition table. When i reboot my new VM, there is no OS. Did I miss something? Did I miss a step? Do I need to backup/restore the MBR as well?
 
Old 04-02-2012, 03:05 PM   #2
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,373

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
A VM has a single or set of files that can easily be copied in the HOST. Why don't you just copy the virtual hard drive and don't fool with the dd part in the client?

If I do dd on a real system I don't like to boot the original OS. I use a live cd/usb to access the real hard drive and put to some place.

Last edited by jefro; 04-02-2012 at 03:06 PM.
 
Old 04-02-2012, 04:32 PM   #3
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Hi Jefro, yea I know, I've cloned my VM by copying the vmx files before. I'm just trying to learn how to use the dd command and how to clone a system.
 
Old 04-02-2012, 06:06 PM   #4
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,500

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
I agree with you that this should work.

I just tried to copy the first 1k bytes from my /dev/sda to a file, and compared /dev/sda and the image file with hexedit. They are equal.
When you you open with khexedit the orginal /dev/sda, the .img file and the new /dev/sda, what do you see?

jlinkels
 
Old 04-02-2012, 07:06 PM   #5
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,373

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
Then boot your VM to a live iso. Then dd it over. Be sure to use /dev/sda and not sda1.
 
Old 04-02-2012, 09:57 PM   #6
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Original Poster
Rep: Reputation: 15
hello jlinkels, I'm not famaliar with khexedit or hexedit. Any other ideas?
 
Old 04-03-2012, 01:27 AM   #7
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Well guyz, I think i figured it out, ran the dd command to copy the disk and I changed the follow bs option from 64K to 4096 and I also removed the notrunc as well. That seemed to fix the issue.
 
Old 04-03-2012, 06:22 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,133
Blog Entries: 2

Rep: Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836Reputation: 4836
I used your commands many many times and they always worked, but I never used the conv=noerror,notrunc part of it.
Just a sidenote, if you are not speed limited (like a copy from disk to disk) you will get much better performance with larger blocksizes, I have had made good experiences with blocksizes between 4-16MB.
 
Old 04-03-2012, 10:37 AM   #9
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,500

Rep: Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636Reputation: 636
Quote:
Originally Posted by L1nuxn00b703 View Post
Well guyz, I think i figured it out, ran the dd command to copy the disk and I changed the follow bs option from 64K to 4096 and I also removed the notrunc as well. That seemed to fix the issue.
Reducing the BS down to 4096 awfully slows down the process. In addition, the conv=notrunc option was also used as an example in the learn the dd command thread, so I don't see a reason why that shouldn't work.

Maybe you could try to experiment with both settings (or neither) and check the result, just for the sake of learning.

jlinkels
 
Old 04-03-2012, 09:47 PM   #10
jefro
Moderator
 
Registered: Mar 2008
Posts: 16,373

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381
I like to know about errors, so that is why I like dd and just a block size number.
 
Old 04-04-2012, 07:03 PM   #11
L1nuxn00b703
Member
 
Registered: Sep 2009
Posts: 117

Original Poster
Rep: Reputation: 15
Ok guyz, i just ran the same command on my VM in rescue mode

Code:
dd if=/dev/sda of=/path/to/my/nas/sda.img bs=64K conv=noerror,notrunc
And then I restored it without any issues. I guess the 1st time around I tried it, there was some kind of disk/network hiccup.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
clone hard disk with: cat /dev/sda >/media/disk/backup deathalele Linux - Security 3 04-17-2009 12:29 AM
LXer: Clone/Back Up/Restore OpenVZ VMs With vzdump LXer Syndicated Linux News 0 11-25-2008 10:40 AM
RAID1 array down to one disk with bad blocks, clone to good disk with dd noerror? ewolf Linux - Server 2 05-10-2008 12:40 AM
clonezilla clone disk to image, when restore from image to destination hdd problem. hocheetiong Linux - Newbie 3 05-06-2008 07:59 PM
Can't clone FC6 using tar-backup and restore skellert Fedora 10 03-30-2007 06:13 PM


All times are GMT -5. The time now is 12:38 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration