What is the procedure for cloning a boot HD?

DxHum

Member
Joined
Jun 2, 2024
Messages
56
Reaction score
21
Credits
466
Currently, I have a 234GB SSD hard drive that is the boot drive on my Ubuntu system. The system will sometimes crap out and it is necessary to shut down the system and reboot.

After the reboot, I need to run the fsck command to correct errors. Then the system will boot normally and work for a week or so before it happens again.

I also have a 1 TB SSD that functions fine and is used as a data drive. But I've move this data to an external raid drive so that I can clone the 234GB drive to the 1TB drive. Then I can pull the failing drive from the machine.

I'd rather not pull the drives and use cloning hardware. I imagine that there is a command line I can issue in terminal to do the same thing.

So, is there a command I can issue to clone the bootable drive while it is in the box, or must I pull it?

Thank you,
DX
 


Several methods open to you, if using a drive bigger than the one to be cloned, I suggest you make a new partition on it first at the beginning of the drive the same size as the current one.

see
 
You can't clone a drive you are booted from. You will need to boot from a live USB drive.
It really doesn't matter which distro. It doesn't have to be the same one you are cloning.

Open a command line console.

fdisk -l

That will show you which disks are which.
Your OS disk might be /dev/sdb and your 1TB drive might be /dev/sdc, most likely your USB drive will be /dev/sda.
But you never know until you take a look.

Once you know which is the source drive, and which is the destination drive.

dd if=/dev/sdX of=/dev/sdY status=progress

change the X and the Y above to the correct devices. ( i.e. /dev/sda and /dev/sdb or example )

If you accidently type in the wrong one, there is no recovery option.

The main disadvantage to doing this, is now your 1TB drive, will effectively become a 234 GB drive.
You usually clone to a similar size drive.

Note: This will not work for partitions, it MUST be the entire disk.
For example if this is a dual boot system with an OS on /dev/sda1 and another OS on /dev/sda2
it probably will not work. You have to use the entire /dev/sdX

