Howto: Disk-Images erstellen unter Linux

Aus aktuellem Anlass: Wie erstelle ich von meiner Disk ein (komrpimiertes) Image?

Update: Anstatt mit dd lässt sich das auch mit Umleitungen machen! Siehe Variante 2.

Ausgangslage:

Angenommen ich will meine /boot-Partition sichern, bzw ein Image davon erstellen.
[cc lang="bash"](14:14)mhutter@ganymede:~$
df -h
Filesystem            Size  Used Avail Use% Mounted on
*schnipp*
/dev/md0              221M   31M  179M  15% /boot[/cc]
Hinweis: Die meisten dd-Befehle müssen mit Root-Rechten ausgeführt werden.

Variante 1: Ohne Komprimierung

(NICHT empfohlen)
[cc lang="bash"](14:21)root@ganymede:~#
dd if=/dev/md0 of=/backup/boot.img bs=4M
58+1 records in
58+1 records out
246611968 bytes (247 MB) copied, 0.366272 s, 673 MB/s
(14:22)root@ganymede:~#
ls -lah /backup
total 236M
-rw-r–r– 1 root root 236M 2009-10-30 14:22 boot.img[/cc]
Das ging zwar sehr schnell (0,3sek), aber das Image ist so gross wie die ganze Partition! Klar kann man nachträglich noch gzippen oder so, aber ich bevorzuge

Variante 2: Direkt komprimieren

(empfohlen!)
[cc lang="bash"](14:24)root@ganymede:~#
dd if=/dev/md0 | gzip -c > /backup/boot.img.gz
481664+0 records in
481664+0 records out
246611968 bytes (247 MB) copied, 3.52991 s, 69.9 MB/s
# NACHTRAG! Das geht auch einfacher!
# Das Ergebnis ist genau dasselbe:
gzip -c < /dev/md0 > /backup/boot.img.gz
# Ende Nachtrag
(14:25)root@ganymede:~#
ls -lah /backup
total 29M
-rw-r–r– 1 root root 29M 2009-10-30 14:25 boot.img.gz[/cc]
Das hat jetzt zwar rund 10mal länger gedauert, aber siehe da: Das Image ist nur noch 29MB gross! Win!

Zusatzinfo

Images entpacken und mounten

Das Entpacken klappt einfach mit [cci]gunzip boot.img.gz[/cci] Und so wird nachher gemountet:
[cc lang="bash"]mount -o loop /backup/boot.img /mnt/boot/
# Manchmal muss man auch den Dateisystemtyp angeben:
mount -o loop -t ext2 /backup/boot.img /mnt/boot/[/cc]

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>