Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then 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.
I've got an 80GB drive with the following partitions.
Disk /dev/hda: 81.9 GB, 81964302336 bytes
255 heads, 63 sectors/track, 9964 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/hda1 * 1 13 104391 83 Linux
/dev/hda2 14 5112 40957717+ 83 Linux
/dev/hda3 5113 5239 1020127+ 82 Linux swap / Solaris
/dev/hda1 is boot, /dev/hda2 is everything else. This box is used as a CCTV server (using Zoneminder - highly recommended btw), and the images it records are all written to a directory on /dev/hda1. This doesn't cause the disk to fill up because Zoneminder auto deletes when the free space gets below a certain percentage, but I want to move the images to a separate partition and add a much larger disk at the same time.
I think I can copy the existing partitions to a new larger disk using the following (or equivalent - here hda is the existing disk, hdb is the new larger disk - obviously I'll have to boot from a rescue cd to do this):
dd if=/dev/hda of=/dev/hdb
and then add a new partition at the end, but what I really want to do is also resize /dev/hda2 down to about 10Gb (it's currently ~40Gb) to maximise the amount of space available. I'll delete all the image files from /dev/hda2, which should bring the spaced used down to about 7Gb.
I think I can create the partitions on the new disk with the desired size using fdisk and then copy them individually. So /dev/hdb1 would be exactly the same as /dev/hda1, and /dev/hdb2 would be about 10Gb. I could then do
dd if=/dev/hda1 of=/dev/hdb1
which should work fine because the partitions are identically sized, but if I try
dd if=/dev/hda2 of=/dev/hdb2
then this will fail as hda2 is bigger than hdb2. I guess I could add conv=noerror but how do I guarantee that I'll get all the files off hda2. The total space used should be less than the size of the new partition, but is there the possibility that some files might be missed because they're located higher up the partition that the 10Gb point (remember that I've deleted all the images by this point so it's just important files left). Or is ext3 cleverer than this and will move all the files towards the start of the partition when I delete the images files. Or is there a totally different and better way to do this?
You may be making this too complicated.....
First, you talk of deleting files before resizing or cloning....If the stuff you need to keep is not too large, maybe it's better to simply copy the files. (Or are you trying to preserve the OS as well?)
I would back up essential files to some other media (DVD, external USB drive, etc.), install the new harddrive, and re-install the OS and configure.
Quote:
dd if=/dev/hda2 of=/dev/hdb2
then this will fail as hda2 is bigger than hdb2. I guess I could add conv=noerror but how do I guarantee that I'll get all the files off hda2. The total space used should be less than the size of the new partition, but is there the possibility that some files might be missed because they're located higher up the partition that the 10Gb point (remember that I've deleted all the images by this point so it's just important files left). Or is ext3 cleverer than this and will move all the files towards the start of the partition when I delete the images files. Or is there a totally different and better way to do this?
No, ext3 is not that clever, and "conv=noerror" won't make it work. dd is dumber than a post--it happily copies bytes from pt A to pt B until it runs out of room
yeah, i didn't specify that, sorry. i want to copy everything on to the bigger drive and then just boot from that. i don't want to have to go through reinstalling the os and all the apps. i could just dd the entire old drive on to the new drive and add a partition at the end, but i really wanted to reclaim the unused 30GB in the root partition. maybe it's just making it too complicated...
Quote:
Originally Posted by pixellany
No, ext3 is not that clever, and "conv=noerror" won't make it work. dd is dumber than a post--it happily copies bytes from pt A to pt B until it runs out of room
You can certainly re-size any of your partitions--before or after cloning to the new disk. Best way is use something like the GPArted stand-alone bootable CD.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.