Adding Backup Disk on a Linux Server

It is better to have a second hard disk on servers for backup. Here, we will partition a fresh disk, format and mount it as /backup.

parted /dev/sdX print free
parted /dev/sdX mktable gpt
parted /dev/sdX mkpart primary ext4 0% 100%
mkfs.ext4 /dev/sdX1

Replace /dev/sdX with the actual device name of your backup disk.

Now you need to find the UUID for this new drive with the command

blkid

Create a folder to mount the disk, in this case, we use /backup

mkdir /backup

Edit /etc/fstab

vi /etc/fstab

Add

UUID=1c7b33ed-ea6d-4694-9925-edfd0e8a2837  /backup ext4 defaults 0 1

Replace “1c7b33ed-ea6d-4694-9925-edfd0e8a2837” with the actual UUID for your new disk, that you found using blkid command.

Now run

mount -a

This will mount all disks specified in /etc/fstab, verify /backup is mounted with the command

df -h

Partitioning New HDD

Here we partition the device /dev/sdb and mount it as /backup.

First, we check free space on the server with

[root@sok ~]# parted /dev/sdb print free
Error: /dev/sdb: unrecognised disk label
Model: ATA WDC WD1003FBYX-0 (scsi)                                        
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: unknown
Disk Flags: 
[root@sok ~]#

Lets make the partition table of type GPT

[root@sok ~]# parted /dev/sdb mktable gpt
Information: You may need to update /etc/fstab.

[root@sok ~]#

Now you will see we have 1000 GB free space.

[root@sok ~]# parted /dev/sdb print free                                
Model: ATA WDC WD1003FBYX-0 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name  Flags
        17.4kB  1000GB  1000GB  Free Space

[root@sok ~]#

Let’s create a partition of type ext4 using 100% of the disk.

[root@sok ~]# parted /dev/sdb mkpart primary ext4 0% 100%
Information: You may need to update /etc/fstab.

[root@sok ~]# parted /dev/sdb print free                
Model: ATA WDC WD1003FBYX-0 (scsi)
Disk /dev/sdb: 1000GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags: 

Number  Start   End     Size    File system  Name     Flags
        17.4kB  1049kB  1031kB  Free Space
 1      1049kB  1000GB  1000GB               primary
        1000GB  1000GB  729kB   Free Space

[root@sok ~]#

Formatting the Disk

[root@sok ~]# mkfs.ext4 /dev/sdb1
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
61054976 inodes, 244190208 blocks
12209510 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2392850432
7453 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

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

[root@sok ~]# 

Mounting Disk

First, find the UUID of the disk with command blkid

[root@thor ~]# blkid
/dev/sda2: UUID="aba6f962-366b-455a-959a-b9d04a9bfa34" TYPE="ext4" 
/dev/sda1: UUID="3432e015-01e6-4f09-9991-ff73a90f340b" TYPE="swap" 
/dev/sdb1: UUID="1c7b33ed-ea6d-4694-9925-edfd0e8a2837" TYPE="ext4" PARTLABEL="primary" PARTUUID="7c182896-e88f-44cf-b3fe-e369b88044a1" 
/dev/loop0: UUID="63f812e0-51e0-4cf8-8ae4-da70d61ce272" TYPE="ext3" 
/dev/sdd1: UUID="5cabe12d-a575-4374-af15-c8bb3abe8fe8" TYPE="ext4" PARTLABEL="primary" PARTUUID="0eca4648-25a4-4b89-a93b-bc3ad781caa0" 
/dev/sdc1: UUID="01cc1cfd-888b-42e2-bb1c-e0461c6b989d" TYPE="ext4" PARTLABEL="primary" PARTUUID="74cd1045-fbfc-44a0-9a7d-e0965db53d06" 
[root@thor ~]# 

UUID for the disk /dev/sdb1 is

UUID="1c7b33ed-ea6d-4694-9925-edfd0e8a2837"

To mount this disk as /backup, first create a folder

mkdir /backup

Now edit /etc/fstab

vi /etc/fstab

Add the following line

UUID=1c7b33ed-ea6d-4694-9925-edfd0e8a2837  /backup ext4 defaults 0 1

Run

mount -a

This will mount all disks specified in /etc/fstab

Verify your new drive is mounted with the command df -h

[root@thor ~]# df -h | grep backup
/dev/sdb1       917G   77M  871G   1% /backup
[root@thor ~]# 
Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *