In this tutorial, we will cover how to format a hard disk in both Linux and Windows.
Mounting a Hard Disk (Linux)
Log in to the instance with the attached hard disk and type the following command:
The resulting output shows our disks. In our example, the disk that we have attached is listed as
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 49.9G 0 part / ├─sda14 8:14 0 4M 0 part └─sda15 8:15 0 106M 0 part /boot/efi sdb 8:16 0 100G 0 disk
Now that we have our disk name, it's time to partition the disk. We will do this using the
$ sudo parted /dev/sdX
Note: Remember to change the disk from
sdX to your disk.
This will bring up the utility. In this interface, we will first need to type
mklabel to tell the utility what partition table to use. In our example, we will be using GPT (GUID Partition Table). However, you can use other partition tables if they better suit your needs.
GNU Parted 3.2 Using /dev/sdb Welcome to GNU Parted! Type 'help' to view a list of commands. (parted) mklabel New disk label type? gpt
Now that we have chosen the partition table, we will need to create a new partition. To create a new partition type the command
mkpart. In our example, we have named our partition OVHexample, chosen ext4 (the current Linux filesystem standard) as our file system, and partitioned the entire disk. You may change any of these settings to fit your use case.
(parted) mkpart Partition name? ? OVHexample File system type? [ext2]? ext4 Start? 1 End? 100%
We are finished with
parted utility. Type
q to quit.
The partition has been created; we can see that the disk has been added by using the
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sda 8:0 0 50G 0 disk ├─sda1 8:1 0 49.9G 0 part / ├─sda14 8:14 0 4M 0 part └─sda15 8:15 0 106M 0 part /boot/efi sdb 8:16 0 100G 0 disk └─sdb1 8:17 0 100G 0 part
As you can see, the
sdb1 partition has been created. The partition now needs to be formatted.
$ sudo mkfs.ext4 /dev/sdX1
Note: In our example, the file system used is
ext4 and the partition is
sdb1. Remember to change these out with the corresponding file system and partition that you chose.
Next, we will create a new directory and mount the drive to it.
$ sudo mkdir /mnt/disk
$ sudo mount /dev/sdb1 /mnt/disk
Let's check our file system to make sure the disk is mounted.
$ df -h
The following output shows that the disk has been formatted and mounted.
Filesystem Size Used Avail Use% Mounted on udev 3.4G 0 3.4G 0% /dev tmpfs 681M 644K 680M 1% /run /dev/sda1 49G 1.4G 47G 3% / tmpfs 3.4G 0 3.4G 0% /dev/shm tmpfs 5.0M 0 5.0M 0% /run/lock tmpfs 3.4G 0 3.4G 0% /sys/fs/cgroup /dev/sda15 105M 3.4M 102M 4% /boot/efi tmpfs 681M 0 681M 0% /run/user/1000 /dev/sdb1 98G 61M 93G 1% /mnt/disk
Mounting a Hard Disk (Windows)
To manage storage devices in Windows Server 2016, we first need to open our "Server Manager" application. To do so, click the Magnifying Glass in the bottom-left corner of the screen and search for "Server Manager".
Once open, select the File and Storage Services option under the "ROLES AND SERVER GROUPS".
Once in the "File and Storage Services" section select the Disks option under the "Volumes" portion. On this screen, you will see your disk is offline, in order to mount the disk, we will need to "right-click" the disk and select the Bring Online option from the drop-down menu.
After we bring the disk online we will be able to add a new volume to the disk and make it usable. To do so, right-click the disk again and select the New Volume option. Go through the "New Volume Wizard" that pops up, selecting the options that fit your needs. If you are not sure what configuration is best, the default selections will usually be sufficient.
After you are finished, click the Create button and you will have your new disk mounted.
Mounting an external hard drive gives you the flexibility to detach and end instances while still retaining important data. Having the ability to save important files or just create a bit of extra storage is a great asset. Having read this guide, you should be able to confidently mount a hard disk to an instance running Linux or Windows Server.