Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

Clone an SSD drive.

New to Debian (Or Linux in general)? Ask your questions here!
Message
Author
hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Clone an SSD drive.

#1 Post by hack3rcon »

Hello,
I have an SSD drive that a special Operating System installed on it and has some partitions with different sizes. I want to clone it on another SSD. Is below command enough?

Code: Select all

# dd if=/dev/XXX of=/home/jason/SSD.dd
This command will clone all parts of SSD like Boot partition and...?

Thank you.

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Clone an SSD drive.

#2 Post by RU55EL »


mm3100
Posts: 336
Joined: 2020-10-21 21:39
Has thanked: 8 times
Been thanked: 13 times

Re: Clone an SSD drive.

#3 Post by mm3100 »

Yes I think that command of yours will do what you want, just be careful of UUID, since dd will copy those as well.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Clone an SSD drive.

#4 Post by p.H »

hack3rcon wrote:I have an SSD drive that a special Operating System installed on it and has some partitions with different sizes. I want to clone it on another SSD. Is below command enough?
No. The command does not clone a drive on another, it only creates an image file from the source drive. You must also write the image to the destination drive.

Also note that :
- If the destination drive is smaller than the source drive, it won't work.
- If the destination drive is bigger than the source drive and the partition scheme is GPT, the available size recorded in the GPT header on the destination drive will be wrong and the backup partition table which is expected to be located at the end of the drive will be at the wrong location unless you run some partitioning tool to fix the partition table.
- dd copies all blocks, used and unused. It is a waste of time and wears the destination. Also, unused copied blocks will be uselessly marked "in use" by the destination SSD unless you run fstrim on each filesystem afterwards. Depending on the partition scheme and filesystem type, clonezilla may be able to copy only used blocks.
- The operating system may not be happy to be moved to another drive without notice. For instance, the Debian package grub-pc (for BIOS boot) records the physical identifier /dev/disk/by-id/xxx of the drive the boot loader was installed to, so that it can reinstall it in the same location after an update.

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Clone an SSD drive.

#5 Post by CwF »

search !
...and the answer is qemu-img.
I've typed it already.

Bulkley
Posts: 6383
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: Clone an SSD drive.

#6 Post by Bulkley »

+1.

Islander
Posts: 42
Joined: 2020-10-20 08:29
Has thanked: 16 times
Been thanked: 1 time

Re: Clone an SSD drive.

#7 Post by Islander »

gnome-disks has a Create/Restore Disk Image function. Will that work as well?

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Re: Clone an SSD drive.

#8 Post by hack3rcon »

p.H wrote:
hack3rcon wrote:I have an SSD drive that a special Operating System installed on it and has some partitions with different sizes. I want to clone it on another SSD. Is below command enough?
No. The command does not clone a drive on another, it only creates an image file from the source drive. You must also write the image to the destination drive.

Also note that :
- If the destination drive is smaller than the source drive, it won't work.
- If the destination drive is bigger than the source drive and the partition scheme is GPT, the available size recorded in the GPT header on the destination drive will be wrong and the backup partition table which is expected to be located at the end of the drive will be at the wrong location unless you run some partitioning tool to fix the partition table.
- dd copies all blocks, used and unused. It is a waste of time and wears the destination. Also, unused copied blocks will be uselessly marked "in use" by the destination SSD unless you run fstrim on each filesystem afterwards. Depending on the partition scheme and filesystem type, clonezilla may be able to copy only used blocks.
- The operating system may not be happy to be moved to another drive without notice. For instance, the Debian package grub-pc (for BIOS boot) records the physical identifier /dev/disk/by-id/xxx of the drive the boot loader was installed to, so that it can reinstall it in the same location after an update.
Thank you so much for your useful information. I have some questions:
1- If the destination drive is bigger than the source drive then what should I do?
2- How about "fstrim" ?
3- "The operating system may not be happy to be moved to another drive without notice.", then what are the options?

If possible, please show me the commands that I must use.

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Re: Clone an SSD drive.

#9 Post by hack3rcon »

mm3100 wrote:Yes I think that command of yours will do what you want, just be careful of UUID, since dd will copy those as well.
What should I do about UUID?

mm3100
Posts: 336
Joined: 2020-10-21 21:39
Has thanked: 8 times
Been thanked: 13 times

Re: Clone an SSD drive.

#10 Post by mm3100 »

It is not wise to have two mounted filesystems with same UUIDs, if you dd from one drive directly to another one dd will copy UUID of those filesystems on partitions too, so you would need to change that if you want to use both drives at the same time. You should be able to change UUID without reformatting partitions using gparted, not sure if kde parititon manager can do that too. Just make sure filesystem is not mounted while doing so.

