Linux下磁盘的分区和挂载

查看硬盘情况

  fdisk -l

对上述查到的硬盘进行分区

      fdisk  /dev/vda

    命令(输入 m 获取帮助):p   #查看现有分区

     磁盘 /dev/vda:429.5 GB, 429496729600 字节,838860800 个扇区

    Units = 扇区 of 1 * 512 = 512 bytes
   扇区大小(逻辑/物理):512 字节 / 512 字节
   I/O 大小(最小/最佳):512 字节 / 512 字节
  磁盘标签类型:dos
  磁盘标识符:0x00098d78

   设备 Boot Start End Blocks Id System
   /dev/vda1 * 2048 2099199 1048576 83 Linux
  /dev/vda2 2099200 104857599 51379200 8e Linux LVM

命令(输入 m 获取帮助):n   #新增分区
Partition type:
p primary (2 primary, 0 extended, 2 free)
e extended
Select (default p): p   增加主分区

分区号 (3,4,默认 3):
起始 扇区 (104857600-838860799,默认为 104857600):
将使用默认值 104857600
Last 扇区, +扇区 or +size{K,M,G} (104857600-838860799,默认为 838860799):+100GB
分区 3 已设置为 Linux 类型,大小设为 93.1 GiB

命令(输入 m 获取帮助):w   #写入
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
正在同步磁盘

[root@localhost ~]#  partprobe    #刷新让磁盘可以被看到

[root@localhost ~]#  ls /dev/vda   #按Tab键看现有分区

 格式化分区

  mkfs.xfs  /dev/vdb3  #新买数据盘,要先格式化,才能挂载

配置开机自动挂载文件

[root@localhost ~]#  vi /etc/fstab   #增加如下内容

/dev/vda3 /home xfs defaults 0 0
/dev/vda4 /opt xfs defaults 0 0

挂载

       [root@localhost ~]# mount -a    #挂载

       [root@localhost ~]#  df -h #现在就可以看到刚刚新挂载上去的磁盘空间了

posted @ 2021-12-31 10:54  一只竹节虫  阅读(163)  评论(0编辑  收藏  举报