Mount New Disk on Ubuntu

It is embarrassing that you have no idea how to use a new disk on the Ubuntu system, isn't it? This topic is about what and how to do when you get a new disk.

Reference

Examine the Disk

$ sudo fdisk -l

Disk /dev/sdb: 274.9 GB, 274877906944 bytes
255 heads, 63 sectors/track, 33418 cylinders, total     536870912 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
Disk identifier: 0x00000000

Disk /dev/sdb doesn't contain a valid partition table

We can observe that there is a disk with 256 GB volume which is not initialized.

Partition the Disk [Optional]

  • Linux provides that each hard disk device can have up to 4 main partitions (including extended partition), any the extended partition should occupy a primary partition number. In other words, in a hard disk, the total number of main partitions and extended partition is up to 4 (4 + 0 or 3 + 1).
  • The extended partition is not directly used, instead, it is used in the format of logical partition, and a extended partition can be divided into any number of logical partitions.
  • The number of /dev/hd (IDE disk) or /dev/sda (SCSI disk) indicates the nature of the partition, i.e., [1,2,3,4] are main partitions, and [5...16] are logical partitions.
  • Make sure you are familiar with the usage of fdisk.

Format the Disk

Note: If you need more than one partition, first create a disk partition using fdisk.

$ sudo mkfs.ext4 /dev/sdb
mke2fs 1.42.9 (4-Feb-2014)
/dev/sdb is entire device, not just one partition!
Proceed anyway? (y,n) y
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
16777216 inodes, 67108864 blocks
3355443 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
2048 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

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

Examine the UUID of Disk

$ sudo blkid
/dev/sda1: UUID="05003145-9b91-4943-aaa8-22cb496fd4d8" TYPE="ext4"
/dev/sda5: UUID="ca0012ba-2bf1-4d0b-94d3-3e4043746a14" TYPE="swap"
/dev/sdb: UUID="e23a1c1e-8d91-4df8-8fba-f0656a1080ab" TYPE="ext4"

Record the UUID of /dev/sdb which is the formatted partition just now.

Note: You should have a different UUID.

Edit /etc/fstab

$ vim /etc/fstab

Add the following line.

UUID=e23a1c1e-8d91-4df8-8fba-f0656a1080ab  /home  ext4  defaults,errors=remount-ro  0  1

Note: The UUID used here is the one you recorded in the last step. And /home is the location where you want the disk mounted.

Restart and Examine the Disk Again

$ sudo df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       8.8G  1.3G  7.1G  15% /
none            4.0K     0  4.0K   0% /sys/fs/cgroup
udev            8.2G  4.0K  8.2G   1% /dev
tmpfs           1.7G  492K  1.7G   1% /run
none            5.0M  8.0K  5.0M   1% /run/lock
none            8.2G     0  8.2G   0% /run/shm
none            100M     0  100M   0% /run/user
/dev/sdb        252G   60M  239G   1% /home

Now You Are Done...

results matching ""

    No results matching ""