p.H
Global Moderator
Global Moderator
Posts: 3049
Joined: 2017-09-17 07:12
Has thanked: 5 times
Been thanked: 132 times

Re: Clone an SSD drive.

#11 Post by p.H »

hack3rcon wrote:1- If the destination drive is bigger than the source drive then what should I do?
I already replied to this question in my previous post.
hack3rcon wrote:2- How about "fstrim" ?
Can you elaborate ?
fstrim sends discards for all mounted filesystems. It will do the same on another SSD.
hack3rcon wrote:3- "The operating system may not be happy to be moved to another drive without notice.", then what are the options?
Change the drive identification in relevant configurations. The only one I know in Debian is grub-pc debconf configuration, so you would juste have to run

Code: Select all

dpkg-reconfigure grub-pc
after removing the old SSD and booting the new SSD.
hack3rcon wrote:What should I do about UUID?
Nothing if you are not going to use both drives in the same machine at the same time.

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: Clone an SSD drive.

#12 Post by bester69 »

hack3rcon wrote:Hello,
I have an SSD drive that a special Operating System installed on it and has some partitions with different sizes. I want to clone it on another SSD. Is below command enough?

Code: Select all

# dd if=/dev/XXX of=/home/jason/SSD.dd
This command will clone all parts of SSD like Boot partition and...?

Thank you.
This! >> GPARTED COPY/PASTE

Dude, Im not an expert, but i think clonning whole disk is a very bad idea...Im not sure, cos Ive never done like that but sounds very bad... you clone idividual partitions better, so that , you can later work with them and adjust sizes and postitions... Its very easy to do with gparted, just copy and paste like with clipboard... you just need to use a livecd to have all partitions unmounted... I clonned my HDD to SSD and gparted keep UUID and let you resize once copied partition to target...
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

vmclark
Posts: 187
Joined: 2008-07-30 15:16
Has thanked: 1 time

Re: Clone an SSD drive.

#13 Post by vmclark »

@hack3rcon

copy and paste the output of

Code: Select all

lsblk -f
so we can see what special partitions your talking about. Clonezilla or fsarchiver is what I use.

Bulkley
Posts: 6383
Joined: 2006-02-11 18:35
Has thanked: 2 times
Been thanked: 39 times

Re: Clone an SSD drive.

#14 Post by Bulkley »

Yesterday I got a new SSD drive. I booted up my trusty old Clonzilla live-CD and in less than 30 minutes I'm running my system on the new drive. :D

CwF
Global Moderator
Global Moderator
Posts: 2636
Joined: 2018-06-20 15:16
Location: Colorado
Has thanked: 41 times
Been thanked: 192 times

Re: Clone an SSD drive.

#15 Post by CwF »

bester69 wrote: i think clonning whole disk is a very bad idea.
It's a very good idea. A bad idea is to mix purpose on a device and complicate it's archival. If you have 100GB of crap mixed in your OS it would be silly to try and image the whole disk, so think ahead maybe. I image to and fro on device and as a file on a regular basis. An OS archives to a few GB's, you can keep that on the simplest phone or usb, or a master spinning rust. I do windows too, for Debian only a single master image is needed for each architecture. UUID's, PTUUID's, domains, users are changeable. A few dozen OS's can be quickly unique-ified at will. User skel's can be zipped and applied to fresh OS copies. User data bought in from separate image files and devices.

Something needed a parallel OS savior just the other week, I just wrote out from tempfs the current bullseye to a ssd and popped it it in. The incomplete system boot up fine straight into a recovery user desktop, with some craziness, but with a working root terminal. Fix at hand, working network, done. All from a 1.7GB image, installed 4 years ago as a Jessie vm on a machine long gone.

Imaging the whole drive works very well. There are a few extra things to know, but it's all doable. I've learned the hard way, no clonezilla for me. By now, my way is way easier.

User avatar
sunrat
Administrator
Administrator
Posts: 6412
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 116 times
Been thanked: 462 times

Re: Clone an SSD drive.

#16 Post by sunrat »

CwF wrote:
bester69 wrote: i think clonning whole disk is a very bad idea.
It's a very good idea. A bad idea is to mix purpose on a device and complicate it's archival. If you have 100GB of crap mixed in your OS it would be silly to try and image the whole disk, so think ahead maybe.
Totally agree and that's why I use a separate partition for all my data instead of dumping it all in /home . Restores or new distro installs are a piece of cake. My largest OS image using fsarchiver is ~6GB.
On a side note, some people use and even advise to share a /home partition in multiboot but that's crazy IMO. Have /home inside root partition and separate /data partition/s ftw.
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Clone an SSD drive.

