How to clone drives using DD and GParted

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Today I'm going to go over the method that I use when I clone drives. I use this method when cloning from a slow hard drive to a fast SSD, or changing between drives of different sizes. And I've used this for Linux and Windows boot drives probably over 100 times now, while this process typically will clone drives without any data loss or issues. Data loss can occur and there can be problems with any cloning system, so make sure to make a backup before performing any of these actions to keep your data safe. I like using my method because it gives me a good amount of control and understanding of what's going on under the hood so I don't have software doing something weird that I don't understand. The method I use relies on two pieces of software, DD and G-Parted. DD is a block cloning utility. It's pretty dumb and it just copies blocks from one drive to another. G-Parted can detect partitions on a drive and make changes to those as needed, and it allows for resizing partitions, moving them around on different faces on a disk. When these tools are used together, I can clone almost any drive to any other drive and it'll boot just fine. But before I show a demonstration, I want to explain a little bit about what's going on under the hood here. So you can think of a drive as this rectangle here. At the very beginning is a mat, a partition table that tells you where all the partitions on the drive are located. DD is a relatively dumb utility. It just copies blocks. So if you tell it to clone this drive to a different drive, it takes this whole chunk of data and partitions and moves it to a different drive. This works great if you're moving to a drive of the identical size and you can just be done with that clone and use the new drive. But if you're moving to a larger drive, now there's an unused chunk of data at the end of the drive and you likely want to be able to use that extra space. If you're moving to a smaller drive, now the end part gets chopped off and is unusable, which is going to be a problem because that data is likely going to be needed. And this is where G-Parted comes in. G-Parted is able to manipulate and work with these partitions. So that way the partitions can be shrunken together or pulled apart to be able to work with a smaller drive or a larger drive. If I want to clone from a larger drive to a smaller drive, the first thing I would do is move the partitions into the middle, which typically involves shrinking a partition and maybe moving partitions at the end of the drive. So that way the partitions on the drive are now the same size or smaller than the new drive it is being copied to so I can do a clone with DD now. If I'm moving to a larger drive, I'll take my existing partitions, clone it to the larger drive, and then use G-Parted to move the partitions out to be able to utilize the extra space. When I do all of my cloning, I'm going to be booted from a live USB. This means the drives I'm cloning to and from are not being booted from and that way I can manipulate the partitions as I see fit. Because oftentimes when you are booted from a drive, it limits what you are able to do when it comes to moving partitions and working with the drive. When using this cloning method, it's best to be able to plug the old drive and the new drive into the system at the same time. That way you can easily shrink the partitions, copy the data over and make other partition tables as you see fit. If you can't fit both drives into a system, you can often use a USB adapter to be able to plug one of the drives in over USB and then swap the drive in the single spot in the system. Also, if you need to, you can work with a disk image on a network server or USB drive or some other method, but I'm not going to cover using disk images in this video. Now for my demonstration today, I have a little Dell PC that has a 320 GB hard drive with Windows 11 installed onto it. I also have a 250 GB SSD that I'm going to clone the install onto. The other part I'm going to need is a little USB stick to put my live Linux Dister on that I'm going to use for cloning. In this case, 1 GB or more will be more than plenty. I'm also going to need access to the internet to download a few programs that will let me do the cloning. So let's take a look at this system now. So this menu here looks very similar to what I was showing in my demonstration earlier. So I can see my two drives here, this larger drive here, which has my current installation and my smaller drive I'm going to clone to. And I can see that there's a little bit of empty space here. And this is because the bigger drive has some partitions and data here that won't be able to get cloned over if I do a direct clone. And one thing is, if I try to mess around in the Windows Disk Management, I can't move this partition in. I can only shrink this, which will give me empty space right here, but won't let me move this partition in from the very end of the drive. And that's what G-Parted lets me do that I can't do with Windows Disk Management that's built into Windows. I won't need to touch the disks at all in Windows here though. What I'm going to want to do right now is download some tools to do this for me. So the first thing I'm going to do is I'm going to download the G-Parted ISO. So I can just Google G-Parted and then on the website, if I go on to download, I have a little live USB. I can boot from this little live USB ISO file and then access a very small Linux OS has DD and G-Parted, the two tools I'm going to need. And then I'm also going to download that allows me to take that ISO file and put it onto a USB stick. And now that these programs have finished downloading, I have them in my downloads folder. I'm going to open Bruffis, click yes to allow it to have access to my system. I don't need for it to search for any updates. I'm going to select my ISO file in my downloads folder. Going to open it, going to make sure my USB drive is selected. This will wipe all the data on my USB stick. And then I can leave everything else here by the default. I'm going to get a few images. In all of these cases, I can just select the default of yes and okay. And in a couple of seconds, this drive is going to have the live USB put onto it and I can boot from it in the boot menu. And now Rufus has finished making my USB drive bootable. So I'm going to close the program and go under Windows and click restart. And now when my system is restarting, I'm going to mash the boot menu key. In this case, it's F12 on Dell systems. And I'm going to be presented by a little menu right here that shows me different options. I'm going to select the UEFI option for my USB sticks name. Select enter. In a second or two, I'm going to see the boot menu for the G-parted live USB. And for almost all of these options, I can just press enter to accept the default value and it'll work fine for most uses. And here I am booted into the G-parted live operating system. G-parted here opens by default and I've also opened the terminal to type in some commands to let me do a few other things I might need to do. The first thing I want to do is identify my drives. Linux labels drives as SDA and SDB for most SATA drives like hard drives and SATA SSDs and then NVMe 0 and 1, 1 and 1, 2 and 1 and keeps going on for NVMe drives. Make sure to note and write down what drive you're copying data from and what drive you're copying data to. So in this case, SDA is the drive I'm copying data from and NVMe 0n1 is the drive I'm copying data to. Now this is a 320 gigabyte hard drive and it says 289.09. That's because the gigabyte to gigabyte translation because they use base 10 versus base 2 units. And just be aware that numbers are going to be a bit off because of that. One other way to make sure that your data is correct is I can use sudo smartcontrol -i at the new drive path here and typing that into the terminal will give me information about the drive like the model family and the serial number, which is also going to be written on the drive so you can make sure that your physical drive is the same as that SDA drive you see in the operating system. When I select my SDA drive here, I see a menu that looks relatively similar to what disk management in Windows shows me. I can see my large partition here, which is my C drive and I have a little bit of boot data at the very front and a recovery partition at the end. And what I'm going to need to do first is I'm going to need to shrink everything down so that way I have extra space at the end. So when I do a block level copy of this drive to the smaller drive, no data is lost at the end of the drive. And because of that conversion between gigabytes and gibibytes, I like to be safe and be able to shrink it in a little bit more than I have to and then expand it more at the end. So that way I don't have to get these numbers perfect. So what I'm going to do is I'm going to select this large partition, which is my C drive and I'm going to shrink it. File systems like NTFS support being able to shrink it and G-Parted works with those file systems so that they know that they're being shrunk. You can't just shrink a partition with a file system in it without telling the file system because otherwise the file system will have data that it thinks it should have been able to access. That is gone now. So G-Parted will be able to do that. So I'm going to select under partition and then resize/move. And then here under the size one, I'm just going to change that to 220. And because of the changes between gigabytes and gibibytes, when I shrink it down, I'm going to have 82 gigabytes of free space. And then now I'm going to select the small recovery partition at the end of the drive. And I'm going to say partition, resize/move, change the free space proceeding to zero, which means there's no space between that C partition and this recovery partition now and click resize/move. And it says it's going to cause some issues because this might be a needed partition. I've done this plenty of times, but make sure you have a backup. So now I'm going to double check looking at this. I see I have an unallocated part at the end of the drive. I have nothing here at the other than the unallocated at the end of the drive. And this unallocated space is larger than the difference between these drives. So when I copy from the larger drive to the smaller drive, the data being lost is going to have nothing on it. So there will be no data lost. Once the drive is in this state, I'm going to click the little checkmark, which actually writes these changes to disk. And I'm going to click apply, and then it's going to shrink that NTFS file system with this NTFS resize tool. And then in a second or two, it's going to start moving that small partition over. Now I'm going to use DD. This is the tool that's going to copy the partitions and block data from one drive to the other. So the command I'm going to be using is sudo to run it with the full permissions to be able to copy it between drives. DD is the utility. if is the input file. So that's going to be the drive you are copying data from /dev/sda in this case. of is the output file that you're going to be copying data to. So in this case, /dev/nvme0n1. bs is going to be block size. This is not needed, but I'm doing it because it makes it faster. 1m is going to be 1 million. So this means instead of copying lots of little partitions and chunks of data, I'm going to copy one big one. So it just makes it faster. It does not affect the way that the data is being copied at all in this case. And then I'm going to also type status equals progress because I like to see a progress bar. Again, this option here makes no difference to the actual data copying and just shows me this little progress menu right here instead of showing me nothing. And now my DD clone is finished. And if I look at my system here, it says it's copied 256 gigabytes. And it also says there's no space on device. And that's because I'm copying from a bigger drive to a smaller drive. And now I can go into Gparted to move the partitions around so I can take full use of that 256 gigabyte drive. But when opening Gparted, I get this error right here of invalid argument for seek on this drive. And I'm going to hit cancel here and Gparted is going to close. And what's happening here is GUID partition tables, which is what UEFI booted systems use, which is most new systems from within about the last 10 years or so, has another backup partition table at the end of the drive. And when it's reading it, it's going to read the end of the drive, but that's at the end of the drive on the old drive, which is not copied to the new drive. So it's complaining. Now the data is on there. There's still the main primary copy, but lots of things look for the backup copy. If I was to boot this drive, it will boot into Windows successfully right now, but lots of Linux programs don't like that. Luckily, there is a way to fix that with Gdisc. So I'm going to do sudo gdisc /dev/nvme0n1. And Gdisc also detects that I have a damaged GPT. So what I'm going to do is I'm going to hit X for expert mode. And then if I want to hit question mark for help, this E option right here, reallocate backup data structures at the end of the disk, I'm going to hit E right now. And what it's going to do is it's going to reallocate the data. So essentially it's copying the primary partition table at the front of the drive to the end of the drive. So now it has a valid backup. Then I'm going to hit W to write the data. It's going to say I can mess stuff up because I am writing partition tables. I'm going to hit Y right now. It's going to write some new data. And if I run LSBOK, it sees it successfully. And if I go relaunch gpart, it will successfully see all the partitions on the drive now. And this partition table is going to look almost identical to what my hard drive has, but it has a little bit less space because it's a smaller drive. So I'm going to do a very similar action as what I did before by going to each of these partitions, saying resize and move. Free space following, set that to zero, which will make it so it's at the end of the drive now. And then for my big partition, which is the C drive in Windows, I'm going to go to resize/move again. And I'm going to change this new size number to what the maximum size number is above. And then when I hit enter, there's no space in front of the partition, no space at the end of the partition. If I hit resize/move, there's going to be essentially no unallocated space on the drive. And it's going to fully use my 256 gigabyte drive. I'm going to hit the little check to apply it right now. And it's going to copy a little bit of data around on the SSD and run the NTFS resize to use up all the space it can. I'm going to hit close. I'm finished with my clone right now. So I'm going to shut down from my Linux Live USB and boot back into Windows. And this is the hard drive that used to boot the system. Windows 11 is a whole lot faster thanks to me having an SSD in it now. And if I go look at disk management right now, I see essentially the same image that I saw earlier with my 618 megabyte recovery partition at the end of the drive and the C drive using as much space as possible. So now my system is booted from the SSD and has no other issues and is a correctly working Windows installation. Hopefully this video was useful for you and gives you a little bit of ideas of what's going on under the hood when it comes to disk cloning and partition tables. Let me know if you have any other ideas for videos in the comments below and thanks for watching.
Info
Channel: ElectronicsWizardry
Views: 2,919
Rating: undefined out of 5
Keywords:
Id: YmFuBiKtes0
Channel Id: undefined
Length: 14min 9sec (849 seconds)
Published: Sun May 14 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.