element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
    About the element14 Community
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      •  Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
RIoTboard
  • Products
  • Dev Tools
  • Single-Board Computers
  • RIoTboard
  • More
  • Cancel
RIoTboard
Blog Linux on the RIoTBoard Part 5: SDCard Image
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join RIoTboard to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: radiatortwo
  • Date Created: 19 Sep 2014 10:43 AM Date Created
  • Views 3107 views
  • Likes 1 like
  • Comments 16 comments
Related
Recommended

Linux on the RIoTBoard Part 5: SDCard Image

radiatortwo
radiatortwo
19 Sep 2014

This series of blog posts contains the following parts:

1. The bootloader U-Boot

2. The Kernel

3. Debian Root File System

4. Flashing with MFGTool in Windows

5. Creating an SDCard image (This part)


Part 5: SDCard Image


This is the last part of this series.

Here we will create an image that we can use to flash directly on an SDCard we then can boot from.


This is for those who don´t use Windows with MFGTool, but wan´t to use Linux to flash our created system.


There are different methods to achieve this.

One is creating an image from an already flashed system on the RIoTBoard onto an SDCard.

Not really an option since we then would need our system already flashed, which we don´t have.


The second method would be that we use an SDCard reader that´s connected to our building system.

And then do the same steps as MFGTool would do to flash it in Windows.


The other one is, that we create a virtual image file on our building system and mount it as a virtual disk.

And then also do the same steps as MFGTool would do to flash it in Windows.


Since both methods are almost the same and virtual machines often have problems with USB passthrough or like me having no physical access to the building system at all, we´re doing the third method here.


If you have an SDCard reader connected to your build system, you can skip to Step 5.


So let´s get started.


What you need are the previously created files.

- u-boot.imx

- boot.scr

- linux-kernel.tgz

- oneiric.tgz


Step 1:

These additional packages are not essential for this. But they make it a lot easier to create the image.

 

apt-get install qemu-utils kpartx

 

Step 2:

Choose a place where to store the image file.

Since all the files we need for this are stored in one folder let´s do it there.

 

cd /home/riotboard/linux/output

 

Now we will create the image file.

You could use dd for this, but with the qemu-tools it´s a bit easier.


But what size should the file be?

Most 4 GB SDCards have about 3.7 GB of usable space.

So that should be the size right?

Well but what if we want to actually copy the image from our SDCard onto the RIoTBoards eMMC?

Looking at that it only has 3.6 GB of usable space.


So we will create an image file with 3600 MB.

 

 

qemu-img create sdcard.img 3600M

 

So if we now do this...

 

ls -lh sdcard.img


... we see the file is exactly 3.6 GB in size.

-rw-r--r-- 1 root root 3,6G Sep 18 23:21 sdcard.img


Step 3:

Now we need to partition the file.

Looking at our script we are using in MFGTool we find a simple little command that does the trick.


sfdisk --force -uM sdcard.img << EOF
10,,83
EOF

 

Step 4:

Now that we have a file we can use, we need to format the partition inside.

But how? It´s still only a file.

Well that is done through a mapping of a loopback device onto a specific part of the file.

Normally we would do this manually by executing something like "losetup -o 32256 --sizelimit 5160448 /dev/loop1 sdcard.img".

But then you would have to calculate that offset and the sizelimit for every partition you created.

And if you´re using several partitions that can be a real pain in the ass.

 

Luckily I´ve found a little tool that does that for us completely automatic.

And that´s kpartx.

All we have to do is this.

 

kpartx -av sdcard.img

 

After execution you see a line like this.

add map loop0p1 (253:0): 0 7148925 linear /dev/loop0 16065

If we had more than one partition we´d see more lines. One for every partition.

The interesting part here now is the mapping loop0p1.

 

Step 5:

We now have our device and will format and then mount it.

(If using an SDCard reader, replace /dev/mapper/loop0p1 with your device /dev/sdb or whatever it is recognized with from this point on.)

 

mkfs.ext4 -j /dev/mapper/loop0p1
mkdir -p /mnt/sdcard
mount -t ext4 /dev/mapper/loop0p1 /mnt/sdcard

 

Step 6:

Now that the partition is mounted we can extract our file system, as well as the kernel and the modules.

Also we copy the bootscript into place.

 

tar --numeric-owner -C /mnt/sdcard -zxvf oneiric.tgz
tar --numeric-owner -C /mnt/sdcard -zxvf linux-kernel.tgz
cp boot.scr /mnt/sdcard/boot.scr

 

Step 7:

Unmount the partition and then remove the loopback mapping again with kpartx.

 

umount /mnt/sdcard
kpartx -dv sdcard.img

 

Step 8:

Now we need to integrate u-boot into the file.

That can be done with dd. But if we do it just like in MFGTool we will only overwrite the file and all the stuff we´ve done so far would be gone.

So we have to do it like this.

 

dd if=u-boot.imx of=sdcard.img bs=512 seek=2 conv=notrunc

 

