Main Menu

search

You are here

Linux: Mounting external storage

[last updated: 2023-04-14]
raspberry Pi home page
Linux commands
(link to:) askUbuntu - great explanation
-----

  • When you have an external storage device ("file system"), whether SD card or USB drive or stick,
    it must be "mounted" in order to access its files
      Note: external USB sticks will be mounted automatically when inserted/installed.

    ----------

  • Is it mounted already?
    $ lsblk ... shows a table that lists all installed/available devices (maybe but not necessarily also mounted)
      device name/ID will be something like sda, sdb, sdc, etc.
      sda1, sda2 are "partitions" of the sda drive.

    The far right column of the table is "MOUNTPOINTS".
    So if your drive does not have a mountpoint listed, then in fact it is only "installed", but is not 'mounted"

      Confirm this with:
      $ mount | grep sd
      If your device is not listed, then it is not mounted.


      Note: Strictly speaking, the main device (eg. sda) does not get mounted.
      The partition (eg. sda1) is what gets mounted.

    ------------------------------------------------------------------------------------------------------------

  • Steps to mount your device:

    • Find the name/device-ID of your device:
      • $ sudo fdisk -l (lower-case 'L')
          It will be something like:
          /dev/sda

      ----------

    • Decide where you want to mount it:
      • Common mountpoint options are:
        /dev, /media, /mnt, ... plus user-defined whatever ...
        • If you put your drive into /media, then it will show up in File Manager under Devices in left side-bar menu
        • (see askUbuntu link above for detailed explanation)
      • Create a mount point location (ie. a directory - if it does not already exist):
        eg. $ sudo mkdir /media/SSD250

      ----------

    • Partition and Format your device:
      These must both be done before you can mount your device.
        How can you find out if your device is already partitioned and formatted?

      • Partition:
        • Use fdisk:
          $ sudo fdisk /dev/sda
        • fdisk is a program. When you execute it as above,
          you "open" the /dev/sda device into the fdisk program.
          The prompt will change to:
            " Command (m for help): "
        • You have lots of options for how to proceed once in the fdisk program.
          Nominally it is used to create, list, or modify partitions on a drive.
            q ... will quit the program without saving any changes you've made
            w ... will write/save your changes, then exit
            n ... will create a new partition
        • For a new/raw/un-formatted device,
          type 'n' to create a new partition, then probably 'p' for primary partition, then press CR to accept defaults for other parameters,
          then finally 'w' to save and exit.
      • Format:
        • $ sudo mkfs.ext4 /dev/sda1
          This will format the sda1 partition into format type: ext4, which is the standard format for Linux user files

      ----------

    • Mount your device to desired location/mountpoint:
      • $ sudo mount [partitionName] [mountPoint]
        eg: $ sudo mount /dev/sda1 /media/SSD250

      • The mount point becomes the root directory of your mounted device

      ----------

    • Make it autoMount on bootup:
      • If you do not do this, then you will need to manually mount your drive every time you reboot

      • Get UUID and file type:
        • $ sudo blkid
        • Scroll to your target device, eg. /dev/sda1
          UUID will be a multi-char string
          TYPE will usually be ext4, but may be others
          Record these parameters to edit into the fstab file (see below).
      • Edit /etc/fstab file:
        • $ sudo nano /etc/fstab
        • Append the following line (customized for your system with parameters you recorded above from the blkid command)
          to the end of the fstab file:
            UUID=87f73653-9314-4850     /media/sda1     ext4     defaults     0     2

          Fields must be separated with tabs.
          the 'ext4' is your drives' format type
          the 'defaults 0 2' are typical default settings for a secondary drive

        • type ctrl-x, then Y, then enter to save the edited fstab file and exit

      ----------------------------------------------------------------------

    .

    .

    .

    eof