About formatting new EBS volume on Amazon AWS

I do not have much experience working with Linux and mounting / unmounting. I use Amazon AWS, load EC2 with Ubuntu image, and attach a new EBS volume to EC2. From the toolbar, I see that the volume is connected to :/dev/sda1 .

Now I see from this guide from Amazon that the path is likely to be changed by the kernel. Therefore, most likely, my device /dev/sda1 will be mounted, possibly /dev/xvda1 .

So, I logged in using the terminal. I am doing ls /dev/ and I really see xvda1 there. But I also see xvda . Now I want to format the device. But I do not know if the unformatted device is connected with xvda1 or xvda . I cannot list the contents of /dev/xvda1 and /dev/xvda (it says ls: cannot access /dev/xvda1/: Not a directory ). I think I need to format it first.

I tried formatting with sudo mkfs.ext4 /dev/xvda1 . It says: /dev/xvda1 is mounted; will not make a filesystem here! /dev/xvda1 is mounted; will not make a filesystem here! .

I tried formatting with sudo mkfs.ext4 /dev/xvda . It says: /dev/xvda is apparently in use by the system; will not make a filesystem here! /dev/xvda is apparently in use by the system; will not make a filesystem here!

How can I format a volume?

EDIT:

The result of the lsblk :

 NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvda 202:0 0 8G 0 disk `-xvda1 202:1 0 8G 0 part / 

Then I tried to use the sudo mkfs -t ext4 /dev/xvda , but the same error message appears: /dev/xvda is apparently in use by the system; will not make a filesystem here! /dev/xvda is apparently in use by the system; will not make a filesystem here!

When I tried to use the mount /dev/xvda /webserver , I get an error message: mount: /dev/xvda already mounted or /webserver busy . Some websites indicate that this is also possible due to a damaged or unformatted file system. Therefore, I assume that I need to format it first before I can mount it.

+5
source share
1 answer

First of all, you are trying to format / dev / xvda 1, which is the root device. Why?

Secondly, if you added a new EBS, follow these steps.

Blocked device list

This will give you a list of block devices connected to your EC2, which will look like

 [ec2-user ~]$ lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT xvdf 202:80 0 100G 0 disk xvda1 202:1 0 8G 0 disk / 

Of this, xvda1 is / (root), and xvdf is the one you need to format and mount (for the new EBS)

Format device

  sudo mkfs -t ext4 device_name # device_name is xvdf here 

Create mount point

  sudo mkdir /mount_point 

Set the volume

  sudo mount device_name mount_point # here device_name is /dev/xvdf 

Write to / etc / fstab

  device_name mount_point file_system_type fs_mntops fs_freq fs_passno 

Run

  sudo mount -a 

This will read your / etc / fstab file, and if it is ok. it will connect EBS to mount_point

+2
source

Source: https://habr.com/ru/post/1242067/


All Articles