With "conv=notrunc" at the end, we tell dd to only overwrite the beginning of the file and leave the rest as is.

 

Let´s check if that worked.

 

ls -lh sdcard.img

 

If everything went right, the image file should still be 3.6 GB in size.

-rw-r--r-- 1 root root 3,6G Sep 18 23:52 sdcard.img

 

Now the image is done and ready to flash onto an SDCard.

 

Of course if we want to copy or download it we don´t want such a big file.

So let´s pack it into a zip file.

 

zip RiotboardLinux3.17SD.zip sdcard.img

 

And that´s it.

You now can flash the file with dd like this onto an SDCard.

 

dd if=sdcard.img of=/dev/sdb bs=4K

 

Or with Windows you can use a tool like Win32 Disk Imager to write it onto your SDCard.

 

Then put the SDCard in your RiotBoard.

Set the Dip Switches to 2,4,5,7 Off rest On for a normal SDCard or for the Micro SDCard to 2,4,5,8 Off rest On.

 

And that´s it for this series.

Hope you enjoyed this and are now able to create your own Linux system for the RIoTBoard.

  • Sign in to reply
  • radiatortwo
    radiatortwo over 11 years ago in reply to kylemills

    Sorry but I can´t reproduce your problem.

    Did try it with an micro SDCard and it starts without a problem.

     

    But what I just thought of right now!!

    Do you have more than one SDCard connected? SDCard and Micro SDCard?

    And you want to boot from the Micro SDCard?

     

    The problem here right now is the following:

    As I explained in the first part of this blog series, U-Boot in this image searches first for an SDCard if it´s there it boots from it. That means if you want to boot from an Micro SDCard AND you have a normal SDCard connected, it tries to load the kernel and the rootfs from the normal SDCard.

     

    If that´s the case you can do the following:

    Connect your board with the console on the UART connection and power the board up.

    While the bootdelay counts down press return to abort.

    Type the command "printenv" to show the variables.

    In between all the stuff you´ll see a line like this:

    loadmmcdev=if mmc dev 0; then setenv mmcdev 0; else if mmc dev 1; then setenv mmcdev 1; else if mmc dev 2; then setenv mmcdev 2;fi; fi; fi

     

    This checks the devices if they are connected and if it finds one it just set´s it.

    So if you want to just load a specific device change that like this.

     

    setenv loadmmcdev setenv mmcdev 1
    saveenv

     

    Replace the number just with the device you want to boot from.

     

    0 for SDCard

    1 for Micro SDCard

    2 for eMMC

     

    Well if that´s not the case I´d need some more info what devices are connected to your board.

    Otherwise I can´t think of anything why it would give you that errors.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • radiatortwo
    radiatortwo over 11 years ago in reply to Former Member

    Great to hear that!

    I´m really glad that this helps someone.

     

    The only problem I found was that I had to install:

    apt-get install qemu-utils kpartx

    Instead of:

    apt-get install qemu-tools kpartx

    Yup  that´s right will correct that right now.

     

    I´m surprised that this was the only error you´ve found.

    But also I already corrected it a bit. image

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • Former Member
    Former Member over 11 years ago

    These tutorials are great work. They were easy to follow and explained a lot. Otherwise I would have had no idea what was going on.

     

    I have my sdcard all booted up and the system seems to work perfectly.

     

    The only problem I found was that I had to install:

    apt-get install qemu-utils kpartx

    Instead of:

    apt-get install qemu-tools kpartx


    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • radiatortwo
    radiatortwo over 11 years ago in reply to kylemills

    Hmm that´s strange.

     

    I downloaded the image myself and did test it.

    Thought I made a mistake when creating it or something.

     

    But it´s working from my SDCard.

     

    Are you sure you have set the dip switches correctly?

    In that case maybe it is loading the u-boot from your eMMC not the one from the sdcard.

     

    Also do you have an SDCard or micro SDCard.

    Didn´t test it with a micro. Will do that now.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • kylemills
    kylemills over 11 years ago

    i tried the sdcard image.

    getting below error image


     

    [1.471463] EXT2-fs (mmcblk0p1): error: couldn't mount because of unsupported optional features (4)[1.481412] List of all partitions:[1.484917] b300     7699456 mmcblk0  driver: mmcblk[1.490261]   b301     3670852 mmcblk0p1 00000000-01[1.495633] b308     3751936 mmcblk1  driver: mmcblk[1.500964]   b309        8192 mmcblk1p1 00000000-01[1.506312]   b30a     3739648 mmcblk1p2 00000000-02[1.511657] b320         128 mmcblk1rpmb  (driver?)[1.516903] b318        2048 mmcblk1boot1  (driver?)[1.522246] b310        2048 mmcblk1boot0  (driver?)[1.527569] No filesystem could mount root, tried:  ext2 vfat[1.533377] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,1)[1.541820] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(179,1)
    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2026 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube