Create Image From Sd Card

Posted on  by admin
≡ Pages

Create an image on macOS

I spent time figuring this out due to needing SD cards for my Raspberry Pi, but the instructions apply to pretty much anything on SD.

Windows sadly lacks the DD utility that’s ubiquitous on Unix/Linux systems. Luckily there is a dd for Windows utility. Get the latest version here (release at time of writing is 0.63beta). Before using DD it’s important to figure out which disk number is allocated to the SD card. This can be seen in Computer Management tool (click on the Start button then Right Click on Computer and select Manage).

Go to Storage -> Disk Management:. Here the SD card is Disk 1. First start a Windows command line as Administrator (hit the start button, type cmd then right click on the cmd.exe that appears and select Run as Administrator).

Next change directory to wherever you unzipped the DD tool. To copy the SD card to an image file (in this case c:\temp\myimage.img) use the following command line:.

Writing the image back to a clean SD card

In this case we’re using DD with 3 simple arguments:. Input file (if) is the SD card device. Output file (of) is the image file we’re creating. Block size (bs) is 1 megabyte. The first step is to ensure that the SD is complete clean. Most cards come preformatted for use with Windows machines, cameras etc. The diskpart tool can be used to remove that. Go back to your cmd running as administrator (and be very careful if you have multiple disks that you use the right number):.

  • You’re now ready to copy the image back to the SD (simply by swapping the earlier input file and output file arguments):.
  • Modified1 year ago.
  • In Linux, we can do. but if the disk is of 32GB with only 4GB used, the 32GB image file is waste of space-time.
  • Is there any way or tool to create images with only valid data?

Raspberry Pi Resources

66 gold badges3434 silver badges5757 bronze badges. 5757 bronze badges. Pretty good and simple way to deal with this is simply pipe it via gzip, something like this:.


This way your image will be compressed and most likely unused space will be squeezed to almost nothing. You would use this to restore such image back:. One note: if you had a lot of files which were recently deleted, image size may be still large (deleting file does not necessarily zeroes underlying sectors).

Your SD card will stop working

You can wipe free space by creating and immediately deleting large file containing zeros:. 1313 gold badges113113 silver badges144144 bronze badges. 144144 bronze badges. The best thing to do is. Copy all the files from all the partitions preserving meta data. Extract the MBR. replace /dev/sdX with the corresponding device. Partition the destination disk into partitions with sizes greater than copied data and should be of the same format and same flags using gparted.

Use this technique to save time

Google how to partition a disk. Mount the freshly formatted and partitioned disk. On most computers, you just need to connect the disk and you can find the mounted partitions in /media folder. Copy the previously copied data to destination partitions using following commands. Copy back the MBR. Now njoy Ur new disk! 66 gold badges3434 silver badges5757 bronze badges.

Restoration on macOS

5757 bronze badges. Using the bs and count parameters of dd, you can limit the size of the image, as seen in step 2 of answer 1665017. You may already know what size image you want to create. If not, you can get a good idea from df:. Substitute / with a space-separated list of all the mount points relating to the disk partitions.

A more accurate way might be to use fdisk or your preferred partition editor and get busy with a calculator. Total used space in bytes = end sector of last partition X sector size (here that's 3667967 x 512). Total used space in GB = total used space in bytes / 10243 (here that's 1.749023 GB).

If you decide, for example, that your image should be exactly 2 GB, the following command will do that:.

Why do you need to create a Raspberry Pi image?

The resulting image will also include the random noise beyond the greatest extent of the last partition. Don't forget to sudo the above commands if your account doesn't already have sufficient privileges. For my purposes, I don't need an image that is perfectly trimmed down to the last bit of data so when the real size is 1.75 GB then a 2 GB image is near enough for me. This cuts out the other 6 GB (or 30 GB or whatever the device has spare) of unused space that would otherwise be in the image.

