• Welcome to Overclockers Forums! Join us to reply in threads, receive reduced ads, and to customize your site experience!

how to make a drive image.

Overclockers is supported by our readers. When you click a link to make a purchase, we may earn a commission. Learn More.

gsrcrxsi

Member
Joined
Feb 21, 2008
Location
Baltimore, MD
ok, so i want to migrate my OS to another drive, but i dont want to reinstall everything. mainly because its a pain and i have so many things installed and it configured all correctly and i dont want to have to do it again. so my question is, is there a program that i can use to take a drive image, and i can just write that to another drive, and then just boot everything up like normal. the drive sizes will be different also.

this is an Xubunu variant (mythbuntu)
 
Use with caution, be sure you get your paths correct or you could over write good data.

Code:
dd if=/dev/sda1 of=/dev/sdb1

This will copy everything from partition 1 of drive 1 to partition 1 of drive 2. Change the paths as needed. You may need to set back up grub to reflect the new paths. The partition you are copying to will need to be the same size or larger than the original one. If it is larger then you will need to run a utility to expand the file system otherwise the drive will still be reported at the smaller size.
 
can i use gparted to expand it? what about the swap partition? and i assume this requires me to partition and format the drive BEFORE copying?
 
Last edited:
I just cp -ax everything from one partition to the other. Linux is fine with that. Then you have to reinstall the boot loader (or use dd to copy it). It's not like Windows where you have to install files in certain physical places on the hard drive etc.
 
so using the method in post #2 will work?

again what about the swap partition? will i have to manually create it before hand? how would i create that with no OS before hand?
 
so using the method in post #2 will work?

again what about the swap partition? will i have to manually create it before hand? how would i create that with no OS before hand?

Swap partitions can be made at anytime, they are not tied to the OS. The OS finds them on boot and uses what it finds. I'm pretty sure the last time I had to expand a file system I used GParted (possibly QTParted) it worked fine.

You will need to partition the new drive in the way you want it, with Gparted you can setup your swap partition at that time as well. There is no need to format the partition you are copying to since dd will copy everything from the other drive's partition, file system and all. If the drive is new I would highly recommend some stress testing first which possibly should include some sort of low level format across the entire drive.

This boot disk should just about cover all your testing needs and tell you if the drive is in any way defective. Some of the tests may be destructive to the data on the drive so be careful, it doesn't really give much information about what each test does. I have only used this boot disk on blank drives and drives so defective no data could be salvaged in the first place.

Another method is a few nice dd commands

This will write random data to the entire drive (CHANGE THE DRIVE LOCATION FOR YOUR SYSTEM!!!! Data WILL be lost on the "of" location!!!)
Code:
sudo dd if=/dev/urandom of=/dev/sdb

This will do the same as above but write all zeros to the drive.
Code:
sudo dd if=/dev/zero of=/dev/sdb

If either of them fail then you have a problem with the drive. No output will be given while the utility runs but you will see steady drive activity. This will take a few hours depending on the size and speed of the drive. Output will finally be given once dd reaches the end of the disk or cannot write to a part of the disk.
 
well i only plan to migrate data to a brand new drive, i only use WD, and ive never had a new one be DOA. but in either case, i have plently of HDD diag tools at my disposal. i just want to move everything from a 320GB (installed apps and everything intact) IDE drive, to a 500+ GB SATA drive. i want to combine my 2 separate linux & windows drives onto a single drive for space reasons (and a cleaner case without the IDE ribbons) for a total of 4 SATA drives. 1 for OS's, 2x 1TB for data storage, and 1 SATA DVD drive.
 
you will probably have to modify grub.conf or menu.lst (whatever your distro uses) if you are going to be putting them on the same hard drive.
 
yea i know that, but i just dont want to reinstall everything. editing a few configs is no big deal.

oh and a few other things. does the partition im making a copy of have to be unmounted? like i cant make a copy of the OS while its running right? or can i do it from within the OS? and can i use that same code (the dd one) to copy my windows partition? or will it not work for windows?
 
