Difference between revisions of "Mounting a Flash Filesystem"

From wiki.emacinc.com
Jump to: navigation, search
(This page is done.)
Line 10: Line 10:
 
* Mount the device.
 
* Mount the device.
 
</cl>
 
</cl>
<br clear=all>
+
 
{{mbox  | type=notice | text='''NOTE''': You '''must''' have <code>root</code> permissions to perform some of the following steps. Make sure you are logged in as the <code>root</code> user prior to performing the following steps. The <code>su</code> command can be useful for this.  The filesystem will also need to be mounted read/write in order to create the directory mentioned below. See the section regarding remounting the root filesystem as read/write (above) to see how to do this.}}
+
{{mbox  | type=notice | style = margin-botton: 1em; | text='''NOTE''': You '''must''' have <code>root</code> permissions to perform some of the following steps. Use the <code>su</code> command to switch to the root user. The filesystem will also need to be mounted read/write in order to create the directory mentioned below. See [[Quick_Reference#Making_Changes_To_The_Target_Machine's_Filesystem | Remounting a Filesystem]] }}
<br clear=all>
+
 
 
==Determining the Device Node Assigned to the Flash Device==
 
==Determining the Device Node Assigned to the Flash Device==
The easiest way to determine which device node is assigned to a particular flash device is to inspect the output of the ''dmesg'' command shortly after the device has been connected to your machine. Follow these steps to do so:
+
The easiest way to determine which device node is assigned to a particular flash device is to inspect the output of the ''dmesg'' command shortly after the device has been connected to your machine.
 
<cl>
 
<cl>
 
1. Insert the SD, CF or microSD card or plug in the USB flash device to your EMAC OE machine.
 
1. Insert the SD, CF or microSD card or plug in the USB flash device to your EMAC OE machine.
 
* Wait a few seconds for the device to settle and be recognized by the OS.
 
* Wait a few seconds for the device to settle and be recognized by the OS.
* Run this command at a shell on your EMAC OE machine: <br clear=all> <syntaxhighlight lang=console>root@emac-oe:~# dmesg | tail -n 15</syntaxhighlight>
+
* Run this command at a shell on your EMAC OE machine:  
 +
 
 +
root@emac-oe:~# dmesg | tail -n 15
 +
 
 
* Inspect the output. The output should look similar to the following:
 
* Inspect the output. The output should look similar to the following:
  
<syntaxhighlight lang=console>
+
<syntaxhighlight lang=console highlight=14>
 
usb 2-2: new full speed USB device using at91_ohci and address 2
 
usb 2-2: new full speed USB device using at91_ohci and address 2
 
usb 2-2: not running at top speed; connect to a high speed hub
 
usb 2-2: not running at top speed; connect to a high speed hub
Line 39: Line 42:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Inside square brackets, we see <code>sda</code>.  This is the root device node assigned to our flash device.
+
The highlighted line shows that the root device node for the flash device is <code>sda</code> containing one partition <code>sda1</code>.
 
</cl>
 
</cl>
  
 
==Determine Which Partition to Mount==
 
==Determine Which Partition to Mount==
On a line by itself, we see:
+
For this example, there is only one partition. It is possible that the flash device contains up to 4 ''primary partitions''. If there are multiple partitions, choose the partition that contains the data that needs to be accessed. Repeat the steps below to mount the additional partitions if necessary. A partition with the number 5 (sda5) indicates an ''extended partition''.
<syntaxhighlight lang=console>sda: sda1</syntaxhighlight>
 
This means one partition was found on our device: ''sda1''. This is the partition we will use.
 
 
 
<br clear=all>{{mbox | type=notice | text='''NOTE''': If there is more than one partition, you will need to decide which partition to use based on your knowledge of the paritions on the device.  The partition device node assignment will be listed in order in the output above. If the first partition is <code>sda1</code>, and the second one is <code>sda5</code>, that is not an error.  Only 4 ''primary partitions'' can exist on a device. If the second partition is number 5, that means it was created as an ''extended partition''.}}
 
<br clear=all>
 
 
==Determine Where to Mount the Device==
 
==Determine Where to Mount the Device==
Now that we know what device node we are going to mount, we need to determine where to mount it. The <code>/mnt</code> directory is typically used for this (<code>mnt</code> is short for ''mount'').
+
Now that we know what partition we are going to mount, we need to determine where to mount it. The <code>/mnt</code> directory is typically used for the root mount point.
  
 
Create a directory to use for the mountpoint:
 
Create a directory to use for the mountpoint:
  
<syntaxhighlight lang=console>root@emac-oe:~# mkdir /mnt/myflash</syntaxhighlight>
+
root@emac-oe:~# mkdir /mnt/myflash
  
Alternatively, you can pick another place in the filesystem to use.  Just make sure you have permission to create a directory in that location. If the directory contains files, it will still be used as the mountpoint when the ''mount'' command is issued; however, the files contained in the directory will be hidden for as long as the directory is in use as a mountpoint.  This could create a great deal of confusion, so beware this potential pitfall.
+
Any directory on the filesystem can be used as a mount point provided that the required permissions are obtained. If the directory used as the mount point contains files, they will be hidden when the flash device is mounted.
  
<br clear=all>{{mbox | type=notice | text='''NOTE''' The ''mountpoint'' (where a device is mounted) is the directory which is used to host the root of the filesystem located on the partition.  In other words, if this were a machine running an operating system from Microsoft, the ''mountpoint'' would be a drive letter such as <code>D:</code> or <code>Z:</code>.  In Linux (and Unix), there are no drive letters.  Directories are used instead.  Beneficially, using directories instead of drive letters makes things more consistent (and therefore simpler) from a programming standpoint.}}<br clear=all>
+
<br clear=all>{{mbox | type=notice | text='''NOTE''' The ''mountpoint'' is the directory which is used to host the root of the filesystem located on the mounted partition.  In other words, if this were a machine running an operating system from Microsoft, the ''mountpoint'' would be a drive letter such as <code>D:</code> or <code>Z:</code>.  In Linux (and Unix), there are no drive letters.  Directories are used instead.  Beneficially, using directories instead of drive letters makes things more consistent (and therefore simpler) from a programming standpoint.}}<br clear=all>
  
 
==Mount the Device==
 
==Mount the Device==
Now that ''sda1'' has been determined to be the partition to mount and ''/mnt/myflash'' has been created to be used as the mountpoint, we can mount our flash device with the following command:
+
Now that ''sda1'' has been determined to be the partition to mount and ''/mnt/myflash'' has been created to be used as the mountpoint, the flash device can be mounted with the following command:
  
<syntaxhighlight lang=console>root@emac-oe:~# mount /dev/sda1 /mnt/myflash</syntaxhighlight>
+
root@emac-oe:~# mount /dev/sda1 /mnt/myflash
  
 
If no message is returned from the above command, then it succeeded.  To verify this, try the following command
 
If no message is returned from the above command, then it succeeded.  To verify this, try the following command
  
<syntaxhighlight lang=console>root@emac-oe:~# mount | grep sda1</syntaxhighlight>
+
root@emac-oe:~# mount | grep sda1
 +
 
 +
The device should be listed in the output of the above command.  If it is listed more than once, it may have been mounted automatically by the OS.  If so, inspection of the output should show where it was mounted.
  
You should see your device listed in the output of the above command.  If it is listed more than once, it may have been mounted automatically by the OS.  If so, inspection of the output should show you where it was mounted.
+
{{mbox | type=notice | text='''NOTE''': If the device node was something other than <code>sda1</code>, then replace <code>sda1</code> in the command above with the correct device node for the flash device in the ''Determine Which Partition to Mount'' section above.}}
<br clear=all>{{mbox | type=notice | text='''NOTE''': If the device node was something other than <code>sda1</code>, then replace <code>sda1</code> in the command above with the device node you determine for your flash device in the ''Determine Which Partition to Mount'' section above.}}<br clear=all>
 
  
 
==Unmounting the Filesystem After Use==
 
==Unmounting the Filesystem After Use==
After you are finished using the flash device, you may wish to unmount it (similar to "Safely Removing" a device on other operating systems). The ''umount'' command is used for this purpose.
+
After you are finished using the flash device, you may wish to unmount it (similar to "Safely Removing" a device on other operating systems). The ''umount'' command is used for this purpose. Make sure there are no terminal windows open accessing any files or directories on the mounted filesystem before unmounting.
  
Continuing on with the example above, the device mounted above would be unmounted with the following command:
+
Continuing on with the example above, the device would be unmounted with the following command:
  
<syntaxhighlight lang=console>root@emac-oe:~# umount /mnt/myflash</syntaxhighlight>
+
root@emac-oe:~# umount /mnt/myflash
  
 
If it was automounted elsewhere, it will also need to be unmounted from that mountpoint before it will be safe to remove the device.  For instance, if the automounter mounted it on ''/media/sda1'', then issue the following command:
 
If it was automounted elsewhere, it will also need to be unmounted from that mountpoint before it will be safe to remove the device.  For instance, if the automounter mounted it on ''/media/sda1'', then issue the following command:
<syntaxhighlight lang=console>root@emac-oe:~# umount /media/sda1</syntaxhighlight>
+
root@emac-oe:~# umount /media/sda1
  
<br clear=all>{{mbox | typ=notice | text='''TIP''': The <code>sync</code> command can also be handy for ensuring data written to a device is flushed to disk prior to performing some other activity with the device.}}<br clear=all>
+
<br clear=all>{{mbox | typ=notice | text='''TIP''': The <code>sync</code> command can also be handy for ensuring data written to a device is flushed to disk prior to performing some other activity with the device.}}

Revision as of 18:35, 20 December 2013

TODO: {{#todo: Complete (11.27.13-12:15->KY+);(12.04.13-23:00->MD+);(12.20.13-11:00->MW+)|Klint Youngmeyer|oe 4,oe 5,ky,Complete,md,mw}}

In order to use a flash filesystem on an EMAC OE system, it must be mounted first.

There are four steps to mounting a flash filesystem on an EMAC OE machine:

  1. Determine which device node is assigned to the flash device.

  2. Determine which partition to mount.

  3. Determine where to mount the device.

  4. Mount the device.

Determining the Device Node Assigned to the Flash Device

The easiest way to determine which device node is assigned to a particular flash device is to inspect the output of the dmesg command shortly after the device has been connected to your machine.

  1. Insert the SD, CF or microSD card or plug in the USB flash device to your EMAC OE machine.

  2. Wait a few seconds for the device to settle and be recognized by the OS.

  3. Run this command at a shell on your EMAC OE machine:

    root@emac-oe:~# dmesg | tail -n 15
    
  4. Inspect the output. The output should look similar to the following:

    usb 2-2: new full speed USB device using at91_ohci and address 2
    usb 2-2: not running at top speed; connect to a high speed hub
    usb 2-2: configuration #1 chosen from 1 choice
    scsi0 : SCSI emulation for USB Mass Storage devices
    usb-storage: device found at 2
    usb-storage: waiting for device to settle before scanning
    scsi 0:0:0:0: Direct-Access              Patriot Memory   PMAP PQ: 0 ANSI: 4
    usb-storage: device scan complete
    sd 0:0:0:0: [sda] 15634432 512-byte hardware sectors: (8.00 GB/7.45 GiB)
    sd 0:0:0:0: [sda] Write Protect is off
    sd 0:0:0:0: [sda] Mode Sense: 23 00 00 00
    sd 0:0:0:0: [sda] Assuming drive cache: write through
    sd 0:0:0:0: [sda] Assuming drive cache: write through 
    sda: sda1
    sd 0:0:0:0: [sda] Attached SCSI removable disk
    

    The highlighted line shows that the root device node for the flash device is sda containing one partition sda1.

Determine Which Partition to Mount

For this example, there is only one partition. It is possible that the flash device contains up to 4 primary partitions. If there are multiple partitions, choose the partition that contains the data that needs to be accessed. Repeat the steps below to mount the additional partitions if necessary. A partition with the number 5 (sda5) indicates an extended partition.

Determine Where to Mount the Device

Now that we know what partition we are going to mount, we need to determine where to mount it. The /mnt directory is typically used for the root mount point.

Create a directory to use for the mountpoint:

root@emac-oe:~# mkdir /mnt/myflash

Any directory on the filesystem can be used as a mount point provided that the required permissions are obtained. If the directory used as the mount point contains files, they will be hidden when the flash device is mounted.



Mount the Device

Now that sda1 has been determined to be the partition to mount and /mnt/myflash has been created to be used as the mountpoint, the flash device can be mounted with the following command:

root@emac-oe:~# mount /dev/sda1 /mnt/myflash

If no message is returned from the above command, then it succeeded. To verify this, try the following command

root@emac-oe:~# mount | grep sda1

The device should be listed in the output of the above command. If it is listed more than once, it may have been mounted automatically by the OS. If so, inspection of the output should show where it was mounted.

Unmounting the Filesystem After Use

After you are finished using the flash device, you may wish to unmount it (similar to "Safely Removing" a device on other operating systems). The umount command is used for this purpose. Make sure there are no terminal windows open accessing any files or directories on the mounted filesystem before unmounting.

Continuing on with the example above, the device would be unmounted with the following command:

root@emac-oe:~# umount /mnt/myflash

If it was automounted elsewhere, it will also need to be unmounted from that mountpoint before it will be safe to remove the device. For instance, if the automounter mounted it on /media/sda1, then issue the following command:

root@emac-oe:~# umount /media/sda1