I have seen advice in many places that dd should not be performed on a mounted partition and I followed that because it seems intuitively correct; it does seem rather like trying to sketch yourself making a sketch in a mirror with the sketch you're making also visible in the sketch.

It's a bit sketchy. After trying multiple different methods, I found the following article:. It's created to shrink and resize (on first boot) a raspberry-pi image but could be easily adjusted for any other Linux distribution. I successfully got it working with Debian 9 on a custom arm based chip.

The rc.local created by the pishrink script first uses raspi-config to resize the rootfs and then falls back to a method using parted (which I had to install ahead of time on my machine). I commented out the section of code where raspi-config. My sd-card image was shrunk from 15 GB to 1.1 GB. I flashed the shrunk sd-card image with etcher.

Took less than 5 mins as opposed to over half an hour for the full 15 GB image. If you have a big SD card 16 GB, 32 GB etc but you want to save space with backup you can use:. Open disk utility to check witch letter is your usb drive actually has:.

In my case a 32GB SD card with Raspbian image on it recognised as: /dev/sde.

Free Tool to Create Image from SD Card for Windows 11/10/8/7

So I run with /dev/sde:. Output: 20190529_rpi_image_backup.gz . And the size is only 3.5GB.If you want to write this image to a new SD card use:. Also you can write this image made from 32 GB to a 16 GB or 8 GB disk, it is not complaining that the image is too large anymore.

Plug in bootable Ubuntu persistent live USB with image file in usbdata partition into Single-Board Computer such as UP² Board. Boot to USB (default persistent live option).Launch Terminal and type in the following command (single line):. Wait 15-20 minutes. When completed, shutdown and disconnect USB.Boot to internal eMMC drive.

DD on Windows

Create uncompressed sparse image file from internal eMMC and save to flash drive. Extract uncompressed image file to internal eMMC. Create compressed image file from internal eMMC and save to Desktop.

  • Extract compressed image file to internal eMMC.
  • To determine the offset for your image or drive, run:.
  • Then, multiply block-size of 512 bytes by the start-block of the Linux partition, 1050624.
  • 512*1050624 = 537,919,488. Also mount other system folders:.
  • Then cd into root folder of img and chroot:.
  • Then you can update files, passwd, etc. To unmount, run:. Creating Ubuntu Persistent Live USB ImageFollow these steps to flash a USB drive with a persistent live installation of Ubuntu:
  • My solution to make an image of a customized raspios:.

The Need to Make Image of SD Card

11 gold badge1313 silver badges1313 bronze badges. 1313 bronze badges. Creating an entire image of your SD card can be really useful on Raspberry Pi.

  • The system and your data are on this little piece of plastic, which isn’t the safest :).In this tutorial, I’ll show you how to make a full backup copy of your SD card (system, configuration and data).
  • For a Raspberry Pi with many data or even critical data, it’s a good practice to create an image of the entire storage.On Windows, Win32 Disk Imager is the best tool to do this.On Linux, the dd command can do this.
  • And on macOS, ApplePi Baker is the best choice for a graphical solution.
  • Here it is for the short answer, but these tools are not easy to use for the first time.
  • So, in this guide I’ll show you step-by-step how to do in each case.But before that, we’ll start by a short explanation on why it’s so important to do this from time-to-time, if you aren’t sure yet.
  • If you are looking to quickly progress on Raspberry Pi, you can check out my e-book here.

Create an image on Linux

  • It’s a 30-day challenge, where you learn one new thing every day until you become a Raspberry Pi expert.
  • The first third of the book teaches you the basics, but the following chapters include projects you can try on your own.
  • Download the Pi Glossary!If you are lost in all these new words and abbreviations, request my free Raspberry Pi glossary here (PDF format)!
  • If you are on this page, there is a good chance you already know why you want to create an image of your Raspberry Pi.But you may not have considered all benefits of this procedure.

How to Make an Image of an SD Card in Windows

