Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to automatically mount EBS volumes or disks on AWS-EC2

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to automatically mount EBS volumes or disks on AWS-EC2. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

The configuration files that are automatically mounted under linux are placed in the

[root@ip-172-31-10-1 mongodb] # cat / etc/fstab## / etc/fstab# Created by anaconda on Mon Feb 22 17:08:22 2016 years # Accessible filesystems, by reference, are maintained under'/ dev/disk'# See man pages fstab (5), findfs (8), mount (8) and/or blkid (8) for more info#UUID=ef6ba050-6cdc-416a-9380-c14304d0d206 / xfs defaults 0 0

In this configuration file, the last line shows the automatically mounted disk.

For EC2 instances started with AMI, it is important to note that after starting according to the default configuration (the actual number of startup volumes) for the first time, you need to modify the automatic mount script if you want to modify the default number of volumes or mount other volumes. If you unmount the original mount volume in the configuration file without modifying the configuration file, the instance will not be able to start normally after restart, and your EC2 instance will be broken.

So, how do I check to see if the volume I mounted is in the automatically mounted configuration file?

The following is a query

The first step is to query which volumes are mounted on the machine:

$df-lhFilesystem Size Used Avail Use% Mounted on/dev/xvda1 30G 11G 20G 37% / devtmpfs 3.9G 0 3.9G 0 / devtmpfs 3.7G 0 3.7G 0 0 / dev/shmtmpfs 3.7G 17M 3.7G 1% / runtmpfs 3.7G 0 3.7G 0 0 / sys/fs/cgroup/dev/xvdg 500G 377G 123G 76% / data_bak/dev/mapper/kp-data 695G 458G 237G 66% / datatmpfs 757M 0757M 0% / run/user/1000

As you can see from the above, / dev starts with mount volumes, there are a total of three mount volumes, and we need to know the UUID number of each mount volume.

# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTxvda 202:0 0 30G 0 disk └─ xvda1 202:1 0 30G 0 part / xvdh 202:112 0 700G 0 disk └─ kp-data 253 lvmloop0 0 0695G 0 lvmloop0 7:0 0 100G 0 loop └─ docker-202:1-466265-pool 253 lvmloop0 0 0 100G 0 dm └ ─ docker-202:1-466265-07b91bd38d426f9da2428c068aa1b780e3ca2236a29cce6efba92c4143adf498 253 docker-202:1 2 0 10G 0 dmloop1 7:1 0 2G 0 loop └─ docker-202:1-466265-pool 253 docker-202:1 1 0 100G 0 dm └─ docker-202:1-466265-07b91bd38d426f9da2428c068aa1b780e3ca2236a29cce6efba92c4143adf498 253G0 dm# blkid/dev/block/202:1: UUID= "ef6ba050-6cdc-416a-9380-c14304d0d206" TYPE= "xfs" / dev/loop0: UUID= "32b45258-a08f-4e9b-b2fa-5baa99f96c7d" TYPE= "xfs" / dev/mapper/docker-202:1-466265-pool: UUID= "32b45258-a08f-4e9b-b2fa-5baa99f96c7d" TYPE= "xfs" / dev/mapper/docker-202:1-466265-07b91bd38d426f9da2428c068aa1b780e3ca2236a29cce6efba92c4143adf498: UUID= "32b45258-a08f-4e9b-b2fa-5baa99f96c7d" TYPE= "xfs"

The corresponding UUID number can be found through the above two commands.

Just remove the line of the volume that needs to be removed.

Additional steps to separate the EBS volume from the instance

Uninstall the / dev/sdh device using the following command

Umount-d / dev/sdh

Open the Amazon EC2 console https://console.aws.amazon.com/ec2/.

In the navigation pane, select Volumes.

Select the volume, and then select Actions, Detach Volume.

In the confirmation dialog box, select Yes, Detach.

If you encounter a message that shows that the volume is using busy, there is a program that is using the volume.

[centos@ip-172-31-10-1] $sudo umount / dev/xvdfumount: / data: target is busy. (In some cases useful info about processes that use the device is found by lsof (8) or fuser (1))

Find out which processes are using it with the following command:

[centos@ip-172-31-10-1 log] $lsof | grep'/ data'bash 11100 centos cwd DIR 202 80 4096 262146 / data/mongo/logbash 11863 centos cwd DIR 202 80 4096 2 / databash 12107 centos cwd DIR 202 80 4096 262148 / data/mongo/dblsof 13481 centos cwd DIR 202 804096 262146 / data/mongo/loggrep 13482 Centos cwd DIR 202,80 4096 262146 / data/mongo/loglsof 13483 centos cwd DIR 202,80 4096 262146 / data/mongo/log

Then kill these processes, and you can successfully umount the volume or disk ~

On how to achieve AWS-EC2 automatic mount EBS volumes or disks to share here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report