Implementation of formatting partitions and mounting in Centos7

Implementation of formatting partitions and mounting in Centos7

Linux often encounters situations such as adding hard disks or remounting partitions. This article simply records the situation of mounting new partitions. Since the disk partition has been processed before, this time we start recording from the steps of formatting the partition and subsequent mounting.

1. Check the current disk status

[root@pgtest59 ~]# df -lh 
File system capacity used Available used% Mount point /dev/sdb3 50G 994M 50G 2% /
devtmpfs 47G 0 47G 0% /dev
tmpfs 47G 0 47G 0% /dev/shm
tmpfs 47G 11M 47G 1% /run
tmpfs 47G 0 47G 0% /sys/fs/cgroup
/dev/sdb1 1014M 134M 881M 14% /boot
/dev/sdb5 392G 33M 392G 1% /home
tmpfs 9.3G 0 9.3G 0% /run/user/0
tmpfs 9.3G 0 9.3G 0% /run/user/1001 

This time, we will add a new hard disk and mount it to /data, so we will create a mount point first.

[root@pgtest59 ~]# mkdir /data

2. View partition information

[root@pgtest59 ~]# fdisk -l 

Disk /dev/sda: 17997.3 GB, 17997255147520 bytes, 35150888960 sectors Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk /dev/sdb: 480.0 GB, 480036847616 bytes, 937571968 sectors Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes/4096 bytes I/O size (minimum/optimal): 4096 bytes/4096 bytes Disk label type: dos
Disk identifier: 0x000b3fc7

  DeviceBoot Start End Blocks Id System
/dev/sdb1 * 2048 2099199 1048576 83 Linux
/dev/sdb2 2099200 10487807 4194304 82 Linux swap / Solaris
/dev/sdb3 10487808 115345407 52428800 83 Linux
/dev/sdb4 115345408 937570303 411112448 5 Extended
/dev/sdb5 115347456 937570303 411111424 83 Linux

Note: The fdisk -l command can only display information about devices that can perform partition operations (for example, CDs will not be displayed), and it will display whether the partition is mounted or not.

Because the current disk is not formatted, direct mounting will result in an error, for example:

/* Mount without formatting */
[root@pgtest59 ~]# mount /dev/sda /data/
mount: /dev/sda is write-protected, and will be mounted read-only mount: unknown file system type '(null)'

3. Format the partition

[root@pgtest59 ~]# mkfs.xfs /dev/sda  
meta-data=/dev/sda isize=512 agcount=17, agsize=268435455 blks
     = sectsz=4096 attr=2, projid32bit=1
     = crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=4393861120, imaxpct=5
     = sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=521728, version=2
     = sectsz=4096 sunit=1 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Note: This format is xfs, but it can also be formatted into ext4 or ext3 or other required formats.

4. Mount the partition

/* Mount partition */
[root@pgtest59 ~]# mount /dev/sda /data/

/* View results */
[root@pgtest59 ~]# df -Th
File system type Capacity Used Available Used% Mount point /dev/sdb3 xfs 50G 1.6G 49G 4% /
devtmpfs devtmpfs 47G 0 47G 0% /dev
tmpfs tmpfs 47G 0 47G 0% /dev/shm
tmpfs tmpfs 47G 11M 47G 1% /run
tmpfs tmpfs 47G 0 47G 0% /sys/fs/cgroup
/dev/sdb1 xfs 1014M 134M 881M 14% /boot
/dev/sdb5 xfs 392G 33M 392G 1% /home
/dev/sda xfs 17T 33M 17T 1% /data
tmpfs tmpfs 9.3G 0 9.3G 0% /run/user/1001

5. Set up automatic mounting at boot

This step is easy to miss. In many cases, after completing the previous steps, the partition has been mounted successfully. However, if the machine is restarted, the directory will not be available directly (it cannot be viewed by the df command), so it needs to be set to automatically mount at boot time.

vim /etc/fstab
/* Add the following information */
/dev/sda /data xfs defaults 0 0 

Note: The device to be mounted can be one of the following:

  • The name of the device file, such as /dev/sda
  • LABEL of the device
  • The UUID of the device. This method is more commonly used in CentOS 7.
  • Pseudo file systems: such as sysfs, proc, tmpfs, etc.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • Complete steps for mounting a new data disk in CentOS7
  • How to mount a data disk on Tencent Cloud Server Centos
  • Centos7 hard disk mounting method
  • Learn how to mount Centos7 soft raid5
  • How to mount a new data disk on Alibaba Cloud CentOS
  • Centos7 installation and configuration of NFS service and mounting tutorial (recommended)
  • How to mount disk in centos7 cloud host system
  • Detailed explanation of CentOS Alibaba Cloud server hard disk partition and mounting
  • Tutorial on mounting SSD cloud disk on Alibaba Cloud CentOS 7 system

<<:  How to implement load balancing in MySQL

>>:  Solution to mysql server 5.5 connection failure

Recommend

How to install Zookeeper service on Linux system

1. Create the /usr/local/services/zookeeper folde...

Let's learn about MySQL database

Table of contents 1. What is a database? 2. Class...

Web page custom selection box Select

Everyone may be familiar with the select drop-dow...

Vue computed properties

Table of contents 1. Basic Examples 2. Computed p...

MySQL Practical Experience of Using Insert Statement

Table of contents 1. Several syntaxes of Insert 1...

Unicode signature BOM detailed description

Unicode Signature BOM - What is the BOM? BOM is th...

Commonplace talk about the usage of MYSQL pattern matching REGEXP and like

like LIKE requires the entire data to match, whil...

Super detailed tutorial to implement Vue bottom navigation bar TabBar

Table of contents Project Introduction: Project D...

MySQL chooses the appropriate data type for id

Table of contents Summary of Distributed ID Solut...

js to implement collision detection

This article example shares the specific code of ...

Vue uses Baidu Maps to realize city positioning

This article shares the specific code of Vue usin...

Solution for adding iptables firewall policy to MySQL service

If your MySQL database is installed on a centos7 ...

Vue implements internationalization of web page language switching

1. Basic steps 1: Install yarn add vue-i18n Creat...