by Devin Yang
(This article was automatically translated.)

Published - 6 years ago ( Updated - 6 years ago )

Official source material for reference:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html

The following is a complete record of the steps:
1. Use the lsblk command to view available disk devices and their mount points (if applicable)
ubuntu@ip-10-0-0-251:/$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 8G 0 disk
└─xvda1 202:1 0 8G 0 part /
xvdb 202:16 0 150G 0 disk

The output screen lsblk will remove the device path before /dev/.
So that means xvdb is /dev/xvdb

2. Check whether the file system needs to be set up on the volume (Volumn).
ubuntu@ip-10-0-0-251:/$ sudo file -s /dev/xvdb
/dev/xvdb:data

In the above example, data represents that there is no file system for this device, so a .
4. If there is no data, use the following command to create a file system, which means formatting on Windows, and format it as an ext4 file system. Note that if there is data, it will be cleared.
sudo mkfs -t ext4 /dev/xvdb

5. After completion, it can be mounted. sudo mount device_name mount_point
In this example, I mounted to the /opt folder
sudo mount /dev/xvdb /opt

6. Set the file system to mount automatically, otherwise you need to mount it manually after reboot. First, backup /etc/fstab
sudo cp /etc/fstab /etc/fstab.orig

7. Use an editor to open /etc/fstab to modify, use the following format, you can use the device name, such as /dev/xvdb, but it is recommended to use the 128bit UUID of the device.
device_name mount_point file_system_type fs_mntops fs_freq fs_passno
8. To find the UUID step, first use df to list the available devices.
ubuntu@ip-10-0-0-251:~$ df
Filesystem 1K-blocks Used Available Use% Mounted on
udev 2014864 0 2014864 0% /dev
tmpfs 404524 5664 398860 2% /run
/dev/xvda1 8065444 1145048 6904012 15% /
tmpfs 2022604 0 2022604 0% /dev/shm
tmpfs 5120 0 5120 0% /run/lock
tmpfs 2022604 0 2022604 0% /sys/fs/cgroup
/dev/xvdb 154687468 60864 146745900 1% /opt
tmpfs 404524 0 404524 0% /run/user/1000
ubuntu@ip-10-0-0-251:~$

9. Then use the following command to list the UUID of the device, for example, I want to see /dev/xvdb
ubuntu@ip-10-0-0-251:~$ sudo file -s /dev/xvdb
/dev/xvdb: Linux rev 1.0 ext4 filesystem data, UUID=dfd2866b-5600-4c20-80f5-d8a6f4786432 (needs journal recovery) (extents) (large files) (huge files)

10. So make the following modification on /etc/fstab to let the file system mount automatically.
UUID=dfd2866b-5600-4c20-80f5-d8a6f4786432       /opt     ext4   defaults,nofail

Final note: For versions lower than 16.04, add nobootwait
note
If you ever intend to boot your instance without this volume attached (for example, so this volume could move back and forth between different instances), you should add the nofail mount option that allows the instance to boot even if there are errors in mounting the volume. Debian derivatives, including Ubuntu versions earlier than 16.04, must also add the nobootwaitmount option.

11. Confirm that the newly added items are effective and available
sudo mount -a

If you execute the above command, there is no message, no news is good news ( No news is good news ) , then it means that the /etc/fstab file is not set incorrectly,
If any error occurs, do not restart the computer, it will cause the system to fail to restart.
Please restore the backup steps of step 6,
Or after correction, use sudo mount -a to test.




 

Tags: EBS Volume mount ubuntu

Devin Yang

Feel free to ask me, if you don't get it.:)

No Comment

Post your comment

Login is required to leave comments