(There are a couple of Linux distro's that get around this to a point)

No need to worry about pre-formatting the destination disk. dd is going to overwrite
whatever is there.
 
Last edited:
The main disadvantage to doing this, is now your 1TB drive, will effectively become a 234 GB drive.
You usually clone to a similar size drive.


My idea was to create a backup and then restore it to the larger drive. Then I would expand the partition to the full capacity of the new drive.
 
My idea was to create a backup and then restore it to the larger drive. Then I would expand the partition to the full capacity of the new drive.

You would need a 3rd drive, the same size as your original drive ( or larger)

dd if=/dev/sdX of=/path/on/a/large/disk/my_original_os.iso


This will probably be close to 234GB, maybe 1 or 2 GB larger in your case.
After this is done. Then...

dd if=/path/to/my_original_os.iso of=/dev/sdX

Where /dev/sdX is the new drive you want to install to.

Part of the problem here is... the original partition table is set to a specific disk size.
Your target disk might be 2TB, but partition table you are copying is 234GB.

You can resize this without deleting the existing data, but you can't add another partition
until you do this.
 
Currently, I have a 234GB SSD hard drive that is the boot drive on my Ubuntu system. The system will sometimes crap out and it is necessary to shut down the system and reboot.

After the reboot, I need to run the fsck command to correct errors. Then the system will boot normally and work for a week or so before it happens again.

I also have a 1 TB SSD that functions fine and is used as a data drive. But I've move this data to an external raid drive so that I can clone the 234GB drive to the 1TB drive. Then I can pull the failing drive from the machine.

I'd rather not pull the drives and use cloning hardware. I imagine that there is a command line I can issue in terminal to do the same thing.

So, is there a command I can issue to clone the bootable drive while it is in the box, or must I pull it?

Thank you,
DX
Cloning is not the only option in this situation, nor even necessarily the most optimal.

A back up of data, and then a new installation would avoid the issues of size mismatches, and have the benefit of an upgraded operating system if you install the latest version.

A new installation also offers the opportunity to adjust partition sizes to the new larger disk which would likely make the system more efficient and functional than imposing the limitations present in the smaller disk that is proposed to be cloned. YMMV.
 
A back up of data, and then a new installation would avoid the issues of size mismatches, and have the benefit of an upgraded operating system if you install the latest version.
That....is the way to go. A bit more work, but a brilliant outcome
 
Cloning is not the only option in this situation, nor even necessarily the most optimal.

A back up of data, and then a new installation would avoid the issues of size mismatches, and have the benefit of an upgraded operating system if you install the latest version.

A new installation also offers the opportunity to adjust partition sizes to the new larger disk which would likely make the system more efficient and functional than imposing the limitations present in the smaller disk that is proposed to be cloned. YMMV.
I considered doing a fresh install, as I have a backup on my RAID.

So I would pull the defective drive, then make the 1 TB the primary and install.

But how am I restoring data without over-writing the new install?
 
But how am I restoring data without over-writing the new install?

Do you have a third drive large enough to hold the data?
 
Currently, I have a 234GB SSD hard drive that is the boot drive on my Ubuntu system. The system will sometimes crap out and it is necessary to shut down the system and reboot.

After the reboot, I need to run the fsck command to correct errors. Then the system will boot normally and work for a week or so before it happens again.

I also have a 1 TB SSD that functions fine and is used as a data drive. But I've move this data to an external raid drive so that I can clone the 234GB drive to the 1TB drive. Then I can pull the failing drive from the machine.

I'd rather not pull the drives and use cloning hardware. I imagine that there is a command line I can issue in terminal to do the same thing.

So, is there a command I can issue to clone the bootable drive while it is in the box, or must I pull it?

Thank you,
DX
I kept having problems like this with my hard drive. Make sure not to connect your drive to a USB hub. Try to put it on its own bus. I put my hard drive on a separate bus, that is only shared with my UPS, and this problem stopped. I was getting a log of driver errors before I did this.

Signed,

Matthew Campbell
 
You can't clone a drive you are booted from. You will need to boot from a live USB drive.
It really doesn't matter which distro. It doesn't have to be the same one you are cloning.

Open a command line console.

fdisk -l

That will show you which disks are which.
Your OS disk might be /dev/sdb and your 1TB drive might be /dev/sdc, most likely your USB drive will be /dev/sda.
But you never know until you take a look.

Once you know which is the source drive, and which is the destination drive.

dd if=/dev/sdX of=/dev/sdY status=progress

change the X and the Y above to the correct devices. ( i.e. /dev/sda and /dev/sdb or example )

If you accidently type in the wrong one, there is no recovery option.

The main disadvantage to doing this, is now your 1TB drive, will effectively become a 234 GB drive.
You usually clone to a similar size drive.

Note: This will not work for partitions, it MUST be the entire disk.
For example if this is a dual boot system with an OS on /dev/sda1 and another OS on /dev/sda2
it probably will not work. You have to use the entire /dev/sdX

(There are a couple of Linux distro's that get around this to a point)

No need to worry about pre-formatting the destination disk. dd is going to overwrite
whatever is there.
I have cloned flash drives before and it works. You can clone a whole drive or just a partition. Just tell /usr/bin/dd what you want it to do. You can use /usr/bin/df to see which drive partitions are mounted. That fdisk -l works great too. You might specify a block size using something like bs=4M with dd to speed things up a bit. If you clone a partition you will need to define it in the partition table on the target drive first. Personally I think copying the drive with cp -prv would work wonders. It's just a matter of setting up the bootable aspects of it after that.

Signed,

Matthew Campbell
 
My idea was to create a backup and then restore it to the larger drive. Then I would expand the partition to the full capacity of the new drive.
See /usr/bin/cp -prv or /usr/bin/tar.

Signed,

Matthew Campbell
 
you can even do this over the network
On the source machine
Code:
tar zcf - /* | nc $IP 4444
On the destination machine
Code:
 nc -lp 4444 > backup.tar.gz

or use SSH
Code:
dd if=/dev/sdX | ssh user@remotehost "dd of=/home/user/ops-tools.img"
 
You can clone a whole drive or just a partition.

True, but it won't boot. Also if they're using LVM, they can't see the data.
 
Last edited:

Then I would copy all my important stuff to that drive.
Re-install the OS ( or a newer version ) to your 1TB drive.
Copy everything important back to the new OS drive.
 
Then I would copy all my important stuff to that drive.
Re-install the OS ( or a newer version ) to your 1TB drive.
Copy everything important back to the new OS drive.

I think this is probably the best path considering my Linus skill level.
 

Members online


Latest posts

Top