How to attached Volume into Openstack VM for persistent storage
4 min readFeb 17, 2021
1. Create a new Volume
2. Attach the new Volume to VM Instance
Select the volume you just created
3. The message will give you the information which partition is attached to the VM instance, if you don’t remember it, you can still retreive it from VM
[root@kwang-centos7-docker-test ~]# fdisk -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b6061Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 LinuxDisk /dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors # There is new disk /dev/vdb, this is the one we just attached
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes# You won't be able to see if from df command until you format the disk
[root@kwang-centos7-docker-test ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 41931756 4124704 37807052 10% /
devtmpfs 1916904 0 1916904 0% /dev
tmpfs 1940184 0 1940184 0% /dev/shm
tmpfs 1940184 16848 1923336 1% /run
tmpfs 1940184 0 1940184 0% /sys/fs/cgroup
tmpfs 388040 0 388040 0% /run/user/0
4. Create the disk
[root@kwang-centos7-docker-test ~]# fdisk /dev/vdb
Welcome to fdisk (util-linux 2.23.2).Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x82896599.Command (m for help): g
Building a new GPT disklabel (GUID: D2D0A05E-BC31-4A6C-9760-971C74CEA397)Command (m for help): n
Partition number (1-128, default 1):
First sector (2048-10485726, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-10485726, default 10485726):
Created partition 1Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.
[root@kwang-centos7-docker-test ~]# fdisk -lDisk /dev/vda: 42.9 GB, 42949672960 bytes, 83886080 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x000b6061Device Boot Start End Blocks Id System
/dev/vda1 * 2048 83886046 41941999+ 83 Linux
WARNING: fdisk GPT support is currently new, and therefore in an experimental phase. Use at your own discretion.Disk /dev/vdb: 5368 MB, 5368709120 bytes, 10485760 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: gpt
Disk identifier: D2D0A05E-BC31-4A6C-9760-971C74CEA397# Start End Size Type Name
1 2048 10485726 5G Linux filesyste
5. Create file system
[root@kwang-centos7-docker-test ~]# mkfs -t ext4 /dev/sdb
mke2fs 1.42.9 (28-Dec-2013)
Could not stat /dev/sdb --- No such file or directoryThe device apparently does not exist; did you specify it correctly?
[root@kwang-centos7-docker-test ~]# mkfs -t ext4 /dev/vdb
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
327680 inodes, 1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
6. Mount it to the folder
[root@kwang-centos7-docker-test ~]# mkdir /data
[root@kwang-centos7-docker-test ~]# mount /dev/vdb /data
[root@kwang-centos7-docker-test ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/vda1 41931756 4124684 37807072 10% /
devtmpfs 1916904 0 1916904 0% /dev
tmpfs 1940184 0 1940184 0% /dev/shm
tmpfs 1940184 16848 1923336 1% /run
tmpfs 1940184 0 1940184 0% /sys/fs/cgroup
tmpfs 388040 0 388040 0% /run/user/0
/dev/vdb 5029504 20472 4730504 1% /data
[root@kwang-centos7-docker-test ~]# cd /data
[root@kwang-centos7-docker-test data]# ls -l
total 16
drwx------ 2 root root 16384 Jan 15 17:47 lost+found
[root@kwang-centos7-docker-test data]#
7. Now, from the openstack UI, you could see which VM is the volume attached to.