Create and attach Lightsail block storage disks to Linux instances
You can create and attach additional block storage disks for your Amazon Lightsail instances. After you create additional disks, you need to connect to your Linux/Unix-based Lightsail instance and format and mount the disk.
This topic shows you how to create a new disk and attach it using Lightsail. It also describes how to connect to your Linux/Unix-based instance using SSH, so that you can format and mount your attached disk.
If you have a Windows Server-based instance, see the following topic instead: Create and attach block storage disks to your Windows Server instance.
Step 1: Create a new disk and attach it to your instance
-
In the left navigation pane, choose Storage.
-
Choose Create disk.
-
Choose the AWS Region and Availability Zone where your Lightsail instance is located.
-
Choose a size.
-
Enter a name for your disk.
Resource names:
-
Must be unique within each AWS Region in your Lightsail account.
-
Must contain 2 to 255 characters.
-
Must start and end with an alphanumeric character or number.
-
Can include alphanumeric characters, numbers, periods, dashes, and underscores.
-
-
Choose one of the following options to add tags to your disk:
-
Add key-only tags or Edit key-only tags (if tags have already been added). Enter your new tag into the tag key text box, and press Enter. Choose Save when you’re done entering your tags to add them, or choose Cancel to not add them.
-
Create a key-value tag, then enter a key into the Key text box, and a value into the Value text box. Choose Save when you’re done entering your tags, or choose Cancel to not add them.
Key-value tags can only be added one at a time before saving. To add more than one key-value tag, repeat the previous steps.
Note
For more information about key-only and key-value tags, see Tags.
-
-
Choose Create disk.
After a few seconds, your disk is created and you're on the new disk management page.
-
Choose your instance from the list, and then choose Attach to attach the new disk to your instance.
Step 2: Connect to your instance to format and mount the disk
-
After you create and attach your disk, go back to the instance management page in Lightsail.
The Connect tab is displayed by default.
-
Choose Connect using SSH to connect to your instance.
-
Enter the following command into the terminal window:
lsblk
The output of
lsblk
omits the/dev/
prefix from disk paths.Note
On June 29, 2023 we updated the underlying hardware for Lightsail instances. In the following examples, device names for previous generation instances are displayed as
/dev/xvda
. Device names for instances created after this date are displayed as/dev/nvme0n1
. -
Determine whether to create a file system on the disk. New disks are raw block devices, and you must create a file system on them before you can mount and use them. Disks that have been restored from snapshots likely have a file system on them already. If you create a new file system on top of an existing file system, the operation overwrites your data.
Use the following to determine if your disk has a file system or not. If your disk does not have a file system, continue to Step 2.5. If your disk does have a file system, skip to Step 2.6.
-
Use the following command to create a new file system on the disk. Substitute the device name (such as
/dev/nvme1n1
) fordevice_name
. Depending on the requirements of your application or the limitations of your operating system, you can choose a different file system type, such asext3
orext4
.Important
This step assumes that you're mounting an empty disk. If you're mounting a disk that already has data on it (for example, a disk that was restored from a snapshot), don't use
mkfs
before mounting the disk. Instead, skip to Step 2.6 and create a mount point. Otherwise, you'll format the disk and delete the existing data. -
Use the following command to create a mount point directory for the disk. The mount point is where the disk is located in the file system tree and where you read files from and write files to after you mount the disk. Substitute a location for
mount_point
, for an unused space such as/data
.sudo mkdir
mount_point
-
You can verify that the disk now has a file system on it by entering the following command.
-
Finally, mount the disk by entering the following command.
sudo mount
device_name mount_point
Review the file permissions of your new disk mount to ensure that your users and applications can write to the disk. For more information about file permissions, see Making an Amazon EBS Volume Available for Use in the Amazon EC2 User Guide.
Step 3: Mount the disk every time you reboot your instance
You probably want to mount this disk every time you reboot your Lightsail instance. If you don't, this step is optional for you.
-
To mount this disk on every system reboot, add an entry for the device to the
/etc/fstab
file.Create a backup of your
/etc/fstab
file that you can use if you accidentally destroy or delete this file while you're editing it.sudo cp /etc/fstab /etc/fstab.orig
-
Open the
/etc/fstab
file using any text editor, such as vim.You must enter
sudo
before opening the file so that you can save changes. -
Add a new line to the end of the file for your disk using the following format.
device_name mount_point file_system_type fs_mntops fs_freq fs_passno
For example, your new line might look something like this.
-
Save the file and exit your text editor.