Creating a Disk Image on Linux Using DD 🌱

Things You Will Need

Creating An Image

  1. Insert the SD card or USB flash drive to make an image of
  2. Run the following commands in a terminal window:
    # list out disks
    sudo fdisk -l
    # run the following to create a .img, replace sdb with the correct source disk
    sudo dd if=/dev/sdb of=~/flashstorage.img status=progress
    # run the following to create a compressed img, replace sdb with the correct source disk
    sudo dd if=/dev/sdb status=progress | gzip -c >~/flashstorage.img.gz

Restoring An Image

  1. Insert the SD card or USB flash drive to make an image of
  2. Run the following commands in a terminal window:
    # list out disks
    sudo fdisk -l
    # run the following to restore an .img to the target device
    # replace sdb with the correct source disk
    # MAKE ABSOLUTELY CERTAIN THE OUTPUT TARGET IS CORRECT
    # OR YOU COULD POTENTIAL DAMAGE YOUR OS
    # restore img
    sudo dd if=~/flashstorage.img of=/dev/sdb bs=4M status=progress
    # restore gzipped img
    gunzip -c ~/flashstorage.img.gz | sudo dd of=/dev/sdb bs=4M status=progress