As system administrators, we would have got requirements wherein we need to configure raw hard disks to the existing servers as part of upgrading server capacity or sometimes disk replacement in case of disk failure. Attaching BuyVM/FranTech Block Storage Slabs to a Linux has the similar approach.
In this article, I will take you through the steps by which we can add the new Block Storage Slabs to an existing Linux server such as RHEL/CentOS or Debian/Ubuntu.
Important: Please note that the purpose of this article is to show only how to create a new partition and doesn’t include partition extension or any other switches.
I am using fdisk utility to do this configuration.
I have added a hard disk of 512GB capacity to be mounted as a /data
partition.
fdisk is a command line utility to view and manage hard disks and partitions on Linux systems.
Firstly, you need to login BuyVM/FranTech Stallion control panel to attach your Block Storage Slabs to your VM.
This will list the current partitions and configurations.
[root@las ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00095367
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 39843455 19920704 83 Linux
/dev/vda2 39843456 41940607 1048576 82 Linux swap / Solaris
Disk /dev/sda: 549.8 GB, 549755813888 bytes, 1073741824 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
After attaching the hard disk of 512GB capacity, the fdisk -l
will give the below output.
[root@localhost ~]# fdisk -l
Disk /dev/vda: 21.5 GB, 21474836480 bytes, 41943040 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: 0x00095367
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 39843455 19920704 83 Linux
/dev/vda2 39843456 41940607 1048576 82 Linux swap / Solaris
Disk /dev/sda: 549.8 GB, 549755813888 bytes, 1073741824 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: 0x313fd966
Device Boot Start End Blocks Id System
/dev/sda3 2048 1073741823 536869888 83 Linux
New disk added is shown as /dev/sda
. Some will show as /dev/xvdc
based of the disk type.
To partition a particular hard disk, for example /dev/sda. Type m to print command options
[root@localhost ~]# fdisk /dev/sda
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 0x544d73e3.
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
g create a new empty GPT partition table
G create an IRIX (SGI) partition table
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Here since we are creating a partition use n
option to create either primary/extended partitions.
Command (m for help): n
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
By default we can have upto 4 primary partitions. ive the partition number as desired. Recommended to go for the default value 1
.
Partition number (1-4, default 1): 1
Give the value of the first sector. If it is a new disk, always select default value. If you are creating a second partition on the same disk, we need to add 1
to the last sector of the previous partition.
First sector (2048-1073741823, default 2048):
Using default value 2048
Give the value of the last sector or the partition size. Always recommended to give the size of the partition. Always prefix +
to avoid value out of range error.
Last sector, +sectors or +size{K,M,G} (2048-1073741823, default 1073741823):
Using default value 1073741823
Partition 1 of type Linux and of size 512 GiB is set
Enter w to save the changes and exit.
Command (m for help): w
The partition table has been altered!
Now format the disk with mkfs command.
[root@localhost ~]# mkfs.ext4 /dev/sda1
mke2fs 1.42.9 (28-Dec-2013)
Discarding device blocks: done
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
33554432 inodes, 134217472 blocks
6710873 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2281701376
4096 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
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Note: If you try to mount the drive without formating it. you will get this error:
[root@localhost ~]# mount /dev/sda1 /data
mount: /dev/sda1 is write-protected, mounting read-only
mount: unknown filesystem type '(null)'
[root@localhost ~]# mount -t ext4 /dev/sda1 /data
mount: wrong fs type, bad option, bad superblock on /dev/sda1,
missing codepage or helper program, or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
Once formatting has been completed, now mount the partition as shown below.
# mount /dev/sda1 /data
Make an entry in /etc/fstab file for permanent mount at boot time.
/dev/sda1 /data ext4 defaults 0 0
If you are not familiar with BuyVM/FranTech VPS / Storage, I recommend you check out their website: HERE
Comments
Hey - thanks for your overview... I missed the step of creating a directory for the mount command to map to /data, so it might be good to add that for people like me that forgot that.
# mkdir /data
Can we mount the block storage on local pc ?? Or a 3rd part vps such as google or aws and if yes how so