After attaching the volume to the instance, you can check the device list. The new device will be listed as created recently:
$ ls -l /dev | grep xvd
brw-rw---- 1 root disk 202, 0 Jul 13 2020 xvda
brw-rw---- 1 root disk 202, 1 Jul 13 2020 xvda1
brw-rw---- 1 root disk 202, 80 Jul 13 2020 xvdf
brw-rw---- 1 root disk 202, 96 Jul 13 2020 xvdg
brw-rw---- 1 root disk 202, 112 Nov 2 2020 xvdh
brw-rw---- 1 root disk 202, 128 Nov 17 10:12 xvdi
You can also check for the block devices using the lsblk
command.
You will be able to see each block device including the newly attached one, which should be the only without a mount point:
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
xvda 202:0 0 16G 0 disk
└─xvda1 202:1 0 16G 0 part /
xvdf 202:80 0 100G 0 disk /orabk/uncompressed
xvdg 202:96 0 200G 0 disk /orabk/2021_compressed
xvdh 202:112 0 200G 0 disk /orabk/transfer
xvdi 202:128 0 500G 0 disk
Notice how the xvdi disk doesn't show a mount point. Before mounting the volume you need to check if it is already formatted.
You can use the file -s
command to check block device file:
$ sudo file -s /dev/xvdi
/dev/xvdi: data
The result from the command shows only data as the file type. This means the volume is not currently formatted.
Let's format the drive as an EXT4 filesystem:
$ sudo mkfs -t ext4 /dev/xvdi
Creating filesystem with 131072000 4k blocks and 32768000 inodes
Filesystem UUID: cb321863-27f5-4c14-82f5-5e421fc3c60a
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Let's check the block device file again:
# Use the special-file flag to get filesystem type information
$ sudo file -s /dev/xvdi
/dev/xvdi: Linux rev 1.0 ext4 filesystem data, UUID=cb321863-27f5-4c14-82f5-5e421fc3c60a (needs journal recovery) (extents) (large files) (huge files)
If the mount point doesn't exists it needs to be created.
The new folder must be owned by root, hence the use of the su
command:
# Create folder `compress` with root user.
$ sudo mkdir /orabk/compressed
Mount the new volume on the filesystem:
$ sudo mount /dev/xvdi /orabk/compressed
$ sudo chown ubuntu:ubuntu /orabk/compressed
Let's check the file system again to see the mount point:
# Check Filesystem mount point and space
$ df -h /dev/xvdi
Filesystem Size Used Avail Use% Mounted on
/dev/xvdi 493G 70M 467G 1% /orabk/compressed
We will be adding entries to this file using the UUID of the volume (can be done using the device name, but it's not recommended as it can change when disks are removed or added).
The format of each entry is rather simple as follows:
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=a2db89ed-d599-4138-8838-0b950b6c3fbb / ext4 errors=remount-ro 0 1
In this example we already know that information, but in cases where you already have a mounted filesystem and want to check the corresponding information.
Most information can be retrieved from the lsblk
command:
$ lsblk -f | egrep "UUID|xvdi"
NAME FSTYPE LABEL UUID MOUNTPOINT
xvdi ext4 cb321863-27f5-4c14-82f5-5e421fc3c60a /orabk/compressed
With the previous command we obtained the following relevant information: Filesystem Type, Device UUID, and Mount Point. We are just missing the mounting options.
To check the mounting options we can use the findmnt
command(in fact here we also have almost everything except the UUID):
$ findmnt | egrep "TARGET|xvdi"
TARGET SOURCE FSTYPE OPTIONS
├─/orabk/compressed /dev/xvdi ext4 rw,relatime,data=ordered
Make a backup of the current fstab file:
cp /etc/fstab /etc/fstab.orig
The corresponging entry of the /etc/fstab
file with the information of the previous commands would be:
# <file system> <mount point> <type> <options> <dump> <pass>
UUID=cb321863-27f5-4c14-82f5-5e421fc3c60a /orabk/compressed ext4 rw,relatime,data=ordered 0 0
To test the fstab file and make sure all filesystems are mounted properly, first unmount the filesystem and run the mount -a
command:
$ umount /orabk/compressed
$ # Checks the /etc/fstab file and mounts the filesystems specified on it
$ sudo mount -a
$ df -h
After checking the filesystem was properly mounted you can safely reboot your system to test the filesystem is mounted at boot time.