LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
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 09-30-2011, 06:31 AM   #706
dgi
LQ Newbie
 
Registered: Dec 2008
Location: Hellas
Distribution: debian
Posts: 3

Rep: Reputation: 0
Hard Disk Image File & restore


Hello everyone.
Great job.

I have 2 hard disks.
Code:
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        2188    17575078+  83  Linux
/dev/hda2            2189        9729    60573082+   5  Extended
/dev/hda5            2189        2310      979933+  82  Linux swap / Solaris
/dev/hda6            2311        9729    59593086   83  Linux

Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000

Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
 
Click here to see the post LQ members have rated as the most helpful post in this thread.
Old 09-30-2011, 09:26 AM   #707
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-35
Posts: 5,313

Rep: Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918Reputation: 918
^that usually works for me (i am assuming this is just a typo but
Code:
dd if = / dev / sda of = ~ / disk1.img
should be
Code:
dd if=/dev/sda of=~/disk1.img
(no spaces. same for the restore.)
 
Old 09-30-2011, 11:30 AM   #708
dgi
LQ Newbie
 
Registered: Dec 2008
Location: Hellas
Distribution: debian
Posts: 3

Rep: Reputation: 0
Yes, withought spaces.
I don't know why it apears like that, anyway... the commands are:

Code:
dd if=/dev/sda of=~/disk1.img
Code:
dd if=disk1.img of=/dev/sda
but does not boot.
 
Old 10-01-2011, 01:58 PM   #709
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Smile DD and the MBR

Quote:
Originally Posted by schneidz View Post
@ awesome-machine, using dd is there a way to copy a 2 gb drive (boot sector + 1 partition) so that when it is restored to a 100 gb drive, it can be expanded to read/write the whole drive ?
You never want to use dd to duplicate the MBR of a drive together with only (1) only one of two or more partitions currently on the drive. DD is a real lifesaver in certain situations, but this isn't one of them!

Frequently it's better to partition and format the target drive and then copy the files as files rather than a whole file system.

rsync -avH <file_or_directory_or_mount_point/*> --exclude=target <target/>

will copy all the files and links and keep existing times, attributes and permissions, for like transferring the contents of a '/' file system.
 
1 members found this post helpful.
Old 10-01-2011, 02:06 PM   #710
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Post Can't image drive AND write the image to the same drive

Quote:
Originally Posted by dgi View Post
Hello everyone.
Great job.

I have 2 hard disks.
Code:
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        2188    17575078+  83  Linux
/dev/hda2            2189        9729    60573082+   5  Extended
/dev/hda5            2189        2310      979933+  82  Linux swap / Solaris
/dev/hda6            2311        9729    59593086   83  Linux

Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000

Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
Ok, well, you can't make a disk image of an entire hard drive AND write it to the same drive, because you can't fit 2x the capacity of the drive on the drive. The notation '~/' means the user's home directory, such as /home/sam.


You must write the image file to a different drive. And, even if you do that, an image of an 80 Gig drive is not going to boot on a 20 Gig drive.

If you're trying a usb drive, it probably has U3 on it. You have to prepare the drive by getting rid of U3. Just write zeros to about 500 MB of it, maybe three times. Then, unplug the drive, plug it back in, partition and format it.

Last edited by AwesomeMachine; 10-01-2011 at 02:10 PM.
 
Old 10-02-2011, 01:35 AM   #711
dgi
LQ Newbie
 
Registered: Dec 2008
Location: Hellas
Distribution: debian
Posts: 3

Rep: Reputation: 0
ok thank you.
Is there a way to make the backup and restore the operating debian, but only the contents and not the empty hard drive ?
 
Old 10-02-2011, 02:13 AM   #712
propofol
Member
 
Registered: Nov 2007
Location: Seattle
Distribution: Debian Wheezy & Jessie; Ubuntu
Posts: 334

Rep: Reputation: 60
I notice that you mentioned the original drive was /dev/hda - you would need to use if=/dev/hda.
If you do want to use dd to clone a drive, it is probably best to use a live cd rather than using it on a mounted drive. In this case it would be:
Code:
dd if=/dev/sda of=/dev/sdb
The destination drive should be the larger drive. Once it has been copied, use gparted to resize the partitions to fill the new drive or alternatively add a new partition and move youre home directory to it.

Regards,
Stefan

Last edited by propofol; 10-02-2011 at 02:15 AM.
 
Old 10-02-2011, 07:14 PM   #713
c1b3rh4ck
LQ Newbie
 
Registered: Jan 2011
Posts: 6

Rep: Reputation: 0
Woo thanks for this article...
 
Old 10-10-2011, 07:08 AM   #714
patoperro
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
rescue flash drive

very informative thread, indeed, sir!
I managed to get through 30 pages of commentary and search results before finally giving up and daring to post a n00besque question. I have an 8GB flash drive that I cannot re-format. Would not normally be crying in my beer, but I shelled out for a Lacie imakey that I don't want to just trash without putting up a fight, and in searching for an answer happened upon your thread.

Have used osx diskutil, gparted boot disk & even doze utils to try and re-format/re-partition, but they all come up with this (or similar) error:

Partition failed with the error: Unable to write to the last block of the device.

From what I gather, I can use the following command to zero out the thumbdrive.
Code:
dd if=/dev/zero of=/dev/disk2 bs=4k conv=notrunc
Is there anything else I can try so as to breathe some life back into the thing?

thanks,
pato

UPDATE: well, the command ran overnight and finished with:
Quote:
dd: /dev/disk2: end of device
1971467+0 records in
1971466+0 records out
8075124736 bytes transferred in 30762.418721 secs (262500 bytes/sec)
Running sudo diskutil eraseDisk FAT32 BLANK /dev/disk2 I get this:
Quote:
Error: -69760: Unable to write to the last block of the device
When I mount it in DiskUtility it still shows the previous volumes (i.e. disk2s1 disk2s2)

Of note are the differences in volume size, currently 7.73GB, but if I choose to re-partition and create 1 new volume in Disk Utility, it claims 8.08GB is the actual size.

Bueller... Bueller... Bueller...?

Last edited by patoperro; 10-13-2011 at 02:51 AM. Reason: updated status
 
Old 11-06-2011, 05:15 PM   #715
skonakanchi
LQ Newbie
 
Registered: Nov 2011
Posts: 1

Rep: Reputation: Disabled
Thumbs up dd netcat

hats off! very useful thread.
many thnaks
-- srihari konakanchi
 
Old 11-09-2011, 08:04 AM   #716
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Smile Quickie copy to larger drive + defrag linux

Quote:
Originally Posted by schneidz View Post
@ awesome-machine, using dd is there a way to copy a 2 gb drive (boot sector + 1 partition) so that when it is restored to a 100 gb drive, it can be expanded to read/write the whole drive ?
Here's the way I do it. And this is also how to defragment a linux file system. Use rsync.

Partition and format the 100 GB drive. I usually boot a live CD--Knoppix or so. Mount the hard drives, and:

#rsync -avH mount_point_one/*<sp>mount_point_two/

If you want to use dd, you must edit the partition table, which for all practical purposes requires too much care, precision and skill to make it feasible except in cases where valuable data is at stake.

You have to manually edit CHS and LBA boundaries in hex values expressed right to left. If you must add a byte to get the correct value, you have to know exactly how to shift the entire value.

It's kind of like training ill-mannered, vicious monkeys to climb sheer cliffs and pick tea leaves.
 
Old 11-09-2011, 08:14 AM   #717
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Smile Duplicating a drive to an image file on itself . . .

Quote:
Originally Posted by dgi View Post
Hello everyone.
Great job.

I have 2 hard disks.
Code:
debian-test:~# fdisk -l
Disk /dev/hda: 80.0 GB, 80026361856 bytes
255 heads, 63 sectors/track, 9729 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x000d4a5e

   Device Boot      Start         End      Blocks   Id  System
/dev/hda1   *           1        2188    17575078+  83  Linux
/dev/hda2            2189        9729    60573082+   5  Extended
/dev/hda5            2189        2310      979933+  82  Linux swap / Solaris
/dev/hda6            2311        9729    59593086   83  Linux

Disk /dev/hdb: 20.4 GB, 20404101120 bytes
16 heads, 63 sectors/track, 39535 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Disk identifier: 0x00000000

Disk /dev/hdb doesn't contain a valid partition table
With the following command I made an image with the operating (debian) and partitions:
Code:
dd if = / dev / sda of = ~ / disk1.img
After I restore it in another disk with the command:
Code:
dd if = disk1.img of = / dev / sda
but does not boot.
I think it's the mbr.
Can you tell me a command to save the image and the mbr
and how to restore the image with the mbr ?
Thank you.
You're trying to image the entire drive to a file on a partition on itself. So, there isn't enough space to hold the file.

The entire contents of the drive + an image file of the entire contents of the drive will not fit on the drive!
 
Old 11-09-2011, 09:45 AM   #718
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Smile

Quote:
Originally Posted by patoperro View Post
very informative thread, indeed, sir!
I managed to get through 30 pages of commentary and search results before finally giving up and daring to post a n00besque question. I have an 8GB flash drive that I cannot re-format. Would not normally be crying in my beer, but I shelled out for a Lacie imakey that I don't want to just trash without putting up a fight, and in searching for an answer happened upon your thread.

Have used osx diskutil, gparted boot disk & even doze utils to try and re-format/re-partition, but they all come up with this (or similar) error:

Partition failed with the error: Unable to write to the last block of the device.

From what I gather, I can use the following command to zero out the thumbdrive.
Code:
dd if=/dev/zero of=/dev/disk2 bs=4k conv=notrunc
Is there anything else I can try so as to breathe some life back into the thing?

thanks,
pato

UPDATE: well, the command ran overnight and finished with:

Running sudo diskutil eraseDisk FAT32 BLANK /dev/disk2 I get this:

When I mount it in DiskUtility it still shows the previous volumes (i.e. disk2s1 disk2s2)

Of note are the differences in volume size, currently 7.73GB, but if I choose to re-partition and create 1 new volume in Disk Utility, it claims 8.08GB is the actual size.

Bueller... Bueller... Bueller...?

If you use dd from the gnu coreutils package, which requires a C compiler and object linker, it will probably wipe the drive, but you need Linux.

OS X is BSD Unix covered in Apple's custom dessert topping, window dressing, and afflicted by Apple operating-system paralysis to make it safe for closed-source software publishers.

That's not quite Linux. Gparted doesn't work because the drive is reporting incorrect size parameters (last block is beyond the end of the drive).

Might wreck the proprietary magic, but that also means freedom from proprietary oppression:

dd if=/dev/zero of=/dev/sdb bs=64k count=1000

Hit the up arrow and repeat the command a few times. Only works in Linux! Right at the very beginning of the OP are instructions to use Linux to make any flash drive, or any drive, completely or partially encrypted.

It employs the same AES-256 encryption as LaCie's application, but you get the security of knowing that the government didn't pay you to create a backdoor key for your encrypted drives!

Commercial software offers empty promises, but Linux delivers open-source, so programmers have read the code, and if it weren't secure, any programmer is at liberty to correct the flaw.

The U.S government is able to securely approach proprietary-software enterprises and request that secret access be built in for use only by government.

But if it approached the open-source software community with such a request, everyone would know!

However, there is a software publisher that offers a distributed-computing password recovery application. So, every idle cpu cycle on every computer used by the government can be harnessed to recover passwords for encrypted volumes, any encrypted volume.

AES-256 encryption is secure, the passwords are not. So, here's a little trick: write the encrypted partition header to a flash drive and then write zeroes over the encrypted partition header on the HDD.

When you want to access the drive, write the header back before you open it.
 
Old 11-11-2011, 12:53 AM   #719
patoperro
LQ Newbie
 
Registered: Oct 2011
Posts: 2

Rep: Reputation: Disabled
keydrive blues

Hey Awesome,

Thanks for the reply. I'm not sure Ubuntu is Linux enough for you (too much pretty GUI), but I did check to make sure the gnu coreutils package is installed (there wouldn't be but one dd, right?). Unfortunately it didn't help. The partitions are still there with same error message as before. I appreciate the suggestion anyway and it's been a learning experience. Wasn't so keen on having an encrypted drive (the original wasn't encrypted either) but it's interesting to learn what it would take to make something truly safe from prying eyes.

pato
 
Old 11-20-2011, 10:59 PM   #720
AwesomeMachine
LQ Guru
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524

Original Poster
Rep: Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015Reputation: 1015
Smile I don't mind Ubuntu . . .

Quote:
Originally Posted by patoperro View Post
Hey Awesome,

Thanks for the reply. I'm not sure Ubuntu is Linux enough for you (too much pretty GUI), but I did check to make sure the gnu coreutils package is installed (there wouldn't be but one dd, right?). Unfortunately it didn't help. The partitions are still there with same error message as before. I appreciate the suggestion anyway and it's been a learning experience. Wasn't so keen on having an encrypted drive (the original wasn't encrypted either) but it's interesting to learn what it would take to make something truly safe from prying eyes.

pato
I just wish Ubuntu would quit calling itself an os and admit it's a bunch of propeller beanie candidates covering Debian with dessert topping.
 
  


Reply

Tags
backup, best, clonezilla, cloning, command, data, dd, disk, drive, duplicate, erase, explanation, formatting, ghost, hard, image, iso, memory, ping, popular, recover, recovery, rescue, search, security, stick, upgrade, usb, wipe



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
Learn The DD command AwesomeMachine Linux - Newbie 17 08-17-2006 04:22 AM
The best way to learn? iz3r Programming 7 02-06-2005 11:00 PM
Best way to learn Linux from the command line patpawlowski Linux - General 2 03-01-2004 03:37 PM
I want to learn C. KptnKrill Programming 14 12-18-2003 01:03 PM
Best way to learn.... InEeDhElPlInUx Linux - Newbie 5 10-11-2003 01:02 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:39 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
Open Source Consulting | Domain Registration