Creating SD card image in Linux
Posted: Sat Jan 21, 2017 9:18 am
I have been working on a project involving reading data from the SD card, but I wanted to be able to be able to test the game in an emulator even after moving the game data to the SD card. This requires having an SD card image to give to the emulator. I wanted to create the SD image in Linux and had to do a little searching before I found the solution, and I thought I might share it here to spare anybody else the effort. It's actually quite easy, and it doesn't require installation of any software.
After plugging in the SD card by USB, you have to figure out which device it is. I found this out by going to /dev/disk/by-id, searching for an id with a name that had "usb" in it, and then running the "file" command on that id (which is a file that is a symbolic link to the device we want. I suppose I could have used this file directly, now I think of it). It should say something like "/dev/disk/by-id/<name>: symbolic link to `../../sdb'". For me it was sdb. Once you know this, it's easy. Just run
One thing I had been trying to do before this is create an image from scratch, but I couldn't find a simple way to do this without downloading something. If anybody has an idea of how to take a zip full of files and convert it to an image, that would be cool. I know somehow the image needs to have a FAT filesystem, so I was wondering if there was some elegant way to create a filesystem image formatted to just the size to only hold the files inside it. Right now the image is 128 MB, since it's an image of the 128 MB SD card.
After plugging in the SD card by USB, you have to figure out which device it is. I found this out by going to /dev/disk/by-id, searching for an id with a name that had "usb" in it, and then running the "file" command on that id (which is a file that is a symbolic link to the device we want. I suppose I could have used this file directly, now I think of it). It should say something like "/dev/disk/by-id/<name>: symbolic link to `../../sdb'". For me it was sdb. Once you know this, it's easy. Just run
- Code: Select all
sudo dd if=/dev/sdb of=~/sd-card-image.img conv=notrunc
One thing I had been trying to do before this is create an image from scratch, but I couldn't find a simple way to do this without downloading something. If anybody has an idea of how to take a zip full of files and convert it to an image, that would be cool. I know somehow the image needs to have a FAT filesystem, so I was wondering if there was some elegant way to create a filesystem image formatted to just the size to only hold the files inside it. Right now the image is 128 MB, since it's an image of the 128 MB SD card.