1 2 Previous Next 17 Replies Latest reply on Mar 27, 2016 5:52 AM by xbolshe

    How to boot Edison from an SD card (Linux)

    MPayne

      The following is a guide that was written by AlexT_Intel during the time we were working on release 2 at Intel.  It was adapted from some internal projects we were playing around with, and we'd like to share it with the community.  Let me know if there are any typos or technical issues; it has been gone through pretty extensively, but there's always a chance an error still lives.  Thank you Aleksandr for adapting this guide, and I hope those of you who are interested find it useful as well.


       

      Boot with rootfs on external storage


      This article describes a way to boot an Edison board with the Root Filesystem on an external storage (SD card or USB stick). The kernel and bootloader remain on the local eMMC. For now, we are not able to boot a kernel from an external storage. The article assumes certain level of familiarity with Linux and file systems.


      Prepare External Storage


      You need to have a SD card or USB stick formatted with ext4 file system to store your root file system (do not use FAT/FAT32 for that).


      1. On your desktop computer with Linux installed, using GParted (http://gparted.org/), format your SD card using ext4 filesystem. If you only have a Windows system, then easiest approach would be to prepare a bootable USB stick with GParted Live USB image (see instructions on their website on how to do that).
      2. Download and unpack the Edison OS image from the Software Downloads section of the community (Edison - Software DownloadsIntel® Edison Boards and Compute Modules — Software Downloads). In the unpacked directory (with the "flashall.sh" script) run the following commands to prepare the SD card. They mount the Yocto-generated .ext4 rootfs image and copy the contents onto the SD card (be sure to be root to do that). If you are using Windows machine, copy that image file to the USB stick during its preparation.

       

        user@linux:~/Downloads/unpacked-image$ ls

      dnx_fwr_saltbay_pr2.bin     edison_ifwi-dbg-02-dfu.bin  edison-image-edison.ext4    package-list.txt
      dnx_osr_saltbay_pr2.bin     edison_ifwi-dbg-03.bin      edison-image-edison.hddimg  pft-config-edison.xml
      edison_dnx_fwr.bin          edison_ifwi-dbg-03-dfu.bin  filter-dfu-out.js           pft-config-mcg_sku.xml
      edison_dnx_osr.bin          edison_ifwi-dbg-04.bin      flashall.bat                u-boot-edison.bin
      edison_ifwi-dbg-00.bin      edison_ifwi-dbg-04-dfu.bin  flashall.sh                 u-boot-edison.img
      edison_ifwi-dbg-00-dfu.bin  edison_ifwi-dbg-05.bin      flash.log                   u-boot-envs
      edison_ifwi-dbg-01.bin      edison_ifwi-dbg-05-dfu.bin  ifwi_saltbay_pr2.bin
      edison_ifwi-dbg-01-dfu.bin  edison_ifwi-dbg-06.bin      ifwi_saltbay_pr2-dfu.bin
      edison_ifwi-dbg-02.bin      edison_ifwi-dbg-06-dfu.bin  ota_update.scr
       
      user@linux:~/Downloads/unpacked-image$ mkdir Rootfs
       
      user@linux:~/Downloads/unpacked-image$ sudo mount ./edison-image-edison.ext4 Rootfs
      [sudo] password for user:

      user@linux:~/Downloads/unpacked-image$ sudo cp -a Rootfs/* /media/8f88dd49-95ac-4d0c-8c3a-abd445f87fa1/

           3. Your SD card is now ready to boot

       

      Find out the SD card device name


      On a running Edison board, plug your formatted SD card and get the device name:

      root@edison:~# dmesg |tail -n 10
      [    6.387683] g_multi gadget: high-speed config #2: Multifunction with CDC ECM
      [    6.522733] EXT4-fs (mmcblk0p5): mounted filesystem without journal. Opts: discard,barrier=1,data=ordered,noauto_da_ac
      [    7.375959] systemd-fstab-generator[174]: Checking was requested for "rootfs", but it is not a device.
      [   10.001889] systemd[1]: Reloading.
      [   10.098201] systemd-fstab-generator[223]: Checking was requested for "rootfs", but it is not a device.
      [   20.372477] EXT4-fs (mmcblk0p10): mounted filesystem with ordered data mode. Opts: discard,barrier=1,data=ordered,noac
      [  767.952993] mmc1: new high speed SDHC card at address 0007
      [  767.953999] mmcblk1: mmc1:0007 SD16G 14.4 GiB 
      [  767.956822]  mmcblk1: p1
      [  768.275336] EXT4-fs (mmcblk1p1): mounted filesystem with ordered data mode. Opts: (null)
      root@edison:~# 
       


      Here, the SD card device is “/dev/mmcblk1” and the partition we’ve created is "/dev/mmcblk1p1".


      Boot the board using SD card


      To boot using the external device, you need to modify the U-Boot environment variable named "mmc-bootargs" with kernel boot arguments. In the simplest case you can just change the "root=..." part, but here’s a more elaborated approach, which will help you to switch between booting from eMMC and the SD card more easily.


      1. In the Edison Linux console set the U-Boot environment variables like the below:
      # the below is a single line
      root@edison:~# fw_printenv |grep mmc-bootargs=mmc-bootargs=setenv bootargs root=PARTUUID=${uuid_rootfs} rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}
      # the below is a single command line
      root@edison:~# fw_setenv mmc-bootargs 'setenv bootargs root=${myrootfs} rootdelay=3 rootfstype=ext4 ${bootargs_console} ${bootargs_debug} systemd.unit=${bootargs_target}.target hardware_id=${hardware_id} g_multi.iSerialNumber=${serial#} g_multi.dev_addr=${usb0addr}'

      root@edison:~# fw_setenv myrootfs_sdcard '/dev/mmcblk1p1'

      # get the UUID for the eMMC rootfs partition
      root@edison:~# fw_printenv uuid_rootfs
      # use the UUID obtained above
      root@edison:~# fw_setenv myrootfs_emmc 'PARTUUID=012b3303-34ac-284d-99b4-34e03a2335f4'
       
      # this will set the default, use the value we’ve used for myrootfs_emmc
      # if you want to boot from eMMC by default
      root@edison:~# fw_setenv myrootfs '/dev/mmcblk1p1'
       
      root@edison:~# fw_setenv do_boot_emmc 'setenv myrootfs ${myrootfs_emmc}; run do_boot'
       
      root@edison:~# fw_setenv do_boot_sdcard 'setenv myrootfs ${myrootfs_sdcard}; run do_boot'
      1. Reboot Edison
      2. After boot, verify that you are using rootfs stored on your external device:
      root@edison:~# df -h
      Filesystem                Size      Used Available Use% Mounted on
      /dev/root                14.1G    335.5M     13.1G   2% /
      devtmpfs                480.2M         0    480.2M   0% /dev
      tmpfs                   480.5M         0    480.5M   0% /dev/shm
      tmpfs                   480.5M    500.0K    480.0M   0% /run
      tmpfs                   480.5M         0    480.5M   0% /sys/fs/cgroup
      tmpfs                   480.5M    500.0K    480.0M   0% /etc/machine-id
      systemd-1                 5.5M      5.1M    464.0K  92% /boot
      tmpfs                   480.5M      4.0K    480.5M   0% /tmp
      systemd-1                 2.2G      3.6M      2.2G   0% /home
      tmpfs                   480.5M         0    480.5M   0% /var/volatile
      /dev/mmcblk0p5         1003.0K     19.0K    913.0K   2% /factory
      /dev/mmcblk1p1           14.1G    335.5M     13.1G   2% /media/sdcard
      /dev/mmcblk0p10           2.2G      3.6M      2.2G   0% /home
      /dev/mmcblk0p7            5.5M      5.1M    464.0K  92% /boot

      root@edison:~# 

      The root file system is now 14.1 GB (this will depend on your SD card size).


      Remarks


      The above tutorial is an example. The naming of your device may change. After executing the steps above and booting the board with external rootfs successfully, you may want to tweak your system in order to have a more usable board:


      1. The /home will still be mounted from eMMC after booting, and it’s limited to ~2.2 GB. To use the SD card for /home as well, you should disable mounting this partition by removing the last line of the /etc/fstab (the line concerning home mounting).
      2. The SD card will still be automounted to /media/sdcard by Edison’s automount daemon. Since it is the rootfs anyway, this mountpoint becomes useless, so disable the systemd service:
      3. Now, you have plenty of room to work on Edison and no unnecessary mounts:
      root@edison:/etc/systemd# systemctl stop media-sdcard.mount
      root@edison:/etc/systemd# systemctl disable media-sdcard.mount
      rm '/etc/systemd/system/default.target.wants/media-sdcard.mount'
      root@edison:/etc/systemd# df -h
      Filesystem                Size      Used Available Use% Mounted on
      /dev/root                14.1G    343.5M     13.1G   3% /
      devtmpfs                480.2M         0    480.2M   0% /dev
      tmpfs                   480.5M         0    480.5M   0% /dev/shm
      tmpfs                   480.5M    492.0K    480.0M   0% /run
      tmpfs                   480.5M         0    480.5M   0% /sys/fs/cgroup
      tmpfs                   480.5M    492.0K    480.0M   0% /etc/machine-id
      systemd-1                 5.5M      5.1M    464.0K  92% /boot
      tmpfs                   480.5M      4.0K    480.5M   0% /tmp
      tmpfs                   480.5M         0    480.5M   0% /var/volatile
      /dev/mmcblk0p5         1003.0K     19.0K    913.0K   2% /factory
      /dev/mmcblk0p7            5.5M      5.1M    464.0K  92% /boot
       
      root@edison:/etc/systemd# 
        1 2 Previous Next