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
  • 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
Pi IoT
  • Challenges & Projects
  • Design Challenges
  • Pi IoT
  • More
  • Cancel
Pi IoT
Blog PiIoT - DomPi 07: Setting up the Command Center (2)
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Events
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: mg.sergio
  • Date Created: 11 Jul 2016 9:05 PM Date Created
  • Views 638 views
  • Likes 2 likes
  • Comments 2 comments
  • piiot
  • piiot challenge
Related
Recommended

PiIoT - DomPi 07: Setting up the Command Center (2)

mg.sergio
mg.sergio
11 Jul 2016

In this post I continue with the initial setup of the Command Center. I will focus on how to boot from a USB drive and avoid card corruption (EDIT: the openHAB installation will be done in an addtional post with the Mosquitto installation as well). But first, the links to previous posts and the project status.

 

Previous Posts

PiIoT - DomPi: ApplicationPiIoT - DomPi: IntroPiIoT - DomPi 02: Project Dashboard and first steps in the Living room
PiIoT - DomPi 03: Living room, light control via TV remotePiIoT - DomPi 04: Movement detection and RF2.4Ghz commsPiIoT - DomPi 05: Ready for use Living Room and parents and kids´ bedrooms
PiIoT - DomPi 06: Setting up the Command Center - RPI3

 

Project Status

image

Setting up the RPI3 to boot from a USB Drive

The first question to answer is, why would I want to boot from a USB Drive?? Well, as many nice things, you come across them via the hard way... The SD cards are very good for quickly storing and accessing data, however, they are not designed to write on them constantly. There is a physical limitation and after some hundreds or thousands of times that you write on the same physical part of the card, this part loses its capability to store data. The effect is that whatever you write there, you lose it, producing SD card corruption. The effect? you will need to get another SD card and if you were cautious enough, recover any backup you did in the past - hopefully recent past...

 

There are different approaches to avoid SD corruption or at least to minimize its effect, making the SD card last longer: avoid the graphical interface and use only the command line, move to RAM parts of the OS storage, reduce the number of logs and how frequent they are updated, allow plenty of free space, etc, etc. All this has some disadvantages. I have come across another solution, to move most of the OS to a USB Hard Disk. Since the HD are prepared to frequently writing, they last longer. So far I have had 2-3 SD cards corrupted by no HD corruption.

 

A couple of notes. For the RPI2, technically speaking you don't boot from a USB Drive. The RPI would always require a SD card with the boot partition to actually boot. By modifying a line in the configuration, then it'd refer to the USB drive to continue with the OS boot up. So in fact you still required the SD card and the USB drive, being the advantage that the SD card wouldn't get corrupted since the heavy writing process performed by the OS happens on the USB drive. The second note is about the RPI3. It seems that the hardware does allow direct booting from a USB drive as well as from the network, however, there is not yet support for doing so. More info here. So all in all, the SD card is still required for the RPI3 but this may change in the coming months.

 

The process looks as follows:

  1. Flash the USB Hard Drive. In my case I don´t currently have any HDD free at home so I will be flashing a 32GB USB pendrive. The pendrives suffer the same as the SD cards with continuous rewrites, but hope that being 32GB it won´t suffer that much and in any case I will move the data to a HDD as soon as I can.
  2. Modify the SD card file to redirect to the USB once the RPI has booted up
  3. Test and clean up

 

Flashing the USB

Two things to note. Your USB drive will be completely deleted and you will lose any info it was on it as well as any partition it had. The second is that, since I will be flashing a 16GB image, I will need to extend the partition once finished to recover the 16GB remaining until the 32GB size of the pendrive.

I will follow the same steps as when I did the initial back up in PiIoT - DomPi 06: Setting up the Command Center - RPI3. And then I will flash the newly created image to the USB. Before flashing the USB you will probably need to unmount the partition - if there was any there. I did so by using the Mac "Disk Utility" app and clicking on the partition: on the left hand side menu you will find the drive "USB Flash Drive Media" in my case, and hanging from it the existing partition(s). Click on them and then click on unmount.

 

The commands for backing up and flashing are, as a reminder:

sudo dd if=/dev/rdisk1 bs=1m | gzip > ~/Desktop/pi.gz  
gzip -dc ~/Desktop/pi.gz | sudo dd of=/dev/rdisk2 bs=1m 

The second line points at /dev/rdisk2 that is the destination device where I have the pendrive. These lines will take loooong.

 

Modify the SD card

In order to tell the bootup process where to find the required filesystem to continue launching Raspbian, I need to modify a file. Before plugging the SD card into my Mac, let's identify what is the USB folder in the RPI. To do so, plug the pen drive to the RPI now and run the command:

 

pi@dompi:~ $ df
Filesystem     1K-blocks    Used Available Use% Mounted on
...                  ...
tmpfs               5120       4      5116   1% /run/lock
tmpfs             474028       0    474028   0% /sys/fs/cgroup
/dev/mmcblk0p6     64366   19980     44386  32% /boot
tmpfs              94808       0     94808   0% /run/user/1000
/dev/sda7       13801392 3494756   9582568  27% /media/pi/root
/dev/sda6          64366   19962     44404  32% /media/pi/boot
/dev/sda5          30701     449     27959   2% /media/pi/SETTINGS
/dev/mmcblk0p5     30701     449     27959   2% /media/pi/SETTINGS1

you can see there that /media/pi/root is under /dev/sda7. We will add this to the cmdline file later. If you plan to have more USB drives connected, the approach I'm sharing here probably won't work and you need to look for the UUID to specify it. More info here. This "quick" approach shall be ok for DomPi though.

 

So I plug the SD card into my Mac. The SD card has three partitions, the boot, Recovery and the actual partition with the files. In the boot partition I will modify the /boot/cmdline.txt. Currently it has this single line

 

dwc_otg.lpm_enable=0 console=ttyAMA0,115200 console=tty1 root=/dev/mmcblk0p7 rootfstype=ext4 elevator=deadline fsck.repair=yes rootwait

 

And replace what says "/dev/mmcblk0p7" by "/dev/sda7". Note that sda7 is what I found out using the df commandMore details here and here.

 

Test and clean-up

I put both the SD card and the USB pendrive into the RPI and power it on. If all goes fine, this still may not be working image it may happen we did not change the cmdline.txt file. So if it works, then you turn it off, take out the USB and power it on again and it does not work... You can be sure that it is booting from the USB! Congratulations. Now, we can clean up the drives. The USB contains a partition called /boot that we can just delete - it is just 66MB but... In the SD card, you can as well delete any partitions that are not the /boot one.

 

The last part would be to resize the main partition so that I don't lose the 16GB as said before. I will postpone this action to focus on DomPi and work on more features. In any case, the resizing can be done with GParted or via the command line.

 

Node´s Dashboard

image

  • Sign in to reply

Top Comments

  • DAB
    DAB over 9 years ago +1
    Another nice update. It looks like you are making good progress. DAB
  • mg.sergio
    mg.sergio over 9 years ago in reply to DAB

    Thanks DAB.

     

    Re progress... sometimes you expect to hit issues and surprisingly all goes flawlessly and sometimes is just the opposite and you encounter delays in the "easy" parts. In this update, the sda7 thing caught me by surprise and spent longer time than expected to figure out why the RPI was not booting up until I found the issue - in my previous RPI2 it was either sda1 or sda2 so I did not pay enough attention to this part until the n-th go.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • More
    • Cancel
  • DAB
    DAB over 9 years ago

    Another nice update.

     

    It looks like you are making good progress.

     

    DAB

    • Cancel
    • Vote Up +1 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 © 2025 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