Below is a quick list of reasons or cases to help you. The first thing to consider is the storage you are using on Raspberry Pi.As your system and critical data are on a micro SD card, don’t expect to keep years for life in the same state. The lifespan of a SD card is expected to be 10 years or more. But, this mostly depends on the model, the usage and how you handle it daily. Even if you use the best SD card with your Raspberry Pi, it may still happen.If you use your SD card with caution, always in the same device, with a low disk usage on your Raspberry Pi, it could have a long lifespan.

Create an image on Windows

But if you change devices regularly, travel a lot or let your Raspberry Pi run on heavy load all day, it probably won’t. Also, your system may be corrupted one day, due to updates, security breaches or mishandling. In short, don’t expect your SD card to work forever, and anticipate a malfunction at anytime. Basically, I never expect a storage method to be 100% safe.That’s why I recommend doing regular backups of them if you keep critical data on your card.

  • I already have an entire guide on how to back up your Raspberry Pi.And today, we’ll see how to clone the entire SD card on your computer.This is the best way if you have a lot of critical or important data.
  • Raspberry Pi BootcampSale: 10% off today.Take it to the next level.I'm here to help you get started on Raspberry Pi.Learn all the skills you need in the correct order.
  • By the way, even if you have a retro gaming solution like Retropie on it and think you don’t need to be concerned, think again.
  • If there is a huge catalog of games on your Raspberry Pi, I really recommend backing up your SD card :).

Which disk

A copy on your computer or on an external drive (I recommend this one) will be worth it if you spend a lot of time on your Pi.

Small anecdote here, when I started on Raspberry Pi, I tested 5 to 10 new projects each week (while writing my experiences on RaspberryTips).SD card preparation, update and configurations (like Wi-Fi and keyboard layout) was a waste of time for me. My solution was to create a basic Raspbian installation on a small SD card, and create an image on my computer.This way, I could flash this image instead of the one from the Raspberry Pi Foundation and everything would be ready to use.

I have learned a lot and generally use the configuration files to do this.

Making the image

  • I have the files on my computer, and I copy them to each SD card I flash (you can learn how to do this in this article).
  • In the beginning this was very useful.Even so, there are probably many cases where it makes sense to do this (cluster?
  • Multiple web servers? Many Raspberry Pi deployment?).
  • As most of you are generally on Windows, let’s start with this system.
  • Win 32 Disk Imager is a well-known tool on Windows for Raspberry Pi And Linux users.It’s often used to create SD cards (or USB disk) from an image of an operating system downloaded on the Internet.

Making an image file from an SD card on Windows

  • You can download it here on SourceForge.It looks like this:. But the goal today is the opposite: creating an image from an SD card.Win 32 Disk Imager can also do this, let’s see how!
  • Here are the steps to follow to create an image of any SD card on Windows, with Win 32 Disk Imager:.
  • Insert your SD card in your computer.If you don’t have an SD card reader on your computer, you’ll need a USB adapter for this (I explain everything here).
  • Find the partition letter corresponding to your SD card: Open the File explorer and go to “This PC”.Take note of the drive letter, you’ll need it later.

Win32 Disk Imager

  • Open Win 32 Disk Imager. Start by choosing an image location and name for your image:Make sure to have enough free space on your disk where you want to store the image (a 64 GB SD card can quickly fill a SSD disk ^^).You can use a local storage, or an external USB drive.
  • Then select the device you want to back up:You’ll typically only see the “boot” partition, but don’t worry, Win32DiskImager will create an entire image of all partitions on the device. You can now click on “Read” to start the copy:.
  • The process will start and it can take some time depending on your SD card size (between 15min and 1h in general for a standard size):.
  • Once done, your image is safe, and we’ll now see how to flash it on another card. I recommend doing at least one test to recover the SD card from this image before considering you are safe.I have had too many backups in my life that didn’t work when needed, so we can never be sure if a backup will work in real conditions :). What you can do, is insert another SD card in your computer and flash it with the image.To do this, you can use Win32 Disk Imager almost the same way:.
  • Choose the image file. Pick the device letter in the list. And click on “Write” to start the copy:. If you prefer, there are other tools to do the same thing.The one I recommend everywhere on this website is Etcher.
  • You can also use Raspberry Pi Imager if you want (official software from the Raspberry Pi Foundation).

