Practice of fdisk and parted partition under centos

Requirement: add a 100M hard disk and permanently mount it to / data01, write out the detailed operation steps

Method 1:

[root@localhost ~]# fdisk -l |grep 'sdb'
Disk /dev/sdb: 106 MB, 106954752 bytes

[root@localhost ~]# fdisk -cu /dev/sdb
Command (m for help): m
Command action
  ......
   d   delete a partition
   l    list known partition types
   m   print this menu
   n   add a new partition
   p   print the partition table
   q   quit without saving changes
   w   write table to disk and exit

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p  
Partition number (1-4): 1
First sector (2048-208895, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-208895, default 208895): 
Using default value 208895

Command (m for help): p

Disk /dev/sdb: 106 MB, 106954752 bytes
64 heads, 32 sectors/track, 102 cylinders, total 208896 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: 0x65338ab6

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048      208895      103424   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

#Inform the system that the partition table of / dev/sdb hard disk has changed
[root@localhost ~]# partprobe /dev/sdb

[root@localhost ~]# mkfs.ext4 /dev/sdb1

#Turn off automatic checking of partitions
[root@localhost ~]# tune2fs -c 0 -i 0 /dev/sdb1
//Notes:
-c 0 count   Turn off the function of how many disk checks per mount
-i 0 interval Turn off disk checking every 180 days

[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  5.0G   14G  27% /
tmpfs           120M     0  120M   0% /dev/shm
/dev/sda1       190M   35M  145M  20% /boot
[root@localhost ~]# mkdir /data01
[root@localhost ~]# mount /dev/sdb1 /data01
[root@localhost ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        19G  5.0G   14G  27% /
tmpfs           120M     0  120M   0% /dev/shm
/dev/sda1       190M   35M  145M  20% /boot
/dev/sdb1        94M  1.6M   88M   2% /data01

[root@localhost ~]# vim /etc/fstab 
....
/dev/sdb1               /data01                 ext4    defaults        0 0

//The first 0 means: turn off the automatic backup function
//The second 0 indicates that the disk auto check function is turned off

Method two:
Use parted tool to partition (it can be used for data disk partition larger than 2T). Common parameter description:

p[rint] displays partition table information
mklabel creates a partition table. The available partition tables are: gpt, msdos(mbr)
mkpart create partition
rm delete partition
q exit without saving

parted /dev/sdb mklabel gpt y
parted /dev/sdb mkpart primary 0 -1 Ignore(All capacity is assigned to a partition by default)
parted /dev/sdb p

partprobe /dev/sdb
mkfs.ext4 /dev/sdb1 
tune2fs -c 0 -i 0 /dev/sdb1
/bin/mount /dev/sdb1 /data01/
df -h
echo "/bin/mount /dev/sdb1 /data01/" >>/etc/rc.local 

Step summary:
1. partition
2. Inform the system / dev/sdb that the partition table of the hard disk has changed the format to create the file system
3. Format and create file system
4. Turn off automatic check of disk partition
5. Mount the partition
6. Carry out permanent mount (automatic mount after power on)

Tags: Linux vim

Posted on Wed, 04 Dec 2019 11:29:02 -0500 by sun14php