Systempartition sichern mit Linux-Livesystem, dd und Samba

Words
657
Reading
3 min
Listen
Play
5y

(Etwas zwangloser heute)

Wichtig: Alles nur als Denkanstoß und Erfahrungsbericht gedacht. Lasst euch inspirieren, aber folgt dem nicht blind, wenn ihr euch nicht auskennt! Immer Handbuch lesen!

Hallo,

heute wollte ein Freund von mir, anlässlich der Installation eines Linux Zweitsystems, sein Hauptsystem mit Windows sichern. Ich riet ihm infolgedessen zu dd im Livesystem.

dd steht für disk dump und schreibt ganze block devices Bit für Bit irgendwohin, in den meisten Fällen in eine Datei oder ein anderes block device. Mit block devices sind hier Festplatten, USB-Sticks etc. gemeint. Ein bisschen muss man aufpassen, dass man nicht versehentlich die zu sichernde Festplatte überschreibt!

Da mein Freund aber keine externe Festplatte zur Verfügung hatte, fragte er mich, ob denn SMB/Samba übers Netzwerk auch ginge, woraufhin ich meinte, klar, wenn du das Ding gescheit mountest, sollte es kein Problem sein.

(Samba Anleitung: https://wiki.archlinux.org/title/Samba#Manual_mounting)
Wir haben das dann auch gleich ausprobiert. Nach anfänglichen Schwierigkeiten (Livesystem schmiert ab, Kollege verwendet Anleitung von '09) haben wir Samba dazu gebracht, den Netzwerk-Share zu mounten, das sah ungefähr so aus:

# cd /mnt
# mkdir backup-samba
# mount -t cifs -o username=<user>,password=<pw> //<hostname>/<share> backup-samba

Dann konnten wir auch schon anfangen zu kopieren:

dd-Parameter
  • if=/dev/<blockdevice> (zu sichernde Partition, zB /dev/sda1)

  • of=/mnt/backup-samba/disk.img (oder anderer Name)

  • bs=4M
    (Es ist nicht ganz klar ersichtlich, welche Blockgröße (Puffergröße, quasi wie groß ist die Schaufel vom Kopierbagger) man wählen sollte, aber ich habe mit 4-16MiB sehr gute Erfahrungen gemacht. Mehr braucht man nicht, bei weniger wird irgendwann der Overhead proportional zu groß.)

  • status=progress (ganz wichtig, weil man sonst nicht ohne weiteres irgendeinen Fortschritt angezeigt bekommt)

Der fertige Befehl:

# dd if=/dev/sda1 of=/mnt/backup-samba/disk.img bs=4M status=progress

Testen kann man das Image mithilfe von Loop Devices:

# losetup --partscan --find --show disk.img
# mount /dev/loop0p1 /mnt

to free up loop0, use after umount:
# losetup -d /dev/loop0

(Quelle: https://superuser.com/a/684707)

Danach kann man auch den SMB Share unmounten:

# umount /mnt/backup-samba
# rmdir /mnt/backup-samba

War tatsächlich gar nicht so schwer :)


English version


(Somewhat more casual today)

Important: All intended only as food for thought and experience report. Be inspired, but don't follow blindly if you don't know your way around! Always read manual!

Hello,

today a friend of mine, on the occasion of installing a Linux second system, wanted to backup his main system with Windows. I advised him to use dd in the live system.

dd stands for disk dump and writes whole block devices bit by bit somewhere, in most cases to a file or another block device. With block devices here hard disks, USB sticks etc. are meant. **You have to be a bit careful not to accidentally overwrite the harddisk you want to backup!

Since my friend didn't have an external hard drive, he asked me if SMB/Samba would work over the network, whereupon I said, sure, if you mount the thing properly, it shouldn't be a problem.

(Samba manual: https://wiki.archlinux.org/title/Samba#Manual_mounting)
We tried it out right away. After initial difficulties (live system crashes, colleague uses instructions from '09) we got Samba to mount the network share, it looked something like this:

# cd /mnt
# mkdir backup-samba
# mount -t cifs -o username=<user>,password=<pw> //<hostname>/<share> backup-samba

Then we could start copying:

dd-parameter
  • if=/dev/<blockdevice> (partition to backup, e.g. /dev/sda1)

  • of=/mnt/backup-samba/disk.img (or other name)

  • bs=4M
    (It is not very clear which block size (buffer size, quasi how big is the shovel of the copy excavator) you should choose, but I made very good experiences with 4-16MiB. You don't need more, with less the overhead becomes proportionally too big at some point).

  • status=progress (very important, because otherwise you don't get any progress displayed)

The finished command:

# dd if=/dev/sda1 of=/mnt/backup-samba/disk.img bs=4M status=progress

You can test the image using Loop Devices:

# losetup --partscan --find --show disk.img
# mount /dev/loop0p1 /mnt

to free up loop0, use after umount:
# losetup -d /dev/loop0

(source: https://superuser.com/a/684707)

After that you can also unmount the SMB share:

# umount /mnt/backup-samba
# rmdir /mnt/backup-samba

Was actually not that hard :)

Systempartition sichern mit Linux-Livesystem, dd und Samba | Ecency