How to use “dd” to back up the SD card

By the way, you can also install Raspberry Pi Imager on RPI OS if you don’t have a computer. If you are a Linux user, let’s see how to do this on your favorite system!I’ll show you on Ubuntu, but the tool is the same on any distribution. “dd” is a base command on Unix. The goal is to offer a tool to manage files.You can use it to erase a partition (filling it with zeros), generate a random file, but also to manage disk images!I’m also using it for benchmarks (like in this post about SD cards).

Master your Raspberry Pi in 30 daysSale: 10% off today.Download the eBook.Uncover the secrets of the Raspberry Pi in a 30 days challenge.Learn useful Linux skills and practice multiples projects.

As dd can do a complete backup of any disk, it’s really useful for this.Let’s see how to use it! Are you a bit lost in the Linux command line? Check this article first, for the most important commands to remember, and a free downloadable cheat sheet so you can have the commands at your fingertips.

Looking for the drive letter on Windows is pretty easy, but on Linux it’s a bit more hidden.A device name on Linux is something like /dev/sdX (if you use an USB adapter), or /dev/mmcblkX (if your computer has an SD card reader).

A solid backup is mandatory

  • On Ubuntu, you can use the Disk Utility to find this information:. I’m using a 16 GB SD card for this test, so this is this one (/dev/sde).If you aren’t on Ubuntu and can’t find a similar tool, you can also jump to the terminal and use the following command:sudo fdisk -l.
  • It will show you a list of drives on your computer.
  • You just need to find the one corresponding to your SD card.In my case, it looks like this:.
  • So, we have a disk named /dev/sde, with two partitions (/dev/sde1 and /dev/sde2).
  • Once we know the device name, we need the correct command to create the image of this device:.
  • Open a terminal. Type the following command:sudo dd bs=4M if=/dev/sde of=/home/username/MyImage.img. Don’t forget to replace the device name (if for input file) and the file destination (of for output file).
  • You’ll get something like this:Expect at least 15 minutes to create the image (depending on the SD card size).

Image restoration to the SD card

  • Note: In any command I give you with “dd”, you can add the option status=progress to see the transfer statistics.
  • Example:sudo dd bs=4M if=/dev/sde of=/home/username/MyImage.img status=progress.
  • Copying back the image to another SD card is almost the same thing.I recommend trying this at least one time, just to be sure that your image is working (don’t try on the same SD card!).
  • To copy an image to a new SD card, there are two ways you can use:.
  • The first one is to use dd again, in the reverse order:The command is something like:sudo dd bs=4M if=/home/username/MyImage.img of=/dev/sdeFor the first time, you need to edit this command with the correct path, image name and device name.
  • The command is something like:sudo dd bs=4M if=/home/username/MyImage.img of=/dev/sde. For the first time, you need to edit this command with the correct path, image name and device name.
  • The second way, that I always recommend is to use Etcher:Etcher is a free tool you can download here.The good news is that it’s a graphical tool and very intuitive.The dd command seems simple now because you just used it to create the image, but in 6 months, you probably won’t remember the correct options.The tool looks like this:Just select your backup image, your drive (automatic in theory), and click on “Flash!” to start the copy.

