How do I clone a drive and resize (downsize) a partition ? fdisk verify warning.

JD jd1008 at
Fri Jun 25 00:10:51 UTC 2010

On 06/24/2010 04:12 PM, Patrick Bartek was caught red-handed while 
> --- On Thu, 6/24/10, Linuxguy123<linuxguy123 at>  wrote:
>> I'm moving /, /boot and swap from a
>> conventional hard drive to an SSD.
>> Both drives are 160 GB in size.
>> I want to resize the /boot and swap partitions from 200 MB
>> and 2 GB to
>> 500 MB and 8 GB respectively.   The first
>> resize is because preupgrade
>> now fails to run unless /boot is 500 MB or larger and the
>> second because
>> the swap file is supposed to be as big as the RAM in the
>> computer and my
>> laptop currently has 4GB and I want to upgrade to 8 GB in
>> the future.
>> [snip]
>> So how do I move ALL the data from / on the hard drive to /
>> on the sdd ?
>> dd won't work because its for device files, not for
>> partitions.  If I
>> use dd between the devices, it won't resize anything.
> In Linux, "everything's a file." ;-)
> No, dd won't "resize" a partition, but you can use it to copy the filesystem from one partition to another of the same size or larger, then just resize the filesystem using an appropriate tool.  I've done this.  Not that hard at all.
>> Or should I do an outright dd and then use gparted to
>> resize everything
>> afterward ?
> I would dd the filesystem on each partition separately for safety.  Not the whole drive.  Although, what you said above will work.
>> Can one make cp copy EVERYTHING on one drive to another and
>> keep the
>> timestamps, etc, all correct ?
>> [snip]
> I've used cp with the -a "ARCHIVE" switch set, and it worked quite well. The copied files should be exact duplicates of the old.  However, I copied the contents of one partition at a time.  Never tried to do a whole drive all at once.
> B
If you dd partition A on drive 1  to partition B from drive 2, and the 
size of partition B is
LARGER that partition A, then the size of the FILESYSTEM on partition B 
will be identical to size of partition A. In other words, the filesystem 
superblock will retain the info about the size that it occupied on 
partition A - and thus you will  not be able to take advantage of the 
full size of partition B.
If B is bigger than A, then you need to do something different:
Boot any Linux System Rescue CD, and DO NOT ALLOW IT TO MOUNT ANY LINUX 
That is important.
After you have fdisk'ed your partitions on the new drive,
and mkfs'ed the correct filesystems on those partitions:
1. mkdir -p /disk1/part1 /disk1/part2 ...etc
2. mount these partitions. i.e.
    mount /dev/sda1 /disk1/part1; mount /dev/sda2 /disk1/part2
3. mkdir -p /disk2/part1 /disk2/part2 ....etc
4. mount these partitions. i.e.
    mount /dev/sdb1 /disk2/part1; mount /dev/sdb2 /disk2/part2
5. cd /disk1/part1
6. tar cf - . | tar -C /disk2/part1 -xpf -

similarly repeat steps 5 and 6 for part2, part3, ...etc; i.e.
cd /disk1/part2
tar cf - . | tar -C /disk2/part2

As far as swap partitions (I asume you created them on disk 2:
mkswap /dev/sdbX where X is the number of the swap partition.

Good luck

More information about the users mailing list