One way is to create a blank os and copy all folders and files that you need.
There are a lot of tutorials for that.
Check for how to create a linux system backup with rsync
How To Backup Your Entire Linux System Using Rsync
Full system backup with rsync
The other way and the best way to clone a whole drive, partition with data or an os on a drive and I prefer that myself, is with dd
, the best in my opinion for clone/backup of devices/partitions.
dd
will clone everything bit per bit.
Before you start experimenting and trying out different tools, I would do a full backup/clone of the device to another with dd
, if you have the option, and check if the backup/clone works.
If your whole devices is encrypted with luks
as an example, you can do a whole clone and flash to your new device, that will work too!
If you work with mounted fuse/sshfs you can backup/clone directly to this network folders too.
You can list all your block devices with lsblk
Example:
- if your drive is /dev/sda and you wanna store/backup/clone on a directory or storage
dd if=/dev/sda of=/home/user/osbkp.img bs=1M status=progress
You don't need name.img it can be os123.bkp too
- do a live clone of a running system to target drive without creating an image.
source is /dev/sda and target is /dev/sdb
dd if=/dev/sda of=/dev/sdb bs=1M status=progress
Sometimes you create the new backup/clone to your new drive but you can't start from this device, than try again with dd(nothing works 100%)
- clone the image to a new drive, where target is /dev/sdb
dd if=/home/user/osbkp.img of=/dev/sdb bs=1M status=progress
- clone a given partition
dd if=/dev/sda1 of=/home/user/part1.img bs=1M status=progress
Explain:
if=INPUT/SOURCE
of=OUTPUT/TARGET
bs=BLOCKS SIZE FOR COPY
There are different blocksize that can be used I prefer 1MB, you can speed the process up or slow done with this setting, you have to find by yourself what is the best option
status=progress STATUS IN REALTIME
- if you work with fat* as storage you can split the files, take a look at that posts too:
Break up a dd image into multiple files
Creating a 80GB image with dd on a FAT32 drive
There are a few thinks that you have to keep in mind:
0. dd will clone everything of this devices.
Your drive is /dev/sda
and you clone this
with 5 partitions
/dev/sda1
/dev/sda2
/dev/sda3
/dev/sda4
/dev/sda5
You will get one file from /dev/sda with all this partitions, mbr, gpt, etc..
1. You can clone to every drive/storage
- You can clone from a harddisk to usb, or usb to harddisk, etc.. and
run your cloned os from your new device
2. Your running target devices must have the same size or must be bigger
- you can't clone a bigger device to a smaller drive or clone only the used space of a partition
- Example:
Your partition to clone is 8 GB but your os on the partition is only 1GB
so you have free space of 7 GB, your target where you wanna clone to run your os is 4GB, this is not possible! You will clone the whole device with dd to your new drive you can't resize this.
If you clone to a bigger devices you can create a new partition with the remaining space and mount/use that on your new device/os.
Take care if you try to merge the remaining space to your given partition!
3. The best way is to use a live system or other linux systems
and than plugin your drives and clone from target to source or from target to storage
4. every device has it's unique uuid and a label name that identified the device
if you clone drive a to b and you have both drives in one pc and you try to boot one of them with the label name or uuid, check grub or your bootmanager you will get a problem or you boot the wrong os.
You can check this with blkid
and other commands.
You can change that and generate a new uuid, label, etc.. but be careful
5. You don't need to format the drive where your cloned image will run the dd will destroy/delete everything an create the new mbr, gpt, format, filesystem etc. from the given backed os
Create your basic clones with dd and do your stuff, but later I mean it is better to clone/copy only the changed files.
In GNU/LINUX everything is a File.
dd if=/dev/sda of=/someotherlargedrive/backupname.iso bs=4M
? – Hölderlin Mar 22 '23 at 14:28