Last edited:
the short answers to your questions are:
yes you can do it while your OS is live, no issues there and yes you can do it to the windows OS.

HOWEVER, it is a great deal more complicated to do a windows migration with DD then it is to do a linux migration with DD
 
It's rarely worth it to do a Linux hard drive copy with dd. dd copies every bit... even the garbage bits on the disk that are unused. It's very low level. Using cp is much faster, and works fine, as long as you take 2 minutes to set up partitions (and you can pick new sizes too, as long as they are big enough to hold what you are copying to them). For backup, you can just create a tarball and pipe it through gzip or bzip2... that way you aren't copying the empty parts of the disk, so it's much smaller. (Using /dev/zero on the empty part of the drive can cut down on the size of the image when compressed, but also takes a long time.)
 
It's rarely worth it to do a Linux hard drive copy with dd. dd copies every bit... even the garbage bits on the disk that are unused. It's very low level. Using cp is much faster, and works fine, as long as you take 2 minutes to set up partitions (and you can pick new sizes too, as long as they are big enough to hold what you are copying to them). For backup, you can just create a tarball and pipe it through gzip or bzip2... that way you aren't copying the empty parts of the disk, so it's much smaller. (Using /dev/zero on the empty part of the drive can cut down on the size of the image when compressed, but also takes a long time.)


not very often that i disagree with you, however, if you resize your root partition before taking the image, DD the /boot image, then DD the root

on the receiving system after you DD the boot image, mount the root partition into a temp directory, DD the root file and your done,

works better this way for mass deployment
 
Well, I wasn't really considering mass deployment, but I suppose it saves a few steps. Even so, I think I'd just write a quick 5 minute script to partition and format the drive before unpacking the tarball for a mass deployment.

Also, all that resizing of partitions is both risky and time consuming, and then you have to undo it to get the rest of your space usable again.

If I were to use dd, I'd /dev/zero out the unused space. Then it compresses to like nothing.

EDIT: dd would, however, be very useful for copying over the MBR and partition tables automatically in a mass deployment...
 
IMO a fresh install would be good.
Than again I fresh install Linux every few months. NOt because it rotted (like my windows box) but because i'm trying a new distro. It also keeps me from collecting too much junk.
 
I don't do a lot of new distro experimentation now. I love Gentoo and stick with it.

I also keep my Gentoo install very healthy with full daily updates of world, pruning, depcleans, security checking, revdep-rebuilding, etc. It's all automated. Gentoo gets ugly if you don't care for it regularly (this is not a Linux thing, but a Gentoo thing). Feed it daily and it will live forever.
 
im pretty good with linux, still learning, but i really dont know wtf you guys are talking about anymore lol. i just want a simple way to migrate everything (programs, files, and settings intact) so i can load up with the new drive without doing anything and it just works.

will dd do that or not?
 
Only if the drives are identical in size. It can clone from one to another, but you can't really clone a 40gb to a 200gb with it.

Here is what I'd do:

1) put both drives in one computer, with the new drive in the same location it will be when running the system (e.g. primary master probably on IDE, first SATA on SATA... doesn't really matter, but changing it later will screw things up)
2) load up a live cd (gentoo minimal, knoppix, whatever you like, it doesn't matter)
3) partition the new drive as desired, with partitions going in the same order as on the original drive
4) format the new partitions on the new drive (mke2fs -j makes an ext3, mkswap makes a swap, etc.)
5) mount the old drive read only and the new drive read write (all data partitions, swap not important)
6) for each partition, cp -axv /old/drive/mount/point/* /new/drive/mount/point
7) mount /proc and /dev (mount -o bind /dev /new/drive's/dev/location, mount -t none /proc /new/drive's/proc/location)
8) chroot to the new drive (chroot /mnt/new/drive)
9) run grub-install /dev/new/drive/device/name

That should do it.
 
Back