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
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.
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.
Yes, you can. But you need to use
cp -a
command to preserve permissions.Using rsync you can backup entire root partition content to remote location or any device.
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.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 totar
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.