You are not logged in.

#1 2019-11-21 15:25:42

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

[SOLVED] Disk imaging with dd and restoring single files. How?

Hi to all?
I would like to be able to create a backup of my laptop drives (a 256GB SDD with Windows 10, Archlinux OS, UEFI and /boot partitions and a 1TB HDD which I use to store data) and to be able to restor from this backup single files if needed.
Clonezilla does not permit me to do that, but I have seen that it is possible to create disk images with dd and then mount them if needed.
To create the image if I have understood correctly I can use the following commands from a live cd:

dd if=/dev/sda of=/media/externalhd/backup_sda.img
dd if=/dev/sdb of=/media/externalhd/backup_sdb.img

once I have mounted the destination drive (for example a 4TB USB device as /media/externalhd/ (see https://unix.stackexchange.com/question … ltaneously)
To mount the images and restore single files I can use:

losetup -P -f --show backup_sda.img
losetup -P -f --show backup_sdb.img

and mount the devices (or use the scripts as in this page https://unix.stackexchange.com/question … ull-system ).

Now the question are:
1) is all above correct?
2) Is it possible to improve something?
3) Is there any program/live CD that allows to do the same more easily?
4) Do you have any other suggestion?

Thank you,
Xwang

Last edited by Xwang (2019-11-24 12:00:23)

Offline

#2 2019-11-21 15:53:54

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 25,405

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Don't use dd, use rsync: https://wiki.archlinux.org/index.php/Rs … tem_backup

Unless your external hd absolutely does not understand unix permissions, in which case it'd probably still be better to tar them up instead of going for a full disk dump when in actuality you explicitly don't even want a disk dump.

Offline

#3 2019-11-21 15:54:52

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 20,703

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

I don't know about those scripts (I did not look), but the losetup and dd commands look correct.  You will need to run them with root privileges. BUT:  Do Not run those dd commands to image a mounted, live file system.   Especially if those images are being written to that same file system.  Also, be aware that the loop devices may be of the form loop0p1 loop0p2.  Those are associated with the partitions embedded in the image and are the things you will want to mount.

Edit:  V1del and I were posting at the same time.  I agree that their solution is the better way to create a backup, I was trying to directly answer your question.  I use this technique because I work with embedded Linux in which we upload an image to a flash memory on the target.  Mounting the image on my host system is a convenient way to go in and configure the system to be used on the target using a host system that actually has a keyboard and display.

Last edited by ewaller (2019-11-21 16:02:46)


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
The shortest way to ruin a country is to give power to demagogues.— Dionysius of Halicarnassus
---
How to Ask Questions the Smart Way

Offline

#4 2019-11-21 16:00:37

frostschutz
Member
Registered: 2013-11-15
Posts: 1,658

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

losetup --find --show --partscan will create a partitioned loop device for you, which can be mounted, and thus provides access to files. So yes, it's possible.

But why not backup files in the first place? (rsync, borg, ...)

Offline

#5 2019-11-21 18:31:58

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

I wanted to backup even the Windows and UEFI partitions (NTFS and FAT32 respectively) with MBR too so that to be able to use these disk images both as a whole system backup and a backup from which recover single files if needed.
I do not know if I can backup with rsync also the windows and UEFI partitions and the MBR, If possible I will prefer to us that too.
In any case I will do the backup from a live cd so that the system Iìm copying is not running meanwhile.

Offline

#6 2019-11-22 03:19:20

headkase
Member
Registered: 2011-12-06
Posts: 1,993

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Why don't you just do a mirror?  You have to store the backup anyway so mirroring to a drive of equal capacity does both backup and storage?  You can get hard drive caddies for convenient plugging of the physical drives.  Then if you want files, plug the "backup/mirror" drive into the caddie and just mount the partition you need?

Last edited by headkase (2019-11-22 03:20:12)

Offline

#7 2019-11-22 07:43:26

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

headkase wrote:

Why don't you just do a mirror?  You have to store the backup anyway so mirroring to a drive of equal capacity does both backup and storage?  You can get hard drive caddies for convenient plugging of the physical drives.  Then if you want files, plug the "backup/mirror" drive into the caddie and just mount the partition you need?

I'm trying to use the hardware that I already have (the external 3TB HDD in which I hope I will be able to put two backup images which I will cycle periodically (every month).

Offline

#8 2019-11-23 00:39:15

headkase
Member
Registered: 2011-12-06
Posts: 1,993

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

What is your use case?  Think about what you want, and consider the trade-offs.  It may be that a different backup strategy would be better than what this convoluted approach seems.

Offline

#9 2019-11-23 12:49:37

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

My use case is to make every month a disk image of the hard drives so that in case of a catastrophic failure I will be able to return to a previous working state without the need of reinstall windows, linux, bootloader and programs in the two operating systems. Moreover in case of need I want to be able to take single files from the disk images by mounting them in order to not have another backup set just to be able to restore single files.
I will keep two backup images (one and two month old respectively) in the external 3TB HDD.

Offline

#10 2019-11-23 12:57:52

graysky
Wiki Maintainer
From: :wq
Registered: 2008-12-01
Posts: 10,734
Website

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Again, use rysnc.

Offline

#11 2019-11-23 13:08:07

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

How can I use Rsync from a live CD to backup the windows partitions too plus UEFI and MBR tables so that to be able to restore both hard drive in case of need?
(I haven't found a guide for a dual boot backup which uses rsysnc, can you explain better how to do that, please?)

Offline

#12 2019-11-23 14:19:54

edacval
Member
From: .LT
Registered: 2008-10-23
Posts: 98

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Del

Last edited by edacval (2019-11-23 14:56:45)

Offline

#13 2019-11-23 14:24:58

Slithery
Administrator
From: Norfolk, UK
Registered: 2013-12-01
Posts: 5,776

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Xwang wrote:

Clonezilla does not permit me to do that...

Google disagrees with you.


No, it didn't "fix" anything. It just shifted the brokeness one space to the right. - jasonwryan
Closing -- for deletion; Banning -- for muppetry. - jasonwryan

aur - dotfiles

Offline

#14 2019-11-23 14:51:47

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Slithery wrote:
Xwang wrote:

Clonezilla does not permit me to do that...

Google disagrees with you.

You are right.
Probably I have to try to use the advanced mode of clonezilla to avoid that the images are splitted and compressed and then it is possible to mount them.
With the standard settings I need to have enough free space on the hard disk to decompress and join the split images before I can mount them.
I will try.

Offline

#15 2019-11-24 11:59:04

Xwang
Member
From: EU
Registered: 2012-05-14
Posts: 419

Re: [SOLVED] Disk imaging with dd and restoring single files. How?

Xwang wrote:
Slithery wrote:
Xwang wrote:

Clonezilla does not permit me to do that...

Google disagrees with you.

You are right.
Probably I have to try to use the advanced mode of clonezilla to avoid that the images are splitted and compressed and then it is possible to mount them.
With the standard settings I need to have enough free space on the hard disk to decompress and join the split images before I can mount them.
I will try.

I've tried and I've discovered that:
1) creating a disk image with default tools but uncompressed and not splitted does need to recover the image before mounting it (so I will need to have enough free space to temporarly store a restored image file which is as great as the hdd space I am backup-ing. So this approach is not feasible for me)
2) creating a disk image uncompressed and not splitted and forcing the use of dd creates images directly mountable.
So I will probably stick with this modus operandi which seems to full fill all my needs.
Thank you all for your support.

ps: this is the command used by clonezilla to create the backup with dd:

/usr/sbin/ocs-sr -q1 -c -j2 -z0 -i 40960000000000 -sfsck -senc -p choose savedisk 2019-11-24-09-img sda

Offline

Board footer

Powered by FluxBB