Formatting Large Volumes in OpenStack

See the article https://ukyrcd.atlassian.net/wiki/x/2RcpBw for how to create a basic OpenStack volume.

A volume larger than 2 TB requires a special method for it to be usable.  Like any volume, a large one requires the creation of a "filesystem". The difference with a large volume is that it also requires the use of a program called "parted". This program is meant to help create a special structure for the volume called a GPT partition table.

Log in to the VM (e.g. via SSH) that you have attached the volume to from a previous step. We suggest that you practice the steps below in a fresh VM that you can throw away, one with no important data in case you make a mistake and  end up erasing existing data. It's very easy to accidentally do this when doing operations on storage.

You need to have super user (sudo) access to run the disk commands below. Note that the steps below may truncate some of the output. And the output will differ from what you are working on, so look for some similaritiesFirst, run fdis

  1. First, a basic VM has been created that runs CentOS 7 with m1.medium flavor (which comes with 40 GB of disk space). Running `lsblk` ("list block devices") will show the disk present. At this point, no volumes have been attached. vda is the block device that was created at VM launch, a 40 GB disk space accessible by this VM.

    $ sudo lsblk
    NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda    253:0    0  40G  0 disk 
    └─vda1 253:1    0  40G  0 part /
  2. Outside of this tutorial, I created a 2TB volume and attached it to the VM (either through the web GUI or CLI), lsblk shows the new volume labeled as device 'vdb'. This label may differ in your VM.

    $ sudo lsblk
    NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda    253:0    0  40G  0 disk 
    └─vda1 253:1    0  40G  0 part /
    vdb    253:16   0   2T  0 disk 
  3. Mounting it will cause an error due to non-existent filesystem on vdb.

    $ sudo mount /dev/vdb /mnt
    mount: /dev/vdb is write-protected, mounting read-only
    mount: unknown filesystem type '(null)'
  4. We'll use fdisk to format the block device. Passing -l just shows the disks in more detail.

    $ sudo fdisk -l
    
    Disk /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: 0x000b3c5c
    
       Device Boot      Start         End      Blocks   Id  System
    /dev/vda1   *        2048    83886046    41941999+  83  Linux
    
    Disk /dev/vdb: 2147.5 GB, 2147483648000 bytes, 4194304000 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
    
  5. Now run fdisk on the new block device (vdb for this example–make sure that you know which disk you're running fdisk on. You'll erase an existing disk if you pick the wrong one). This command tells us that we need to format the device with a GPT partition table.

    $ sudo 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 0xb8c926f8.
    
    Command (m for help): 
    
    
    $ sudo fdisk /dev/vdb
    Welcome to fdisk (util-linux 2.31.1).
    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.
    The size of this disk is 9.5 TiB (10468982784000 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).
  6. Run the program "parted". It will take you to a shell prompt where you can enter commands within the program.
    $ sudo parted /dev/vdb
    GNU Parted 3.1
    Using /dev/vdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted)            
  7. Type "print" within parted to show current setup, then enter `mklabel`.
    (parted) print                                                            
    Error: /dev/vdb: unrecognised disk label
    Model: Virtio Block Device (virtblk)                                      
    Disk /dev/vdb: 2147GB
    Sector size (logical/physical): 512B/512B
    Partition Table: unknown
    Disk Flags: 
    
    
    
  8. If the previous command shows a warning like:

    Warning: The existing disk label on /dev/vdb will be destroyed and all dat
    a on this
    disk will be lost. Do you want to continue?
    
    

    You can input "yes" after you're sure that you're formatting the empty volume (this warning comes up sometimes if you run fdisk and the program automatically creates a different partition table that we don't want.

  9. Use 'parted' to create a partition for the volume that will have a GPT. Below, see the value for Partition Table. It must show 'gpt' to confirm that the previous command worked.
    (parted) mklabel gpt              
    (parted) print                                                            
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 2147GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start  End  Size  File system  Name  Flags
    
                                            
    
    
    
  10. Note that the previous step shows no information under the "Number Start End ...". Now we need to tell the program to create the table with a specified size. The size you can get from the "Disk /dev/vdb: 2147GB" line in the previous step. We run `mkpart primary 0GB 2147GB` below. For your own volume, run the command with the size number that your disk is associated with. Again, run print to confirm.
    (parted) mkpart primary 0GB 2147GB
    (parted) print                                                            
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 2147GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name     Flags
     1      1049kB  2147GB  2147GB               primary
    
  11. Type quit (the result was already saved). You can run parted again and print to confirm that your previous steps were done (check the value for Partition Table, and check the start/end/size values).
    (parted) quit                                                             
    Information: You may need to update /etc/fstab.
    
    $ sudo parted /dev/vdb                               
    GNU Parted 3.1
    Using /dev/vdb
    Welcome to GNU Parted! Type 'help' to view a list of commands.
    (parted) print                                                            
    Model: Virtio Block Device (virtblk)
    Disk /dev/vdb: 2147GB
    Sector size (logical/physical): 512B/512B
    Partition Table: gpt
    Disk Flags: 
    
    Number  Start   End     Size    File system  Name     Flags
     1      1049kB  2147GB  2147GB               primary
    
    
    
  12. Running lsblk will show that vdb1 partition has been created. This partition is actually what will have the filesystem to allow us to access it.
    $ lsblk
    NAME   MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
    vda    253:0    0  40G  0 disk 
    └─vda1 253:1    0  40G  0 part /
    vdb    253:16   0   2T  0 disk 
    └─vdb1 253:17   0   2T  0 part 
  13. Format with the ext4 filesystem using `mkfs`on /dev/vdb1 (not /dev/vdb). vdb1 is the partition that was created using parted. When formatting a device with a filesystem, you want to do it on a partition and not on the whole disk.
    $ sudo mkfs -t ext4 /dev/vdb1
    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
    131072000 inodes, 524287488 blocks
    26214374 blocks (5.00%) reserved for the super user
    First data block=0
    Maximum filesystem blocks=2671771648
    16000 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, 884736, 1605632, 2654208, 
            4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
            102400000, 214990848, 512000000
    
    Allocating group tables: done                            
    Writing inode tables: done                            
    Creating journal (32768 blocks): done
    Writing superblocks and filesystem accounting information: done     
$ sudo parted /dev/vdb
$ # vdb is the disk name for this specific case. Check by running lsblk for your disk name for the volume.

(parted) print                                                            
Error: /dev/vdb: unrecognised disk label
Model: Virtio Block Device (virtblk)                                      
Disk /dev/vdb: 10.5TB
Sector size (logical/physical): 512B/512B
Partition Table: unknown

(parted) mklabel gpt
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10469GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:

Number  Start  End  Size  File system  Name  Flags

(parted) mkpart primary 0GB 10469GB                                       
(parted) print                                                            
Model: Virtio Block Device (virtblk)
Disk /dev/vdb: 10469GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
df -h
Number  Start   End      Size     File system  Name     Flags
 1      0.00GB  10469GB  10469GB               primary


Create a ext4 filesystem for the partition. ext4 is a filesystem type.

Create ext4 filesystem
$ sudo mkfs -t ext4 /dev/vdb
mke2fs 1.44.1 (24-Mar-2018)
/dev/vdb contains a ext2 file system
    last mounted on /mnt/volume1 on Thu Sep 20 22:03:23 2018
Proceed anyway? (y,N) yes
Creating filesystem with 2555904000 4k blocks and 319488000 inodes
Filesystem UUID: b8a711b5-1929-4f20-92df-71568a930ea7
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
    102400000, 214990848, 512000000, 550731776, 644972544, 1934917632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done 

Mount the filesystem found in vdb at a mountpoint. Check that you can actually access it by running `ls` and writing a file there.

$ sudo mkdir /mnt/volume1
$ sudo mount /dev/vdb /mnt/volume1
Test creation of large file within /mnt/volume1.
Size is different than what intended because the dd process was stopped early.
$ sudo dd if=/dev/zero of=large2.txt bs=1M count=50000
$ ls -lh
total 32G
-rw-r--r-- 1 root root 32G Sep 20 22:05 large2.txt
drwx------ 2 root root 16K Sep 20 21:29 lost+found




Center for Computational Sciences