Skip to content

Instantly share code, notes, and snippets.

@colllin
Last active February 17, 2023 19:36
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save colllin/5e311ec948f38ecf697dfe19303056f3 to your computer and use it in GitHub Desktop.
Save colllin/5e311ec948f38ecf697dfe19303056f3 to your computer and use it in GitHub Desktop.
Mount an EC2 volume
  • Create & attach volume in AWS console (must be in same availability zone).
  • From your ec2 instance, list attached volumes:
    sudo fdisk -l
    
  • Find the disk in the list and copy it's identifier to your clipboard, e.g. /dev/nvme1n1.
  • If it's a brand new volume, you probably need to format it:
    Don't do this to a volume with data on it, or else it won't have data on it anymore. You can skip this step and come back to it if you get an error about wrong fs type when trying to mount the disk.
    sudo mkfs.ext4 /dev/nvme1n1
    
    For other available filesystem types, type mkfs. then tab-tab for autocomplete. See also Making an EBS Volume Available for use on Linux for more details, warnings, etc.
  • Create an empty directory where you want to mount the volume, if it doesn't already exist:
    mkdir ~/extrastorage
    
  • Mount the disk to that directory:
    sudo mount /dev/nvme1n1 ~/extrastorage
    
  • You probably need to give yourself permission to read & write from the mounted directory via some combination of the following:
    sudo chmod 775 ~/extrastorage
    sudo chown ubuntu ~/extrastorage
    sudo chgrp ubuntu ~/extrastorage
    
    In other words, ls -g ~ and then change the permissions to match the stuff you can access.
  • You should now be able to access data on that volume as normal file structures nested under ~/extrastorage
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment