0

Probably that's an odd question, I'm sorry. Can I copy my Ubuntu 20.04 os to another computer (completely, I would like to include everything out of the box) just copying my / directory? If I want to transfer everything on a new computer, can I simply copy/paste my / directory on the new computer?

Thanks

EDIT: Another question, let me explain my situation. I have several files in the root directories and not only in my home directory that I want to backup, some of them are simply changes to config files, some of them are new files, but I don't know exactly which file is modified/new. I want to move to another computer, and I would like to have the same os working on my actual computer, changing only the hardware. How can I do it? I thought the easy way would be copy-pasting the directories

  • 1
    No. "cp" will mess up permissions if you do not use the settings to preserve them. But there is a better tool for this: disk dump (dd is the command). Boot from a live session, 'dd` your partitions onto an external disk and you can reuse that disk dump to put it on another system. Mind that I would advice to not do this: make a backup of PERSONAL files and just reinstall the system. a bit more work but you can automate all your alterations you want to make – Rinzwind Oct 6 at 18:30
  • I am using cp -a with no problems. dd is not so good for this purpose. – Pilot6 Oct 6 at 18:32
  • I got confused about why everyone was recommending dd for backup until I re-read the question and it's not about backup, it's about migrating a working OS to another computer, so I made a suggested edit to the title – thomasrutter Oct 6 at 23:31
  • 1
    OP, why not physically remove the system drive from computer A and place it into computer B? That would be faster than dd and avoid the problem of the target drive being a different size. – thomasrutter Oct 6 at 23:42
  • @thomasrutter... same computer... is in a few of the comments..... "essentially" a new computer since it will be TOTALLY reloaded.. but it is the same physical machine... apparently – WU-TANG Oct 6 at 23:45
3

Dont't.

It is a waste of time.

Making a backup of your operating system is time consuming. Your backup is quickly obsolete. Operating systems come for free and install in less than an hour. The operating system you install in the future will be better than the one you are considering to backup now.

Instead invest this time and effort in a good backup of your user data.

Your user data are unique.

They do not exist anywhere else on this planet.

Once lost, they are lost forever.

Having a good backup of your data anytime is therefore priority number 1, and essentially your single only concern when you work with computers.

With that out of the way, no, it is not just a matter of copying and pasting an operating system to a new computer to have an operational system on your new computer.

| improve this answer | |
  • @fedeubuntu IMO, although wu-tang's answer is technically correct, I would go with vanadium's answer. You can backup your /home directory (or any other directories) with Back in time or with any similar programs; where you can (1) excludes the directories that you do not want to include in a snapshot / backup, and (2) setup scheduled snapshots among other things. You should save these snapshots on a different internel or on an external drive. – Jags Oct 6 at 22:54
  • 1
    I actually agree somewhat with this but there are just use cases where it is not feasible. I don't really know if the OP truly has one, not my call. But, for instance, I cannot stand re-configing my raspberry pi after a power outage... it runs about 5 services and even with the old config files backed up it still takes hours to get it back onlline. Drivers have to be downloaded, workarounds remembered, PPDs, new ssh keys, etc... no thanks! If it doesn't create a huge inconvenience then yeah i use it as an opportunity to upgrade. But i do keep a backup iso or virtual of most of my machines. – WU-TANG Oct 6 at 23:36
  • Sometimes you just need an OS configured as you want, and use it for years since you don't need anything else. In my job, where computers are old and used for a single purpose, it's easier to just create an image with clonezilla and in case of trouble it just takes a few minutes to have a clean an usable system. – schrodigerscatcuriosity Oct 7 at 1:06
  • @schrodigerscatcuriosity fully agree, but as the question is asked now, it appears to be a typical Ubuntu 20.04 user wanting to transfer a working system to another computer. In that case, it is not worth the hassle. Transferring the image of the system to another computer may, depending on the hardware, not work, or at least not without additional technical interventions. – vanadium Oct 7 at 8:44
2

I'd rather just copy the entire drive, with drive space not being so costly anymore.

I am a proponent of using dd in these situations whenever possible.
(Though I've gotten away with it mounted and in use, copying the root system should probably be done via a live CD/USB)
(All the device/directory names used below are arbitrary)

Option 1) I would copy the drive to an iso.
dd if=/dev/sda of=/someotherlargedrive/backupname.iso bs=4M status=progress

To restore that image back on a drive.
dd if=/someotherlargedrive/backupname.iso of=/dev/sdb bs=4M status=progress

OR

Option 2) I would copy the ubuntu partition to an iso.
dd if=/dev/sda1 of=/someotherlargedrive/backupname.iso bs=4M status=progress

To restore the image back on a partition
dd if=/someotherlargedrive/backupname.iso of=/dev/sdc1 bs=4M status=progress

!!!Keep in mind that if only cloning a partition, there may be other necessary partitions like "/boot" that may need to be considered depending on the situation.

OR

Option 3) I would copy the entire drive to another drive, creating a usable bootable clone.
dd if=/dev/sda of=/dev/sdb bs=4M status=progress

