Adding a second drive

From NodeSpace Wiki
Jump to navigation Jump to search

Danger: When working with the file system, it's important you watch what you type. You can make your system inoperable. NodeSpace is not responsible for data loss.

Adding a secondary (or tertiary) drive to a system is a common task. This wiki article will walk you through finding your secondary drive and adding a filesystem to it as a mounted filesystem.

Finding the drive[edit | edit source]

When SSH'd into your server, run the following command ls /dev/sd*. This command will output all detected SATA drives by the OS and any partitions. You should see /dev/sda /dev/sda1 /dev/sda2 /dev/sdb, etc. Typically if you have a single SATA drive, the secondary drive will be /dev/sdb. /dev/sda1 is the first partition on the disk /dev/sda. Always verify first. Make note of the drive. If you do not see the drive or have a question, open a support ticket.

Partition the drive[edit | edit source]

Now we need to add partition(s) to the drive. Run the following command as root (or sudo as a regular user): fdisk /dev/sdb (change the letter to the appropriate drive).

fdisk will then prompt you for a command. Check the disk to see if any partitions exist by typing p and enter. If any partitions exist, you'll see them listed, like this:

Device     Start        End    Sectors   Size Type
/dev/sda1   2048 1953525134 1953523087 931.5G Linux filesystem

Enter the p command to create a partition. We recommend keeping the defaults for the next options.

Partition number (1-4, default 1): 1
First sector (2048-16777215, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-16777215, default 16777215): 
 
Created a new partition 1 of type 'Linux' and of size 8 GiB.
 
Command (m for help): 

Once the partition is created, you can then write it to the disk using the w command. Warning! If you messed up, this is where you can abort if needed. Pressing enter after w commits the changes to the disk.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

Now if you re-run ls /dev/sd*, you should see the partition created.

Format the partition[edit | edit source]

Before you can use the drive, you need to format the partition. Run the following command as root (or sudo): mkfs.ext4 /dev/sdb1. Change the “sdb1” to the partition that you just created. This will format the partition using the ext4 filesystem.

Mount the filesystem[edit | edit source]

The last step is to mount the filesystem. Run the following commands:

user@server:~$ sudo mkdir /media/sdb1
user@server:~$ sudo mount /dev/sdb1 /media/sdb1
user@server:~$ sudo nano -Bw /etc/fstab

The second to last command is mounting the filesystem to our /media/sdb1 directory. The last command edits the the fstab file which will automatically mount the drive when the system boots.

Add the following to the last line of the file and save:

/dev/sdb1 /media/sdb1 ext4 defaults 0 1

And now you can use your additional drive.