cPanelResources

Tutorial Preparing a local disk or partition for backups

Overview
In this tutorial, we'll explore how to configure a disk or partition in preparation for using it as a local backup directory when enabling backups in WHM >> Backup Configuration.

Note: The examples in this tutorial are generally applicable to any CentOS 7 system, but all examples were tested on the server environment specified below:

Operating System (OS): CentOS 7.5
cPanel Version: 76
Virtualization Software: OpenStack Virtual Machine

Terms To Know
Disk - a disk is a hard or floppy round, flat, and magnetic platter capable of having information read from and written to it.

Partition - A partition is not more than a segment of a hard drive that creates a data space clearly separated from other data spaces or segments.

Filesystem - A filesystem determines the methods and structures the OS (Operating System) will use to keep track of files on a disk. It defines how the data is organized, stored and accessed within the disk.

Sector - A sector is the minimum storage unit. For example, we have a 1MB disk; this disk can be divided into one partition, this partition can be divided into two sectors of 512KB.

Step 1. Locate and identify hard drives from the command line using lsblk, and fdisk
Let us take a look at available disks on a test server. Using the lsblk command, I can see a recently attached 5G disk (hard-drive) in size:

Code:
# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   20G  0 disk
└─vda1 253:1    0   20G  0 part /
vdb    253:16   0    5G  0 disk
loop0    7:0    0  500M  0 loop /var/tmp
The disk we are interested in is the vdb disk, which is represented in the system
as /dev/vdb. We can confirm this with the fdisk -l command:
Code:
# fdisk -l

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
Step 2. Partition the disk
Once we have confirmed the specific disk we want to use (/dev/vdb in this example), we can then use the fdisk /dev/vdb command to partition it.

Note: The fdisk command is going to open the ncurses interface. The lines in bold in the code syntax below require that you manually enter a value on your keyboard. A description of each manual entry is available under the CODE block.

Code:
# 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 0x48285897.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-10485759, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-10485759, default 10485759):
Using default value 10485759
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
• We are interested in the 'n' option, after pressing 'n' on the keyboard we get asked the type of partition we want.

• Because we are using an entire disk for backups, with only one partition we are using letter 'p' to create a primary partition.

• The fdisk command is going to ask for the first, and final sectors. We can press enter when asked for the first sector, and enter when asked for the final sector to use the entire disk.

• We must press the 'w' key to write the changes to the partition.


We now have our disk partitioned, and we can see vdb1 using the lsblk command:

Code:
# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda    253:0    0   20G  0 disk
└─vda1 253:1    0   20G  0 part /
vdb    253:16   0    5G  0 disk
└─vdb1 253:17   0    5G  0 part
loop0    7:0    0  500M  0 loop /var/tmp
Step 3. Create the filesystem
We now have a partition, and we need to format the partition with the mkfs.ext4 command so it has a valid ext4 filesystem.:

Command:
Code:
# mkfs.ext4 /dev/vdb1
Step 4. Configure the partition/disk to be appropriately mounted with /etc/fstab
We can mount the disk on the /backup directory with the mount command:

Code:
# mount -t ext4 /dev/vdb1 /backup/
We can see the disk is now mounted:

Code:
# mount|grep vdb
/dev/vdb1 on /backup type ext4 (rw,relatime,data=ordered)
Note: The above was a manual mount, and should the server reboot it won't be mounted back when the system boots.

For the disk to be automounted, we need to first open the /etc/fstab file in a command line text editor (e.g. vi, nano):

Code:
# vi /etc/fstab
Then, add the following line to the end of this file and save:

Code:
/dev/vdb1               /backup                                  ext4     defaults,auto               0 0
The above entry specifies the following:
  • The partition we created /dev/vdb1
  • The directory we are associating with the /dev/vdb1 partition, which is /backup
  • The filesystem we assigned to the filesystem when we formatted it
  • Default settings for the filesystem
  • The 'auto' option is fundamental. It tells the system to mount the disk on boot time. This is included for clarity, but it is included in the "defaults" options (rw, suid, dev, exec, auto, nouser, and async).
Step 5. Configure the default backup directory
Now that the disk is configured (partitioned, formatted, and mounted), you can enter the path to it (e.g. /backup) in the Default Backup Directory field when enabling backups in WHM >> Backup Configuration.

Questions/Feedback
Feel free to click on the Discussion tab to let us know if you have any trouble with the instructions in this tutorial, or have additional questions and feedback.
Author
cPanelResources
Views
4,111
First release
Last update
Rating
0.00 star(s) 0 ratings