OR

Option 4) I'd just take the hard drive out of the one PC and put it into the new one... Other than things like graphics and other manually downloaded drivers, the [LINUX] drive should transfer operationally with little to no reconfiguration.

OR

sidebar....Depending on the application and the urgency for portability, I may consider using VMs, as they are easily cloned (or just copied with the cp command)... So the PC itself is basically a file and portable to another host running the virtualization software. I have dd'ed physical boxes into images for VMs(and sometimes directly onto VMs) and have taken copies of my Desktop PC elsewhere around the house and to work & travel on a laptop.

| improve this answer | |
  • For the second solution, if I copy ubuntu making an iso, can I burn it into a usb to install it somewhere else? – fedeUbuntu Oct 6 at 20:13
  • 1
    you cannot "install" it.. but you can copy it "somewhere else" like i detailed there in the "restore" part. You will basically be cloning it to your new partition in the new location (you would "effectively" be installing it, but install means something different, so we wont use that word)..... but again, be aware of the warning I put there about partitions... if have any other directories mounted on separate partitions like /boot, /home, etc... those will not come and you will need to copy those too, separately. But If all your directories are mounted under "/", then it's pretty automatic. – WU-TANG Oct 6 at 20:29
  • I know that .iso files are meant to be burnt on a drive to be installed and I thought that that process would make me have an ubuntu.iso image to burn it and install just like you have the basic image to make the first ubuntu install, but I think I'm wrong. I have everything mounted under /. I'm doing this process on the same computer, I want to clean my entire drive from every partition, then install there only my old Ubuntu with everything that it has now, so I need to be sure that everything goes right – fedeUbuntu Oct 6 at 20:34
  • 1
    yes that is wrong in this case, .iso = image... you will have an "image" of your partition using option 2... Do you have another drive in your machine or external that is going to be large enough to store the whole partition? can you show the output of df -h ...or maybe a snapshot of the gnome-disks utility? – WU-TANG Oct 6 at 20:41
  • I have an external drive to which I would put my backup – fedeUbuntu Oct 6 at 20:49
0

Yes, you can. But you need to use cp -a command to preserve permissions.

| improve this answer | |
  • And then I just need to paste every directory inside / of the new computer? – fedeUbuntu Oct 6 at 18:29
  • Not "paste" but copy it back the same way. – Pilot6 Oct 6 at 18:31
  • are you 100% sure? did you personally try it? in reality, i have to do it on the same computer so i need to be sure nothing goes wrong – fedeUbuntu Oct 6 at 20:28
  • 1
    User wants to copy entire system across, so this will be inadequate because it won't transfer partitions, partition UUIDs, boot sector (if MBR), UEFI boot menu entry (if UEFI) and so on, that will all need to be done manually. At minimum, fstab and boot would need to be manually repaired after doing this. It's not going to be easy. Reinstall is best, followed by dd of entire drive. – thomasrutter Oct 6 at 23:40
0

Using rsync you can backup entire root partition content to remote location or any device.

sudo rsync -aAXv / --exclude={"/dev/*","/proc/*","/sys/*","/tmp/*","/run/*","/mnt/*","/media/*","/lost+found"} <remote location or any drive location> 

Here you don't need to backup /dev/,/proc,/sys,/run/,/mnt,/media,/lost+found and ignore it. These partitions are not preferred because they content details which can be different to system to system according to installation and backuping them won't help to restore in another system or you might messed up if you restore backup in another system.

| improve this answer | |
  • This is another good way. – Pilot6 Oct 6 at 18:34
  • Then how can I restore it on another computer? – fedeUbuntu Oct 6 at 20:14
  • Just rsync it directly to the drive you want to transfer it to. You have to have partitioned the target drive how you want it, your fstab probably won't work after, and booting won't either. It's going to be easier for you in the long run to reinstall and just copy over your personal files, but dd would be second best. – thomasrutter Oct 6 at 23:37
0

Copying a working system to another computer is possible (at least sometimes, I have tried it two times with success), however, it is not simple and it is sometimes a trial-and-error approach to get the copied system to boot.

First, before making a copy it's best to boot from a live DVD or USB so that filesystems on your disk are not actively used. There are system files (eg. logs) that are modified constantly while the system is running, so you won't copy them properly if you boot from the same system you are trying to copy.

Second, instead of using cp I suggest to tar every filesystem and un-tar it on the target computer onto appropriate partition (also using live DVD/USB for this purpose). This preserves permissions, links, special files like devices, pipes etc.

Third, after having everything copied to the target computer you will anyway need to adjust some crucial configuration files (like /etc/fstab), otherwise your copied system will not boot. You may need to generate a new initramfs as well. And surely, you will need to reinstall GRUB on the new system.

These are just general hints; if you don't fully understand what do I mean by the above, I suggest you don't try this because it requires at least average knowledge of the mechanisms how the system boots, how the filesystems are mounted etc.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.