First method: use dd

  • Etcher is a free tool you can download here.The good news is that it’s a graphical tool and very intuitive.The dd command seems simple now because you just used it to create the image, but in 6 months, you probably won’t remember the correct options.
  • The tool looks like this:Just select your backup image, your drive (automatic in theory), and click on “Flash!” to start the copy.
  • Whatever the method you use, it should create an exact replica of the original SD card.Once done, insert it in your Raspberry Pi and check that everything is working correctly.
  • The last operating system is macOS.I will be quick on this tutorial, as I didn’t test because I don’t have a Mac :).But I know they are working methods to create an image from your Raspberry Pi.
  • The first method is to use “dd”, like in the previous part for Linux.As macOS is based on Unix, dd is also available on it.
  • Just run a terminal and follow the Linux part :).The only thing to change is to replace “sudo fdisk -l” with “diskutil list” because fdisk is not working exactly the same way on macOS….
  • Master Python on Raspberry PiSale: 10% off today.Get the eBook.Do more with your Raspberry Pi, learn the useful concepts and take the shortcuts.You miss half of the fun of using a Raspberry Pi if you don’t know anything about Python.

Restoring the image to any SD card

  • If you prefer a graphical tool, I found ApplePi Baker that seems to do exactly what we need.You can download it here on Tweaking4All.Scroll down to the ApplePi-Baker V2 download link, get it and install it:.
  • The tool looks like this:. It’s intuitive, with big symbols for each step.Start by choosing the disk you want to back up on the left, then click on “Backup” to set the image name and location.Once done, the process starts, and your image is created as with dd.
  • As on any operating system, it’s mandatory to try your backup at least once before considering the job done.What you can do, is to take a new SD card and flash the image to it, then test it on your Raspberry Pi.
  • I already explained in the Linux part two ways you can use: dd and Etcher.

Second method: try ApplePi Baker

They will work perfectly on macOS.If you want to use these tools, go to the previous part about Linux and find the “Image restoration” section. The other way if you installed ApplePi-Baker, is to use the “Restore” option on the right.Pick the disk you want to flash (“1” on my picture), and click on “Restore” to select the image to copy.The process will starts immediately.

The dd command

After a few minutes, try to boot this SD card on your Raspberry Pi, and see how it goes.

Step-by-step image creation with Win32 Disk Imager

If everything is OK, you can consider your backup safe.Redo the same process regularly to keep an updated version of the image (if needed).

Getting Started with the Raspberry Pi Zero Wireless

Reminder: Remember that all my Patreon supporters get access to this website without ads, early access to my videos and much more.

Getting Started with the Autonomous Kit for the Sphero RVR

You can become part of this community for as little as $3 per month & get all the benefits immediately. You may also like:. Get My Cheat Sheet!Grab your free PDF file with all the commands you need to know on Raspberry Pi!

That’s it, you now know why you should create an image of a Raspberry Pi, and how to do so on any operating system.I hope this guide was useful for you, if it’s the case, please share it on your favorite social network!

MicroSD Shield and SD Breakout Hookup Guide

Don’t forget this technique, even if you don’t need it yet. It will save you a lot of time in the future if you remember to create images for your most critical systems.By the way, try to keep the image at a safe location too (or keep two copies), your computer disk can also break or be formatted :).

MP3 Player Shield Hookup Guide V15

A good external hard drive (my favorite is this one on Amazon) is probably a good option to consider.

MicroSD Breakout With Level Shifter Hookup Guide

Personally, I’m using a NAS at home for all these backups (this one from Synology), but that’s a bit more expensive.

OpenLog Hookup Guide

Not sure where to start?Understand everything about the Raspberry Pi, stop searching for help all the time, and finally enjoy completing your projects.Watch the Raspberry Pi Bootcamp course now.Master your Raspberry Pi in 30 daysDon’t want the basic stuff only?

If you are looking for the best tips to become an expert on Raspberry Pi, this book is for you.

Hardware Hump Day: Cloning your Raspberry Pi

Learn useful Linux skills and practice multiple projects with step-by-step guides.Download the e-book.VIP CommunityIf you just want to hang out with me and show your support, you can also join the Patreon community.