Adding a New Drive in Linux

New drives are not automatically partitioned, formatted or mounted in all SoftLayer Servers, both Virtual and Bare Metal. The following is one way of setting up a new drive after ordering:

Creating a Primary Partition

  1. Use fdisk -l to show a list of drives and partitions on the system.

    Note: The primary disk on a Virtual Server is /dev/xvda. There are two partitions, /dev/xvda1, which is the boot partition and /dev/xvda2, which is the root file system. Additional disks are labelled /dev/xvdb (Swap), /dev/xvdc, etc. The primary disk on a Bare Metal Server is /dev/sda. The boot partition is typically /dev/sda1 and the root file system varies based on how partitioning is configured at provision. Additional disks are labelled /dev/sdb, /dev/sdc, etc.

  2. Determine which disk needs to be set up. Below shows part of the output of running fdisk -l. /dev/xvdb shows one partition, /dev/xvdb1, so /dev/xvdb is not a new disk. /dev/xvdf does not show any partitions under the area whose first column is labelled "Device Boot", so it has not been set up:

    Disk /dev/xvdb: 2147 MB, 2147483648 bytes
    255 heads, 63 sectors/track, 261 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0x00025cdb

    Device Boot Start End Blocks Id System
    /dev/xvdb1 1 261 209645182 Linux swap / Solaris

    Disk /dev/xvdf: 21.5 GB, 21474836480 bytes
    255 heads, 63 sectors/track, 2610 cylinders
    Units = cylinders of 16065 * 512 = 8225280 bytes
    Sector size (logical/physical): 512 bytes / 512 bytes
    I/O size (minimum/optimal): 512 bytes / 512 bytes
    Disk identifier: 0xd26c00fe

    Device Boot Start End Blocks Id System

    [Note that there is nothing here]

  3. Run the fdisk command with the name of the device as an argument. On the example system above, the command is:

    # fdisk /dev/xvdf

    Note: Running the command in step 3 will give access to the following commands to run on the disk:

    Command action
    a toggle a bootable flag
    b edit bsd disklabel
    c toggle the dos compatibility flag
    d delete a partition
    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)

  4. To create one partition that spans the entire disk, type the letter 'n' and press enter, type the letter 'p' and press enter, type the number '1' and press enter, and then press enter twice to accept the default values for the first and last cylinders. To save and exit, type the letter 'w' and press enter.

Formatting the Partition as ext3 or ext4

To format the example disk's new partition as ext3 or ext4, run one of the below commands.

  1. # mkfs.ext3 /dev/xvdf1
  2. # mkfs.ext4 /dev/xvdf1

Note: The name of the partition will vary. If you created a single primary partition on a hypothetical disk called /dev/xvdc, then the partition name would be /dev/xvdc1. Likewise, for a Bare Metal Server, if you created a single primary partition on a hypothetical disk called /dev/sdc, the partition would be called /dev/sdc1.

Mounting the New Partition

  1. Create the new directory where the drive will be mounted. For example, to create the mount point, /home2, this is the command:

    # mkdir /home2

  2. Mount the drive using the mount command. The first example showsthe mounting of the example partition onthe mount point created above. The second example is of the third hard disk on a Bare Metal Server to the /backup directory.

    1. # mount /dev/xvdf1 /home2

    2. # mount /dev/sdc1 /backup

  3. Add an entry into the /etc/fstab file so that the drive will mount automatically after rebooting. Below is an example /etc/fstab. The last line of the file shows the example partition mounted as an ext4 file system with default mount options. More information on all of the parameters shown in this file can be found on this man page for fstab.

    UUID=6e4334eb-d2f5-4978-8840-38a33874f54b / ext3 defaults,noatime 1 1
    UUID=035d36c2-f638-4287-93bd-0092b20c5c14 /boot ext3 defaults,noatime 1 2
    LABEL=SWAP-xvdb1 swap swap defaults 0 0
    tmpfs/dev/shmtmpf defaults 0 0
    devpts /dev/pts devpts gid=5,mode=620 0 0
    sysfs /sys sysfs defaults 0 0
    proc /proc proc defaults 0 0
    /dev/xvdf1 /home2 ext4 defaults 0 2