Skip to content

Instantly share code, notes, and snippets.

@nareshganesan
Last active August 31, 2015 03:51
Show Gist options
  • Save nareshganesan/9c079814a2ca462cb0a0 to your computer and use it in GitHub Desktop.
Save nareshganesan/9c079814a2ca462cb0a0 to your computer and use it in GitHub Desktop.
EC2 attach an existing volume to instance - Linux
# command to show the list of volumes attached to the instance
lsblk # get the device which has no mount point.
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvdf 202:80 0 100G 0 disk
xvda1 202:1 0 8G 0 disk /
# Check files system of the volume
sudo file -s /dev/xvdf
# if the device is not empty to format the volume
sudo mkfs -t ext4 device_name
# Create a mount point Eg: /data
sudo mkdir mount_point
# mount the volume to a location
sudo mount device_name mount_point
# To mount on restart
sudo cp /etc/fstab /etc/fstab.orig
sudo nano /etc/fstab
# device_name mount_point file_system_type fs_mntops fs_freq fs_passno
Eg: /dev/xvdf /data ext4 defaults,nofail 0 2
# Mounting all the volumes attached.
sudo mount -a
# cool feature about EC2
# if you delete a file by mistake then stop the instance and restart immediately
# go the path where the file was deleted. tada -> file is present with .save extension
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment