建立於: 7年前 ( 更新: 7年前 )
參考的官方原文資料:
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
以下是進行步驟完整記錄:
1. 用lsblk指令查看可用的磁碟裝置及他們的掛載點(if applicable)
所以就是說xvdb就是/dev/xvdb
2. 檢測是否需要建立檔案系統到卷中(Volumn)上。
4. 沒資料的情況下透過下方指令,即可建立檔案系統,就是Windows上的格式化意思,格式化為ext4檔案系統,注意,如果有資料會被清空。
在這個例子中,我是掛載到了/opt資料夾
11. 確認新增的項目是有作用的,可用
如果出現任何錯誤,千萬不要重開機,會造成系統無法重啟。
請還原step 6的備份步驟,
或修正後,再使用sudo mount -a測試。
http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ebs-using-volumes.html
以下是進行步驟完整記錄:
1. 用lsblk指令查看可用的磁碟裝置及他們的掛載點(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
輸出畫面lsblk會移除前置/dev/的裝置路徑。所以就是說xvdb就是/dev/xvdb
2. 檢測是否需要建立檔案系統到卷中(Volumn)上。
ubuntu@ip-10-0-0-251:/$ sudo file -s /dev/xvdb
/dev/xvdb: data
在上例中,出現了data代表,沒有檔案系統給這個裝置,因此要建立一個.4. 沒資料的情況下透過下方指令,即可建立檔案系統,就是Windows上的格式化意思,格式化為ext4檔案系統,注意,如果有資料會被清空。
sudo mkfs -t ext4 /dev/xvdb
5. 完成後,及可掛載。 sudo mount device_name mount_point
在這個例子中,我是掛載到了/opt資料夾
sudo mount /dev/xvdb /opt
6. 設定自動掛載檔案系統,不然reboot後要手動掛載 ,首先,先備份/etc/fstab
sudo cp /etc/fstab /etc/fstab.orig
7. 用編輯器開啟/etc/fstab進行修改,使用如下的格式,可以用裝置名稱,例如 /dev/xvdb,但建議使用裝置的128bit的UUID。
device_name mount_point file_system_type fs_mntops fs_freq fs_passno
8.找UUID的部驟,先用 df
列出可用裝置.
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. 再來用下方指令去列出裝置的UUID,例如我要看的是/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. 所以在/etc/fstab上進行如下的修改,讓檔案系統自動掛載。
UUID=dfd2866b-5600-4c20-80f5-d8a6f4786432 /opt ext4 defaults,nofail
最後註記: 低於 16.04的版本,要再加上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.
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. 確認新增的項目是有作用的,可用
sudo mount -a
如果執行上方指令,沒有出現任何訊息,沒消息就是好消息( No news is good news ),那麼代表/etc/fstab檔沒有設定錯誤,如果出現任何錯誤,千萬不要重開機,會造成系統無法重啟。
請還原step 6的備份步驟,
或修正後,再使用sudo mount -a測試。
No Comment
Post your comment