Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
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?
Click here to see the post LQ members have rated as the most helpful post in this thread.
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.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
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.
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)
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.
Distribution: Mandriva mostly, vector 5.1, tried many.Suse gone from HD because bad Novell/Zinblows agreement
Posts: 1,606
Rep:
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.
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.
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 02:29 PM.
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.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
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.
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.
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.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
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.
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.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Original Poster
Rep:
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.