Sunday, May 5, 2024
 Popular · Latest · Hot · Upcoming
5
rated 0 times [  5] [ 0]  / answers: 1 / hits: 452  / 1 Year ago, sat, january 28, 2023, 8:42:43

I've been trying to get CUDA to work on my system and in the process of messing with nvidia drivers I have broken ubuntu badly enough that I've had to reformat my drive partition multiple times. I've now been hit with that stick enough times that I'm trying to back up my partition once I've installed all my tools and programs and stuff, using dd (as recommended by a friend).



However, when I ran



sudo dd if=/dev/sda4 of=~/backup.img



I eventually got an error that my drive ran out of space. This was strange to me, since the partition is quite large and I have just a fresh ubuntu install along with a few (small) programs on it.



I figured what might be happening is that it was recursively trying to write a copy of what it had already written, so I tried writing the file directly to another partition instead:



sudo dd if=/dev/sda4 of=/media/Ye Olde Data/ubuntu reinstall backup/backup.img



But this took forever and I aborted the process once the file got to a size I was pretty sure was too big to contain only the data I wanted.



What is happening? Is it that /media has the other partitions mounted and thus it's treating the other partitions as part of /dev/sda4? Is it that dd copies the entire partition byte-for-byte, ignoring what bytes actually have files on them?



And whatever the case, how can I do what I am trying to do, correctly?



Oh, and here's my disk information, in case it matters:



sudo sfdisk -l /dev/sda

Disk /dev/sda: 62260 cylinders, 255 heads, 63 sectors/track
Warning: extended partition does not start at a cylinder boundary.
DOS and Linux will interpret the contents differently.
Units = cylinders of 8225280 bytes, blocks of 1024 bytes, counting from 0

Device Boot Start End #cyls #blocks Id System
/dev/sda1 * 0+ 12- 13- 102400 7 HPFS/NTFS/exFAT
/dev/sda2 12+ 14602- 14590- 117187500 7 HPFS/NTFS/exFAT
/dev/sda3 29192+ 62260- 33069- 265622493+ 5 Extended
/dev/sda4 14602+ 29191- 14590- 117193728 83 Linux
/dev/sda5 61228+ 62260- 1032- 8287232 82 Linux swap / Solaris
/dev/sda6 29192+ 61227 32036- 257329138+ 7 HPFS/NTFS/exFAT

More From » dual-boot

 Answers
6

If you copy a partition with dd, the output file will be as big as the partition. dd does a physical copy of the disc, it has no knowledge of blank or used space.



If you compress the result file you will save a lot of space, though, given that blank space will compress away very well (beware, this is going to be computationally very heavy). You can even compress the output of dd on the fly, with something on the line of dd if=/dev/sdaX | gzip -c > compressed_file.gz.



really important:




Moreover, you cannot (never) do a dd on a live (mounted)
partition, the data recorded will be totally inconsistent and
absolutely not useful for a backup. Think about it: blocks of data are
continually allocated, moved and deleted; is like shooting a photo
with long exposure time to a moving target.



To copy the partition with dd you must boot from a different one -
live USB or whatever.




What would I do to solve the problem at hand (notice, only generic instruction because you need to know what you are doing)



First option buy Norton Ghost, or explore the opensource options: partimage and clonezilla (never tested myself).



Second option do it manually:




  1. create an extra partition for backups, call it /dev/sdX (or use a common data partition, whatever).


  2. to backup:




    • boot with live usb

    • mount the real root partition in /real

    • mount the extra partition in /extra

    • do a big tar, on the line of (cd /real && tar cvf /extra/mybck.tar.gz)


  3. to restore




    • boot with live usb

    • mount the real root partition in /real

    • mount the extra partition in /extra

    • restore, on the line of (cd /real && tar xvpf /extra/mybck.tar.gz), beware of the p option to preserve metadata

    • chroot in /real

    • update grub or the bootloader you are using




You can substitute tar with your preferred archiver, just be sure it will respect ownership/mode of files. rsync is worth exploring.


[#25732] Sunday, January 29, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
corsee

Total Points: 479
Total Questions: 122
Total Answers: 106

Location: Barbados
Member since Sat, May 9, 2020
4 Years ago
;