Mount Image to MicroSD

From Estone Technology Wiki
Jump to: navigation, search

Previous Section: Build Yocto Image From Scratch

Create MicroSD Image

Preparing MicroSD Card

Requirements:

  • Host Machine (Linux Ubuntu 16.04.6 LTS)
  • MicroSD Card (Minimum 8GB)
  • GParted (Filesystem Manager)

Prepare MicroSD with fdisk

1. Plug MicroSD to the host machine (Linux Ubuntu)
2. Open Terminal by pressing Ctrl+Alt+T keys in your keyboard simultaneously
3. In the terminal type in lsblk command to see what letter your MicroSD card was given
(Example: /dev/sda, /dev/sdb, /dev/sdc, etc..)

$ lsblk                                           

Lsblk-1.png


4. Locate the MicroSD card in the Storage Devices menu
Note: MicroSD letter (/dev/sd<x>) is dependent on the amount of storage devices that are connected to the host machine
Example: As shown in the image, MicroSD is located at /dev/sdc
Lsblk-hdd.png


5. Run the fdisk command to begin MicroSD Filesystem preparation

$ sudo fdisk /dev/sd<x> 

Fdisk-start.png


  • Here is a list of all available options:

Command (m for help): m 
Help:
 DOS (MBR)
  a   toggle a bootable flag
  b   edit nested BSD disklabel
  c   toggle the dos compatibility flag
 Generic
  d   delete a partition
  F   list free unpartitioned space
  l   list known partition types
  n   add a new partition
  p   print the partition table
  t   change a partition type
  v   verify the partition table
  i   print information about a partition
 Misc
  m   print this menu
  u   change display/entry units
  x   extra functionality (experts only)
 Script
  I   load disk layout from sfdisk script file
  O   dump disk layout to sfdisk script file
 Save & Exit
  w   write table to disk and exit
  q   quit without saving changes
 Create a new label
  g   create a new empty GPT partition table
  G   create a new empty SGI (IRIX) partition table
  o   create a new empty DOS partition table
  s   create a new empty Sun partition table


6. We will now create the first partition for the MicroSD

Command (m for help): n 
Partition type
  p   primary (0 primary, 0 extended, 4 free)
  e   extended (container for logical partitions)
Select (default p): p 
Partition number (1-4, default 1): 1 
First sector (2048-124735487, default 2048): 10240 
Last sector, +sectors or +size{K,M,G,T,P} (10240-124735487, default 124735487): +100M 

Created a new partition 1 of type 'Linux' and of size 100 MiB.


7. Now we will create the MicroSD second partition

Command (m for help): n 
Partition type
  p   primary (1 primary, 0 extended, 3 free)
  e   extended (container for logical partitions)
Select (default p): p 
Partition number (2-4, default 2): 2 
First sector (2048-124735487, default 2048): 215040 
Last sector, +sectors or +size{K,M,G,T,P} (215040-124735487, default 124735487): Press 'Enter' key 

Created a new partition 2 of type 'Linux' and of size 59.4 GiB.


8. Once the 2nd partition is created you need to write changes to the MicroSD card

Command (m for help):  w 
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

9. Now we will add partition filesystem type to the 2 partitions that were created

For 1st Partition:

$ sudo mkfs.vfat -n 'BOOT' /dev/sd<x>1

Mkfs vfat.png

For 2nd Partition:

$ sudo mkfs.ext4 /dev/sd<x>2
$ sudo e2label /dev/sd<x>2 ROOT

Mkfs ext4.png

Prepare MicroSD with GParted

  • GParted allows partitioning in Storage devices with GUI

1. Open the Ubuntu Software Application
Ubuntu-software-application.png


2. Search and type gparted
Gparted-search.png


3. Click the GParted icon and Install


4. Launch GParted by pressing the Launch button and wait for application to start


5. Once application has started, the GParted window will pop-up as shown in the image below:
Gparted.png


6. Choose your MicroSD selection by pressing on the Hard Drive icon and select the location where your SDCard is located
Example: /dev/sdc
Gparted-selection.png


7. Once the MicroSD card is selected press on the Partition >>> new option to create 1st partition
Gparted-partition-create.png


8. In new partition window choose the following settings and press Add to add the partition:
Free Space Preceding (MiB): 8         Create as: Primary Partition
New Size (MiB): 100            Create Partition Name: None
Free Space Following (MiB): Default     File system: fat16
Align to: MiB                 Label: Boot
Gparted-partition-1.png


9. Add 2nd partition by going to Partition >>> New, fill in the following fields and press Add to add the partition.
Free Space Preceding (MiB): 0         Create as: Primary Partition
New Size (MiB): Default           Create Partition Name: None
Free Space Following (MiB): Default     File system: ext4
Align to: MiB                 Label: Root
Gparted-partition-2.png


10. Once the partitions have been created press on the Gparted-apply.png icon to apply partitions to MicroSD


11. Wait for the partitions to successfully apply then press the Close button
Gparted-partition creation.png


12. Exit and Close gparted after partitions have been created
Gparted-finished-partitions.png

Copying Image to MicroSD

  • To copy U-boot and kernel to MicroSD card you will need to have the files in the <boot> directory with U-Boot and Kernel files created from the previous section


Note: Start at <build_dir> directory from previous section

Copy U-Boot

$ cd <build_dir>
$ cd <boot>
$ sudo dd if=flash.bin of=/dev/sdx bs=1k seek=33 status=progress && sync

Copy Kernel

$ cd <build_dir>
$ cd <boot>
$ sudo mount /dev/sdx1 /mnt/
$ sudo cp -v fsl-imx8mq-evk.dtb Image /mnt/
$ sync
$ sudo umount /dev/sdx1

Copy Root Filesystem

$ cd <build_dir>
$ cd <boot>
$ sudo mount /dev/sdx2 /mnt/
$ cd /mnt/
$ sudo tar -xvf <path-to-build_dir>/<boot>/imx8mqevk-avs-qt5-20181205182706.rootfs.tar.bz2
$ sync
$ cd <build_dir>
$ sudo umount /dev/sdx2


Note: After copying U-Boot, Kernel, and Filesystem you can safely remove the MicroSD from the host machine and connect to EMB-2238 and boot