#17 Post by RU55EL »

About six months or so ago, I got a new 1 TB SSD to replace the 256 GB SSD in my work computer. The computer is dual boot, Debian and Windows. [Using Clonezilla] Took about an hour to copy all the files, swapped the drives, and boom, computer worked exactly as before except the SSD was much bigger.
Last edited by RU55EL on 2020-11-27 13:10, edited 1 time in total.

User avatar
RU55EL
Posts: 546
Joined: 2014-04-07 03:42
Location: /home/russel

Re: Clone an SSD drive.

#18 Post by RU55EL »

sunrat wrote: [...] that's why I use a separate partition for all my data instead of dumping it all in /home . Restores or new distro installs are a piece of cake. [...]
When I initially install Debian, I create /home in a separate partition (sometimes a separate drive.) That makes backups, restores or new Distro installs a piece of cake. I love performing a fresh install without formatting the /home partition, using my old /home partition, and having my setting and data preserved. (Of course, I create a backup first.) A clean install of Debian, say from Stretch to Buster, takes about 15 to 20 minutes, on a computer that isn't too old, using an SSD.

User avatar
bester69
Posts: 2072
Joined: 2015-04-02 13:15
Has thanked: 24 times
Been thanked: 14 times

Re: Clone an SSD drive.

#19 Post by bester69 »

If you clone a whole disk.. I think you lose free space on the right side of the bigger target disk..I think you cant resize a table partition, unless ive never seen to do that kind of operation...thats why I clone partition to partition by copying them with gparted.. but I might be wrong and gparted let you to expand table partition as well.

sunrat wrote:...
Restores or new distro installs are a piece of cake. My largest OS image using fsarchiver is ~6GB.
......
by the way, right now ive my system fsarchiver backup (7Gb) uploading to box (I do one or two uploads per year) cloud with duplicity and rclone backend at just 100KB/seg, it will take around tree or four days to upload whole system backup.. at that slow speed.. but it pays off; duplicity is as reliable as btrfs in my experience and resuming operations never fails (seems unbreakable 8) ).. and box cloud us very reliable as well. 8)
bester69 wrote:STOP 2030 globalists demons, keep the fight for humanity freedom against NWO...

hack3rcon
Posts: 746
Joined: 2015-02-16 09:54
Has thanked: 48 times

Re: Clone an SSD drive.

#20 Post by hack3rcon »

Thank you.
The output is:

Code: Select all

$ lsblk -f
NAME FSTYPE LABEL UUID                                 FSAVAIL FSUSE% MOUNTPOINT

sdc                                                                   
├─sdc1
│    vfat   /sysro
│                 020C-0000                                           
├─sdc2
│    vfat   /db   0257-0000                                           
├─sdc3
│    vfat   /vmail
│                 02F6-0000                                           
├─sdc4
│                                                                     
├─sdc5
│    vfat   /sysro
│                 036A-0000                                           
├─sdc6
│    vfat   /db   037F-0000                                           
└─sdc7
     vfat   /unused
                  03FA-0000                                           
I unmount all partitions:

Code: Select all

$ sudo umount /dev/sdcX

Then:

Code: Select all

$ sudo dd if=/dev/sdc of=/home/jason/SSD.dd
234441648+0 records in
234441648+0 records out
120034123776 bytes (120 GB, 112 GiB) copied, 2850.17 s, 42.1 MB/s
And:

Code: Select all

$ file SSD.dd 
SSD.dd: DOS/MBR boot sector; partition 1 : ID=0x6, active, start-CHS (0x0,1,1), end-CHS (0x8f,254,63), startsector 63, 2313297 sectors; partition 2 : ID=0xb, start-CHS (0x90,0,1), end-CHS (0x3ea,254,63), startsector 2313360, 13799835 sectors; partition 3 : ID=0xc, start-CHS (0x3eb,0,1), end-CHS (0x3ff,254,63), startsector 16113195, 29543535 sectors; partition 4 : ID=0xf, start-CHS (0x3ff,0,1), end-CHS (0x3ff,254,63), startsector 45656730, 188784918 sectors
I plugged another SSD and:

Code: Select all

# dd if=/home/jason/SSD.dd of=/dev/sdc
Is it enough? I never defined any "bs" parameter, is it mandatory?
I did above command, but after 1 hour, restoring not finished yet!!! Is it normal?

Post Reply