Difference between revisions of "EBC Exercise 08 Mounting a USB drive"

From eLinux.org
Jump to: navigation, search
(Initial info)
 
m (Unmounting: Added sync's)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
{{YoderHead}}
 
{{YoderHead}}
  
Sometime it might be nice to pull some files off a USB drive and on to the Bone. Or to plug a SD card reader into the USB port so you can read files from it.
+
Sometimes it's nice to pull some files off a USB drive and onto the Bone. Or to plug a SD card reader into the USB port so you can read files from it.
  
 
Shown here is how to read from a ''ext4'' formatted device.
 
Shown here is how to read from a ''ext4'' formatted device.
Line 29: Line 29:
 
  Device        Boot Start    End Sectors  Size Id Type
 
  Device        Boot Start    End Sectors  Size Id Type
 
  /dev/mmcblk1p1 *    8192 3751935 3743744  1.8G 83 Linux
 
  /dev/mmcblk1p1 *    8192 3751935 3743744  1.8G 83 Linux
 +
 +
Here you see two "disks" are present, '''/dev/mmcblk0''' and '''/dev/mmcblk1'''.
 +
/dev/mmcblk'''0''' is the SD card and /dev/mmcblk'''1''' is the built in eMMC flash.
 +
Each have one partition, /dev/mmcblk0'''p1''' and /dev/mmcblk1'''p1''' respectively.
 +
 +
Now plug in the drive you want to read into the USB port and you'll see an additional drive appear
 +
bone$ '''fdisk -k'''
 +
...
 +
Disk '''/dev/sda''': 3.7 GiB, 3904897024 bytes, 7626752 sectors
 +
Disk model: '''SD/MMC'''
 +
Units: sectors of 1 * 512 = 512 bytes
 +
Sector size (logical/physical): 512 bytes / 512 bytes
 +
I/O size (minimum/optimal): 512 bytes / 512 bytes
 +
Disklabel type: dos
 +
Disk identifier: 0xab2c50d0
 +
 +
Device    Boot Start    End Sectors  Size Id Type
 +
/dev/sda1  *    8192 6963199 6955008  3.3G 83 Linux
 +
It is '''/dev/sda''' with partition /dev/sda'''1'''.
  
 
== Mounting ==
 
== Mounting ==
Then make a directory where you want them to appear.
+
To mount a partition you have to make an empty directory where you want
 +
the drive to appear.
  
  host$ '''mkdir bone.files'''
+
  bone$ '''cd'''
 +
bone$ '''mkdir USBdrive'''
  
The mount them. The '''192.168.7.2''' is the address of the bone.
+
Then mount them.  
'''debian''' is the login name and the ''':.''' says to use debians home directory.
+
bone$ '''sudo mount /dev/sda1 USBdrive'''
(If you've set up the shortcuts you could just use '''ssh bone:. bone.files'''.)
+
Then see what appears.
 +
bone$ '''ls USBdrive'''
 +
bbb-uEnv.txt  boot  etc  ID.txt  lost+found  mnt          opt  root  sbin  sys  usr
 +
bin          dev  home lib    media      nfs-uEnv.txt  proc  run  srv  tmp  var
 +
You should see the files on the USB drive.
  
  host$ '''sshfs debian@192.168.7.2:. bone.files'''
+
Note: You can mount any partition, so if you booted off the SD card and wanted to access the
  host$ '''ls bone.files'''
+
files on the eMMC you could:
You should see the files in debian's home directory on the bone.
+
bone$ '''mkdir eMMC'''
 +
  bone$ '''sudo mount /dev/mmcblk1p1 eMMC'''
  
 
== Unmounting ==
 
== Unmounting ==
 
When you are done run:
 
When you are done run:
  host$ '''sudo umount bone.files'''
+
  bone$ '''sync'''
 +
bone$ '''sync'''
 +
bone$ '''sudo umount USBdrive'''
 +
 
 +
The '''sync'''s are to make sure everything has been written to the drive.
  
 
{{YoderFoot}}
 
{{YoderFoot}}

Latest revision as of 09:02, 30 September 2020


thumb‎ Embedded Linux Class by Mark A. Yoder


Sometimes it's nice to pull some files off a USB drive and onto the Bone. Or to plug a SD card reader into the USB port so you can read files from it.

Shown here is how to read from a ext4 formatted device.

Finding

Before plugging in your drive into the USB port run:

bone$ fdisk -k
Disk /dev/mmcblk0: 59 GiB, 63367544832 bytes, 123764736 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xdcc0d66a

Device         Boot Start       End   Sectors Size Id Type 
/dev/mmcblk0p1 *     8192 123764735 123756544  59G 83 Linux

Disk /dev/mmcblk1: 1.8 GiB, 1920991232 bytes, 3751936 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x10867701

Device         Boot Start     End Sectors  Size Id Type
/dev/mmcblk1p1 *     8192 3751935 3743744  1.8G 83 Linux

Here you see two "disks" are present, /dev/mmcblk0 and /dev/mmcblk1. /dev/mmcblk0 is the SD card and /dev/mmcblk1 is the built in eMMC flash. Each have one partition, /dev/mmcblk0p1 and /dev/mmcblk1p1 respectively.

Now plug in the drive you want to read into the USB port and you'll see an additional drive appear

bone$ fdisk -k
...
Disk /dev/sda: 3.7 GiB, 3904897024 bytes, 7626752 sectors
Disk model: SD/MMC
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0xab2c50d0

Device     Boot Start     End Sectors  Size Id Type
/dev/sda1  *     8192 6963199 6955008  3.3G 83 Linux

It is /dev/sda with partition /dev/sda1.

Mounting

To mount a partition you have to make an empty directory where you want the drive to appear.

bone$ cd
bone$ mkdir USBdrive

Then mount them.

bone$ sudo mount /dev/sda1 USBdrive

Then see what appears.

bone$ ls USBdrive
bbb-uEnv.txt  boot  etc   ID.txt  lost+found  mnt           opt   root  sbin  sys  usr
bin           dev   home  lib     media       nfs-uEnv.txt  proc  run   srv   tmp  var

You should see the files on the USB drive.

Note: You can mount any partition, so if you booted off the SD card and wanted to access the files on the eMMC you could:

bone$ mkdir eMMC
bone$ sudo mount /dev/mmcblk1p1 eMMC

Unmounting

When you are done run:

bone$ sync
bone$ sync
bone$ sudo umount USBdrive

The syncs are to make sure everything has been written to the drive.




thumb‎ Embedded Linux Class by Mark A. Yoder