Centos7格式化分区并挂载 - 开发说
当前位置: 主页 » Centos » Centos7格式化分区并挂载

Centos7格式化分区并挂载

      2020年07月02日   阅读 1,174 次     0 评论   Tags:

Centos7格式化硬盘并挂载,centos默认文件系统为xfs,centos6文件系统为ext4,所以此处推荐xfs文件系统。

1、查看硬盘情况 fdisk -l



[root@localhost ~]# fdisk -l

Disk /dev/sdb: 1099.5 GB, 1099511627776 bytes, 2147483648 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 label type: dos
Disk identifier: 0xd722822d

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  2147483647  1073740800   83  Linux

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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 label type: dos
Disk identifier: 0x000bada1

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   104857599    51379200   8e  Linux LVM

Disk /dev/mapper/centos-root: 47.2 GB, 47240445952 bytes, 92266496 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 /dev/mapper/centos-swap: 5368 MB, 5368709120 bytes, 10485760 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

2、开始分区以sdb为例



[root@localhost ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xd722822d.

Command (m for help): n    (此处输入n,注意如果需要对sdb进行重新分区,需要先umount /dev/sdb1 然后修改/etc/fstab,删除添加的哪一行,重启系统,然后在此处输入d,在重复此步骤即可)
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p    (此处输入p)
Partition number (1-4, default 1):      (直接回车)
First sector (2048-2147483647, default 2048):       (直接回车)
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-2147483647, default 2147483647): 
Using default value 2147483647
Partition 1 of type Linux and of size 1024 GiB is set

Command (m for help): w      (输入w,把分区信息写入磁盘)
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@localhost ~]#  mkfs.xfs -f /dev/sdb1     (格式化分区)
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=67108800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=268435200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=131071, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
[root@localhost ~]# mkdir /data     (创建挂载目录/data)
[root@localhost ~]# mount -t xfs /dev/sdb1 /data     (把/dev/sdb1挂载到/data目录)
[root@localhost ~]# df -h      (查看系统硬盘分区状态)
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 7.8G     0  7.8G   0% /dev
tmpfs                    7.8G     0  7.8G   0% /dev/shm
tmpfs                    7.8G  8.9M  7.8G   1% /run
tmpfs                    7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/mapper/centos-root   44G  1.9G   43G   5% /
/dev/sda1               1014M  188M  826M  19% /boot
/dev/sdb1                1.0T   33M  1.0T   1% /data
tmpfs                    1.6G     0  1.6G   0% /run/user/0


3、设置开机自动挂载



[root@localhost ~]# vi /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Jul  2 18:00:27 2020
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/centos-root /                       xfs     defaults        0 0
UUID=46c44b98-bcb5-4da7-9b15-520c3bc32bbd /boot                   xfs     defaults        0 0
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1 /data xfs defaults 0 0      (加入此行)

  • 版权声明:本文版权归开发说和原作者所有,未经许可不得转载。文章部分来源于网络仅代表作者看法,如有不同观点,欢迎进行交流。除非注明,文章均由 开发说 整理发布,欢迎转载,转载请带版权。

  • 来源:开发说 ( https://www.kaifashuo.com/ ),提供主机优惠信息深度测评和服务器运维编程技术。
  • 链接:https://www.kaifashuo.com/2158.html
  • 评论(0

    1. 还没有任何评论,你来说两句吧

    发表回复

    您的邮箱地址不会被公开。 必填项已用 * 标注