I just did this today for a virtual machine that needed more storage.
Originally Posted by rewyllys
It is pretty simple to swap in a new, larger HDD using gparted. This assumes the OLD HDD will be repurposed.
* Always create a 100% backup before attempting any partition-related work. This is dangerous stuff.
* If you do not understand partition names, STOP. Getting these incorrect WILL destroy data. The partition names for YOUR system may or may not be the same as used below. It is highly unlikely that sdb is really the correct NEW HDD name on every system. You have been warned.
* Connect both HDDs, NEW and OLD, to the system
* Boot off a gparted ISO/boot disk
* Create a new partition table as needed (GPT for 2TB and larger HDDs)
* Create partitions on the NEW HDD of the sizes you'd like - match the partition names on the OLD HDD.
** sda1 --> sdb1
** sda2 --> sdb2
* For each partition
** right click on the sda (OLD HDD) partition, select "copy"
** change to the sdb (NEW HDD) partition of the matching name, and select "paste".
** move on to the next partition, in order, until done
* Click "Apply"
* Wait for the data to be copied over. This can take 1 minute or 10 days or anywhere between depending on the CPU, backplane, RAM, disk controllers, HDD performance .... USB will be slower than eSATA or SATA connected HDDs.
* Remove the OLD HDD from the connection, probably swap the SATA cables to ensure the same SATA port is used for the NEW HDD (if you use UUIDs to mount partitions, this is not needed)
* Remove the gparted ISO/boot disk
* Reboot the system
These steps do not account for everything. There are shorter ways to accomplish the same things, if you know what you are doing with gdisk, sfdisk, and the partitioning header (MBR/GPT) are the same between the HDDs.
There are situations where these instructions do not work.
***** Caution - If MS-Windows is involved, a UEFI partition will be necessary if GPT is used on the NEW HDD and that will probably break the order of partitions. Trying to use UEFI on hardware that does NOT support UEFI will not work. A recovery disk will be necessary if any hope of this working for Windows.
Use of sfdisk and fdisk for many versions of Linux DO NOT SUPPORT GPT partitioned HDDs. This is why gdisk, parted and gparted are required. Eventually, a corrected version of fdisk that works with GPT will be the default. Unless you are certain of this support on YOUR system, use parted, gparted for all partitioning work. Both of these tools also automatically address 512b and 4Kb alignment concerns too. Not honoring the suggested alignment for 4K-sector HDDs can cause 50% performance degradation.
For MBR partitioned HDDs and less than 2TB HDDs, it is easy to clone the MBR partition table from sda to sdb:
As root, run:
If you just want to mirror everything from sda to sdb, including the partition table, then boot off any liveCD/USB and run as root:
# sfdisk -d /dev/sda | sfdisk /dev/sdb
If the in/out counts do not match, there is an error so ddrescue should be used instead of plain dd. Check the ddrescue man page for detailed options.
dd if=/dev/sda of=/dev/sdb bs=1024000
After the entire disk is cloned, you can use parted or gparted to resize most of the partitions. I've had issues with extended partition resizing - basically it would not let me under any situation, which is why the instructions at the top have a manual step to create the partitions you like. If the extended partition has extra space, resizing logical partitions _inside_ should not be a problem. That is one way that GPT partitioning is better than MBR, no more extended or logical partitions. There are others ways too.