EBC Exercise 08 Mounting a USB drive

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.