LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 02-08-2006, 11:31 AM   #76
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,604

Rep: Reputation: 47

Matir, do you mind elaborating? Say like jinkels I clone a partition, say 1 Go onto 2 Go.
Then I want to use that new clone, calling it part2, and add files to it.
Are you saying one need to use say qtparted, downsize part2 to say 1.5 Go, to make
the filesystem see the real partition size, then increase the partition back to 2 Go?
 
Old 02-08-2006, 11:50 AM   #77
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Let's say I've got an 80GB Hard drive that's starting to get old (call it /dev/hda) and a brand-new 200GB hard drive (call it /dev/hdb). Now, for purposes of illustration, assume each contains a single partition (hda1,hdb1) that occupies the entire hard drive. And, let's say I have an ext3 filesystem with tons of "vital data" on /dev/hda1.

I would do the following:
Code:
# dd if=/dev/hda1 of=/dev/hdb1 bs=4M conv=noerror
Feel free to substitute in your own options for dd. Now, df would report an 80GB filesystem on each partition. Obviously, we'd like the /dev/hdb1 filesystem to occupy the whole 200GB of the partition. That is simple to achieve with resize2fs. Make sure the filesystem is not mounted, and run:
Code:
# resize2fs /dev/hdb1
By default, it will expand the ext[23] filesystem to fill the entire partition on which it is contained.

I hope this clarified things a bit. Similar tools exist for NTFS (ntfsresize) and reiserfs (resize_reiserfs). There are probably tools for a number of other filesystems, but these are the ones I am aware of.
 
Old 02-08-2006, 12:16 PM   #78
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,604

Rep: Reputation: 47
Crystal clear. Many thanks. I am sure it will help most people new to dd.
I did not know resize2fs exact role, it makes sense now.

Just read the man
I guess now resize2fs work in the same way if one clones a 200 GB partition (with only 50 Gb worth of data on it) onto a 80 GB partition. Am I correct?
I know, a odd thing to do, but I think it stems from
the idea that partition schemes are not always great, and if one does some kind
of rescue this situation could happen. Actually I tried for the sake of toying with dd,
but did not know of resize2fs.
 
Old 02-08-2006, 12:24 PM   #79
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Quote:
Originally Posted by Emmanuel_uk
I guess now resize2fs work in the same way if one clones a 200 GB partition (with only 50 Gb worth of data on it) onto a 80 GB partition. Am I correct?
I know, a odd thing to do, but I think it stems from
the idea that partition schemes are not always great, and if one does some kind
of rescue this situation could happen.
In this case, you'd be unable to 'dd' the entire filesystem, so I'd reccomend doing something like this: (hdb1=200GB, hda1=80GB)
Code:
# resize2fs /dev/hdb1 50G
# dd if=/dev/hdb1 of=/dev/hda1
# resize2fs /dev/hda1
This makes the filesystem image small enough to fit in the new partition before copying, then re-expands it to fit the entire partition. It may not be the most efficient scheme ever, but it should work.
 
Old 02-08-2006, 03:13 PM   #80
Emmanuel_uk
Senior Member
 
Registered: Nov 2004
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,604

Rep: Reputation: 47
Great "lateral thinking" that was. I will force myself to add some contribution,
just by mentioning to newbies to consider whether an alternative to cloning
may be more suitable. Tar was mentioned, one can see some views about
mirdir, rsync and mirrordir as well at http://lwn.net/Articles/160850/
"CLI Magic: Simple backup is Mirdir".
Anyway this a bit out of topic. So just saying thanks really.
 
Old 02-08-2006, 11:21 PM   #81
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
I've never personally had a problem with just using cp to make copies of partitions, but rsync, tar, and dd also work well. Realistically, the only time I use dd is when I need to perform a forensic disection (compromised machine, for example). dd preserves data that has been marked deleted but still exists on the drive.
 
Old 02-10-2006, 11:14 AM   #82
r00tNinj4
Member
 
Registered: Jul 2005
Posts: 41

Rep: Reputation: 15
i am trying to zero a drive using dd.

dd if=/dev/zero of=/dev/hda

but it returns with:

dd: writing to `/dev/hda': Input/output error
1+0 records in
0+0 records out
0 bytes transferred in 0.100800 seconds (0 bytes/sec)
 
Old 02-10-2006, 03:27 PM   #83
irongun324
LQ Newbie
 
Registered: Feb 2006
Location: TN/AL
Distribution: Slackware 10.2
Posts: 8

Rep: Reputation: 0
Quote:
Originally Posted by Matir
Let's say I've got an 80GB Hard drive that's starting to get old (call it /dev/hda) and a brand-new 200GB hard drive (call it /dev/hdb). Now, for purposes of illustration, assume each contains a single partition (hda1,hdb1) that occupies the entire hard drive. And, let's say I have an ext3 filesystem with tons of "vital data" on /dev/hda1.

I would do the following:
Code:
# dd if=/dev/hda1 of=/dev/hdb1 bs=4M conv=noerror
Feel free to substitute in your own options for dd. Now, df would report an 80GB filesystem on each partition. Obviously, we'd like the /dev/hdb1 filesystem to occupy the whole 200GB of the partition. That is simple to achieve with resize2fs. Make sure the filesystem is not mounted, and run:
Code:
# resize2fs /dev/hdb1
By default, it will expand the ext[23] filesystem to fill the entire partition on which it is contained.

I hope this clarified things a bit. Similar tools exist for NTFS (ntfsresize) and reiserfs (resize_reiserfs). There are probably tools for a number of other filesystems, but these are the ones I am aware of.
I've read through this whole thread now as well. I have tried using dd before, but was unaware of all the commands that went with and was unsuccessful. My situation is cloning a 2G hard drive to a 6G hard drive. I have been partitioning the hard drives as follows using fdisk:

hda1: +64M
hda2: rest of disk

So if i have my 2G HD (hda) and my 6G HD (hdb) then to make this work I would have to do:

dd if=/dev/hda2 of=/dev/hdb2 bs=4k conv=notrunc,noerror
resize_reiserfs /dev/hdb # I used reisers checking.

and that would give me a working bootable copy of Linux on hdb assuming I made that partition bootable with fdisk?

Also, all of this dd command usage, does this have to be done from a cd boot prompt, or can I clone the partition that im typing the commands from? (doubtful)

Last edited by irongun324; 02-10-2006 at 03:29 PM.
 
Old 02-10-2006, 08:05 PM   #84
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 118Reputation: 118
Quote:
Originally Posted by irongun324
I've read through this whole thread now as well. I have tried using dd before, but was unaware of all the commands that went with and was unsuccessful. My situation is cloning a 2G hard drive to a 6G hard drive. I have been partitioning the hard drives as follows using fdisk:

hda1: +64M
hda2: rest of disk

So if i have my 2G HD (hda) and my 6G HD (hdb) then to make this work I would have to do:

dd if=/dev/hda2 of=/dev/hdb2 bs=4k conv=notrunc,noerror
resize_reiserfs /dev/hdb # I used reisers checking.

and that would give me a working bootable copy of Linux on hdb assuming I made that partition bootable with fdisk?

Also, all of this dd command usage, does this have to be done from a cd boot prompt, or can I clone the partition that im typing the commands from? (doubtful)
First off, doing this on a mounted partition is very dangerous. I would not advise it. Secondly, in order to boot it (assuming you are using lilo or grub) you'll need to update your bootloader. Only DOS's bootloader looks at the "Bootable" flag in the partition table. Thirdly, make sure you provide a partition to resize_reiserfs. For example, resize_reiserfs /dev/hdb2.
 
Old 02-10-2006, 09:16 PM   #85
jlinkels
Senior Member
 
Registered: Oct 2003
Location: Bonaire
Distribution: Debian Wheezy/Jessie/Sid, Linux Mint DE
Posts: 4,246

Rep: Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546Reputation: 546
Almost.

I assume you have been partitioning hdb correctly and that 64M as first partition is enough to hold you boot stuff etc.

Then do:
dd if=/dev/hda1 of=/dev/hdb1 bs=4k conv=notrunc,noerror
to copy the first partition
and
dd if=/dev/hda2 of=/dev/hdb2 bs=4k conv=notrunc,noerror
to copy the second partition.

(You were right here, but might have forgotten to clone the first partition)

Still, the drive is not bootable, because you did not copy the master boot record yet. You can this with:

dd if=/dev/hda of=/dev/hdb bs=446 count=1

Note that you do a copy on a disk and not on a partition. The bs=446 is important because this is exactly the boot sector, without the partition table.

Then, resize both partitions:
resize_reiserfs /dev/hdb1
resize_reiserfs /dev/hdb2

And NOT /dev/hdb!

Don't forget you might want to create a swap partition if you don't have one yet. On the partition you designated as swap, do mkswap to initialize it as swap partition, no need to do this with dd.

And yes, you can do this in a live system.

jlinkels
 
Old 02-11-2006, 10:28 AM   #86
detly
Member
 
Registered: Nov 2003
Distribution: Debian Sarge/Etch
Posts: 54

Rep: Reputation: 15
Quote:
If you're concerned about spies with superconducting quantum-interference detectors you can always add a "for" loop for government level secure disk erasure: copy and paste the following two lines into a text editor.
You'd have to be a real masochist to use a SQuID for data recovery. What you need is an atomic force microscope adapted for magnetometry (aka. a magnetic force microscope), and even that's subjecting yourself to hundreds of hours of pain.

Furthermore, the above method of data destruction will only really be useful for small amounts of data -- it would take far too long to overwrite every bit on your hard drive several times; especially with the Federal Police armed and battering down the reinforced door to your bunker. A better idea would be a giant steel mallet -- with, for the sake of indulgence -- DD embossed on the striking face.
 
Old 02-20-2006, 09:17 AM   #87
luisgui
LQ Newbie
 
Registered: Feb 2006
Location: Mexico City
Distribution: Ubuntu 5.04
Posts: 1

Rep: Reputation: 0
Hello:

AwesomeMachine:

Since you took the time to post this really useful dd document I would only ask you to use boldface, italics and carriage returns to improve readability, which is, in my humble view, the only rather weak point in your long post.

Thank you and please forgive my baldness. Best regards.

Last edited by luisgui; 02-20-2006 at 09:20 AM.
 
Old 02-22-2006, 04:14 AM   #88
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,593

Original Poster
Rep: Reputation: 162Reputation: 162
You were correct

Quote:
Originally Posted by luisgui
Hello:

AwesomeMachine:

Since you took the time to post this really useful dd document I would only ask you to use boldface, italics and carriage returns to improve readability, which is, in my humble view, the only rather weak point in your long post.

Thank you and please forgive my baldness. Best regards.
Thank you for pointing that out. I want people to know I will change the post to make it better for everyone. I hope for more "useful" criticism in the future. I like it with color, bold, and italics a lot better.
 
Old 03-18-2006, 04:50 PM   #89
fdhin
LQ Newbie
 
Registered: Mar 2006
Location: Europe
Posts: 5

Rep: Reputation: 0
no less than 512?

It was stated that bs should be no less than 512, but I am not sure this is true. If you take it as block size I guess it is correct that dd does not handle blocks smaller than 512 byte, but it should do characters and words too:

bs=1c count=1 should copy a single byte or char.
bs=1w count=1 should copy two bytes (a word).

I didn't get around to checking that with a hex editor, but some of the GNU documentation seems to support the claim.
 
Old 03-18-2006, 05:56 PM   #90
AwesomeMachine
Senior Member
 
Registered: Jan 2005
Location: USA and Italy
Distribution: Debian jessie/sid; OpenSuSE; Fedora
Posts: 1,593

Original Poster
Rep: Reputation: 162Reputation: 162
Correct

Quote:
Originally Posted by fdhin
It was stated that bs should be no less than 512, but I am not sure this is true. If you take it as block size I guess it is correct that dd does not handle blocks smaller than 512 byte, but it should do characters and words too:

bs=1c count=1 should copy a single byte or char.
bs=1w count=1 should copy two bytes (a word).

I didn't get around to checking that with a hex editor, but some of the GNU documentation seems to support the claim.
I tried:

dd if=/home/sam/file bs=1c count=1

and dd printed the first character of the file to the terminal. With an "of=" statement this character would go to the specified output.


dd if=/home/sam/file bs=2w count=1

prints the first four bytes of a file.

I will make the correction.
 
  


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


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


All times are GMT -5. The time now is 05:58 PM.

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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration