Disk images

From Bashlinux
Jump to: navigation, search

How to backup a whole HD

The byte size bs is useful to do a fast copy, specially then output location is remotely on a network

dd if=/dev/sda of=/path/to/store/disk.img bs=4096

To mount a partition from here, you have to consider that you have to ignore partition table.

mount -o loop,offset=32256 /path/to/store/disk.img /mnt/mydisk

How to backup only one partition from a HD

dd if=/dev/sda1 of=/path/to/store/disk.img bs=4096

How to convert a raw image from HD in a VMWare HD image

qemu-img convert -f raw /path/to/image/XPSP2.img -O vmdk /path/to/image/XPSP2.vmdk

How to create a filesystem for CentOS 5 an older distros

One of the issues is grub is unable to read the filesystem, and must of the time is because the recent distros uses 256-byte node size. In order to fix it, specially on VMs, you must do:

  • Create the virtual drive as usual
# qemu-img create -f raw disk.img 20G
  • boot using a knoppix image as cdrom
# qemu-system-x86_64 -m1024 -hda disk.img -cdrom knoppix.iso -boot d
  • On knoppix prompt, type knoppix 3, in order to boot in init level 3
  • From the shell, start cfdisk and add only one Linux partition.
  • Create the filesystem in the created partition with 128-byte node size
 # mkfs.ext3 -I 128 /dev/sda1
  • Turn off the virtual machine
  • Now, you can mount the drive as a real physical disk with
# mkdir disk
# mount -o loop,offset=32256 disk.img disk/