Tools for handling files as 'virtual' SD-card

While playing around with an new arm-board I had the need to create image files that can be flashed to a SD-card later. Usually people create the environment (partitions and file-systems) on a real device. Cards are read to an image file when ready.

I created two scripts which avoid involving the real device. One script (mksdimage) creates an image, the other (mountsdimg) can mount the partitions inside the image.


mksdimage <image file> <fs-type,size in MB,label> <fs-type,size in MB,label> ...

Arguments to mksdimage are:

  • The image file (e.g. sd.img)
  • Following are the partitions to be created, properties of one partition are separated by commata (all mandatory)
    • fs-type: Use the names which can be found in man parted (e.g. fat32, ext2, ext3, ext4, linux-swap)
    • size of partition in MB
    • name of the partition

Example: Create an image (size: 1 GB) with a 'BOOT'-partition (size: 100MB), the root file-system (size: 800MB) and a swap partition (size: 100 MB)

mksdimage sd.img fat32,100,BOOT ext3,800,rootfs linux-swap,100,swap


mountsdimg <image file> <mount-point prefix>

Example: Mount an image file (e.g. one fat32 and one ext3 partition inside)

mountsdimg sd.img sd

Will create two directories, sd1 and sd2, and mount the in-file partitions to that places.This may be the result:

ls -l sd*
insgesamt 879792
drwxr-xr-x 2 root root 16384 1. Jan 1970 sd1
drwxr-xr-x 3 root root 4096 25. Aug 19:56 sd2
-rw-r--r-- 1 root root 900000000 25. Aug 20:28 sd.img

The script keeps running and will ask what to do next. You can choose either let the script unmount the partitions again (using this in a separate window makes life easier). Otherwise you have to do it yourself.

Mounting in sd. Do you want to unmount now (Y/n)?


Please find the scripts attached.

Download SD-card image file tools.

If you have any questions or comments you can use the form below.

Geben Sie einen Kommentar ab


  • Could you please advise how to update your mountscript so it will also provide the filesystem type (seems to be required)?

    "mount: you must specify the filesystem type"

    Erstellt von Lucas, 23/02/2015 4:01pm (vor 4 Jahre)

RSS Feed für die Kommentare auf dieser Seite | RSS feed für alle Kommentare