Amazon EC2 Linux实例添加额外卷后是否自动使用新卷存储咨询
Hey Steve, let’s tackle your EC2 disk space issue step by step—first, the core question you asked:
No, your Linux system won’t automatically start storing files on the new EBS volume once the original runs out of space. Here’s why: when you attach a new volume, it’s unformatted and unmounted by default—your OS doesn’t even recognize it as usable storage until you set it up manually.
Below is a straightforward guide to adding and configuring the extra volume, plus how to make it usable for your system:
- Head to the AWS EC2 Console, navigate to Volumes under the "Elastic Block Store" section.
- Click Create volume, choose the size you need, and make sure the Availability Zone matches your EC2 instance (volumes are AZ-specific).
- Once created, right-click the new volume, select Attach volume, pick your EC2 instance from the dropdown, and confirm.
- SSH into your EC2 Linux instance. First, list all block devices to find your new volume:
Look for a device with your chosen size (e.g.,lsblk/dev/nvme1n1for Nitro-based instances, or/dev/xvdhfor older types). - Format it with a filesystem (ext4 is standard for Linux):
Warning: This will erase all data on the volume—only run this if it’s a brand-new, empty volume.sudo mkfs.ext4 /dev/nvme1n1
- Create a mount point (a directory where the volume will be accessible):
sudo mkdir /mnt/extra-storage - Mount the volume to this directory:
sudo mount /dev/nvme1n1 /mnt/extra-storage - Verify the mount worked with:
You’ll see the new volume listed underdf -h/mnt/extra-storage.
- Get the unique UUID of your new volume (this is more reliable than using the device name, which can change):
Copy the UUID value (looks likesudo blkid /dev/nvme1n1abc123-...). - Edit the
/etc/fstabfile to add the mount:
Add this line at the end (replacesudo nano /etc/fstabyour-uuid-herewith the UUID you copied):UUID=your-uuid-here /mnt/extra-storage ext4 defaults,nofail 0 2 - Save and exit (Ctrl+O, then Ctrl+X in nano). Test the configuration to avoid boot issues:
If no errors pop up, you’re good to go.sudo mount -a
If your original disk is full because of specific large directories (like /var/log, /home, or app data), you can move those to the new volume to free up space immediately:
- For example, to migrate
/var/log:- Stop services that write to the directory first (e.g., syslog):
sudo systemctl stop rsyslog - Copy all files to the new volume (preserve permissions and structure):
sudo rsync -av /var/log/ /mnt/extra-storage/log/ - Backup the original directory:
sudo mv /var/log /var/log.bak - Create a new empty directory as the new mount point:
sudo mkdir /var/log - Update your
/etc/fstabfile to mount the new volume directly to/var/loginstead of/mnt/extra-storage. - Mount the volume:
sudo mount -a - Restart the stopped service:
sudo systemctl start rsyslog - Once you confirm everything works, you can delete the backup:
sudo rm -rf /var/log.bak
- Stop services that write to the directory first (e.g., syslog):
内容的提问来源于stack exchange,提问作者steve

