Creating SD card image in Linux

Advice on general approaches or feasibility and discussions about game design

Creating SD card image in Linux

Postby wuuff » 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
Code: Select all
sudo dd if=/dev/sdb of=~/sd-card-image.img conv=notrunc
and enter your root password (replacing sdb with whichever device you found in the first step). It will freeze for a little while and when it's done, the image will be in your home directory! That's it!

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.
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: Creating SD card image in Linux

Postby Sorunome » Sat Jan 21, 2017 3:52 pm

Another easy way to find your device is by entering
Code: Select all
lsblk

That will display all the mass storage devices attached, including your HDD, where they are mounted to (if they are), and the size of them.

EDIT: Also, you should be able to omit `conv=notrunc`
User avatar
Sorunome
 
Posts: 629
Joined: Sun Mar 01, 2015 1:58 pm

Re: Creating SD card image in Linux

Postby frakasss » Mon Jan 23, 2017 12:36 pm

Sorry for the following stupid question, but...
How can we do this on win system?

So far, I'm just not using the emulator to test things, and that's just a bit boring to transfer everything everytime on the gamebuino...
User avatar
frakasss
 
Posts: 97
Joined: Thu Dec 11, 2014 10:20 am
Location: France

Re: Creating SD card image in Linux

Postby wuuff » Mon Jan 23, 2017 9:22 pm

Thanks for the tips Sorunome!

frakasss, Myndale gave a way to create an .img in this forum thread, but I haven't tested it myself.
wuuff
 
Posts: 61
Joined: Sun Aug 28, 2016 6:05 am

Re: Creating SD card image in Linux

Postby frakasss » Thu Jan 26, 2017 7:29 am

Thanks wuuff! I'll try it on my current dev! :-)
User avatar
frakasss
 
Posts: 97
Joined: Thu Dec 11, 2014 10:20 am
Location: France


Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 4 guests

cron