Formatting an drive for use in Linux: Difference between revisions

From DISI
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 5: Line 5:
  [bwong1@band Desktop]$ sudo parted /dev/sdb mklabel gpt                         
  [bwong1@band Desktop]$ sudo parted /dev/sdb mklabel gpt                         
  Information: You may need to update /etc/fstab.   
  Information: You may need to update /etc/fstab.   
*Note: if the drive was previously used and you're okay with wiping it, you'll see the following:*
[bwong1@band ~]$ sudo parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                             
Information: You may need to update /etc/fstab.


Create a single partition using optimal settings that utilizes all free space
Create a single partition using optimal settings that utilizes all free space
Line 11: Line 17:


Make sure config is right so far by printing it:  
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 -a optimal /dev/sdb mkpart primary 0% 100%                           
  [bwong1@band Desktop]$ sudo parted /dev/sdb print
  [bwong1@band Desktop]$ sudo parted /dev/sdb print
  Model: ST8000DM 0004-1ZC11G (scsi)
  Model: ST8000DM 0004-1ZC11G (scsi)
Line 30: Line 36:
           =                      sectsz=512  sunit=0 blks, lazy-count=1
           =                      sectsz=512  sunit=0 blks, lazy-count=1
  realtime =none                  extsz=4096  blocks=0, rtextents=0
  realtime =none                  extsz=4096  blocks=0, rtextents=0
If this disk has a previous fileystem on disk, use mkfs -f to force overwrite over the previous filesystem. 


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.   
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.   

Latest revision as of 19:04, 13 November 2018

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.   
  • Note: if the drive was previously used and you're okay with wiping it, you'll see the following:*
[bwong1@band ~]$ sudo parted /dev/sdb mklabel gpt
Warning: The existing disk label on /dev/sdb will be destroyed and all data on this disk will be lost. Do you want to continue?
Yes/No? yes                                                               
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

If this disk has a previous fileystem on disk, use mkfs -f to force overwrite over the previous filesystem.

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