Formatting an drive for use in Linux

From DISI
Revision as of 17:52, 26 October 2018 by Benrwong (talk | contribs)
Jump to navigation Jump to search

If you have a new drive you want to add to your system, it's not going to work right out of the box. It needs to be correctly formatted a partition table and a linux-friendly filesystem.

On a CentOS 6 workstation: Create a new disk label:

[bwong1@band Desktop]$ sudo parted /dev/sdb mklabel gpt                         
Information: You may need to update /etc/fstab.   

Create a single partition using optimal settings that utilizes all free space

[bwong1@band Desktop]$ sudo parted -a optimal /dev/sdb mkpart primary 0% 100%
Information: You may need to update /etc/fstab.    

Make sure config is right so far by printing it: [bwong1@band Desktop]$ sudo parted -a optimal /dev/sdb mkpart primary 0% 100%

[bwong1@band Desktop]$ sudo parted /dev/sdb print
Model: ST8000DM 0004-1ZC11G (scsi)
Disk /dev/sdb: 8002GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Number  Start   End     Size    File system  Name     Flags
 1      1049kB  8002GB  8002GB               primary

Write a filesystem to the newly created disk partition:

[bwong1@band Desktop]$ sudo mkfs -t xfs /dev/sdb1
meta-data=/dev/sdb1              isize=256    agcount=8, agsize=268435455 blks
         =                       sectsz=512   attr=2, projid32bit=0
data     =                       bsize=4096   blocks=1953506304, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0
log      =internal log           bsize=4096   blocks=521728, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

Mount the new filesystem identified by diskid partition to a place of your choice. I mount it to /mnt/usb because I'm using a usb attached HDD.

[bwong1@band Desktop]$ sudo mount /dev/sdb1 /mnt/usb
[bwong1@band Desktop]$ df -hl /mnt/usb/
Filesystem      Size  Used Avail Use% Mounted on
/dev/sdb1       7.3T   33M  7.3T   1% /mnt/usb