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

 

 

 

Copying System

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
Lavender-Thief
Posts: 11
Joined: 2022-11-19 18:49

Copying System

#1 Post by Lavender-Thief »

Hello

I was wondering if it's possible to copy a complete Linux system?
Have all my settings and such available on another machine?
I'm a bit afraid to mess things up, that's why I'm asking it here first.

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

Re: Copying System

#2 Post by p.H »

Yes it is possible.

arochester
Emeritus
Emeritus
Posts: 2435
Joined: 2010-12-07 19:55
Has thanked: 14 times
Been thanked: 54 times

Re: Copying System

#3 Post by arochester »

Just watch your hardware, Similar or different?

only_someone
Posts: 24
Joined: 2023-01-24 22:12
Has thanked: 3 times

Re: Copying System

#4 Post by only_someone »

The dd command is what you are looking for i think. but always use this command with the highest caution, because if you use it wrong it can quickly lead to data loss.

With the dd command you can copy whole disks 1:1 or create .img (exact disk images) files and also load them back to the disk (recommended if you want to make backups) as well as create .iso files from disks, and much more.

If you want to copy your current system 1:1, you can theoretically do this from the system itself, but this can lead to problems because while the system is running, changes are constantly being made to certain files. It is recommended to copy the system from a life system, for example you can load a Debian live system [1] or other live systems like Knoppix on a usb stick.

The dd command is as said dangerous, if you use for example as input path an external disk and as output path your disk on which your system is running, your system disk (whether the system is running or not) will be overwritten with what is on the external disk. If this is too dangerous for you, you can use clonezilla [2] for example, with this tool you can also delete disks by mistake, but it has a graphical structure in the terminal where you can see better what you are doing.

The dd command needs an input path (if=) and an output path (of=) to determine from where it should copy the data to where. As an example I can give you this:

**Edited**
dd if=/dev/sdx of=/dev/sdx status=progress

Code: Select all

dd if=/dev/sdx of=/dev/sdy status=progress
in this case it would copy the data 1:1 from the disk sdx to sdy.

To find out the name of the disk you want to copy you can use the command lsblk.

Code: Select all

someone@onepc:~$ lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda      8:0    0 476,9G  0 disk 
├─sda1   8:3    0   512M  0 part /boot
├─sda2   8:4    0     1K  0 part 
├─sda3   8:5    0 472,4G  0 part /
└─sda4   8:6    0     4G  0 part [SWAP]
sdb      8:16   0   1,8T  0 disk 
└─sdb1   8:17   0   1,8T  0 part 
sdc      8:32   0   1,8T  0 disk 
└─sdc1   8:33   0   1,8T  0 part 
sr0     11:0    1  1024M  0 rom  
You should get such an output when you run it. sda, sdb, sdc are the disks themselves and e.g. sda1 would be a partition.
So if i wanted to copy my main disk sda to my other internal disk sdb, so i would have to replace sdx with sda and sdy with sdb in the command I gave above.

But if you are unsure about the dd command better ask first or use clonezilla [2] as an alternative, also, as arochester mentioned above, it would be important to know if the hardware of the other computer changes, because then driver problems could occur.

-------
[1] https://www.debian.org/CD/live/
[2] https://packages.debian.org/buster/clonezilla
Last edited by only_someone on 2023-02-05 23:12, edited 1 time in total.

User avatar
sunrat
Administrator
Administrator
Posts: 6382
Joined: 2006-08-29 09:12
Location: Melbourne, Australia
Has thanked: 115 times
Been thanked: 456 times

Re: Copying System

#5 Post by sunrat »

only_someone wrote: 2023-02-05 21:26

Code: Select all

dd if=/dev/sdx of=/dev/sdx status=progress
in this case it would copy the data 1:1 from the disk sdx to sdy.
Err, no it wouldn't. Should be:

Code: Select all

dd if=/dev/sdx of=/dev/sdy
“ computer users can be divided into 2 categories:
Those who have lost data
...and those who have not lost data YET ”
Remember to BACKUP!

only_someone
Posts: 24
Joined: 2023-01-24 22:12
Has thanked: 3 times

Re: Copying System

#6 Post by only_someone »

sunrat wrote: 2023-02-05 22:29
only_someone wrote: 2023-02-05 21:26

Code: Select all

dd if=/dev/sdx of=/dev/sdx status=progress
in this case it would copy the data 1:1 from the disk sdx to sdy.
Err, no it wouldn't. Should be:

Code: Select all

dd if=/dev/sdx of=/dev/sdy
oh, sorry I mistyped that one :oops:

Well at least this is now the perfect example of how quickly you can lose your data !

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

Re: Copying System

#7 Post by CwF »

To avoid mistake you can use the other designates in /dev/disk like .../by-label etc.

I usually don't go device to device so I'm only 99% sure qemu-img would do the job. I use by-label as often as possible, and take the step to label all.

I forward-up instead of backing up so go from disk to image, from that image to new disk. This condenses verifying things to part of the process. When new disk is successful and from the image now known as the tested good backup.

qemu-img is from qemu-utils. It may pull in libaio and libfuse3-3 for about 7MB's.

It is basically a dd -extra. In a similar way it operates on unmounted devices. It offers sparseness, compression, and the qcow2 format which has many advantages.

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

Re: Copying System

#8 Post by p.H »

only_someone wrote: 2023-02-05 21:26 If you want to copy your current system 1:1, you can theoretically do this from the system itself, but this can lead to problems because while the system is running, changes are constantly being made
No you can't. It will lead to problems as the result will be corrupted. A read-write mounted filesystem is in an inconsistent ("dirty") on-disk state by design and becomes consistent again only when cleanly unmounted or remounted read-only.

only_someone
Posts: 24
Joined: 2023-01-24 22:12
Has thanked: 3 times

Re: Copying System

#9 Post by only_someone »

p.H wrote: 2023-02-08 20:44
only_someone wrote: 2023-02-05 21:26 If you want to copy your current system 1:1, you can theoretically do this from the system itself, but this can lead to problems because while the system is running, changes are constantly being made
No you can't. It will lead to problems as the result will be corrupted. A read-write mounted filesystem is in an inconsistent ("dirty") on-disk state by design and becomes consistent again only when cleanly unmounted or remounted read-only.
only_someone wrote: 2023-02-05 21:26 If you want to copy your current system 1:1, you can theoretically do this from the system itself, but this can lead to problems because while the system is running, changes are constantly being made to certain files. It is recommended to copy the system from a life system, for example...
I admit that my choice of the word "can" was inaccurate, as there is a very high probability that files will be damaged. I used the "can" to refer to that the copied system may or may not work afterwards.

Years ago I tried to copy my GNU/Linux system from my internal HDD to an external HDD to test if I could use it as a portable system. I used the dd command to copy my HDD where the system was running at that moment. I was aware that it was not a good idea but it worked without the copied system causing errors, at least I could not see any error messages in any log file nor was any error visible when using the system. On the 3 attempt it then caused errors when starting the copied system, so it may work but does not have to and it is not recommended as I wrote.

I'm sorry, I was over-motivated in answering.

Post Reply