CentOS挂载新硬盘

Title: CentOS挂载新硬盘
Date: 2021-12-2 11:25:31
Modified: 2021-12-2 11:25:31
Category: Linux
Tags: Liunx
Slug: Linux-SSD-OS
Authors: Stiller
Summary: 在CentOS中挂载新硬盘,在Linux中加入新的硬盘并格式化

首先可以使用下方的命令看到系统中还没有挂载但是以及硬件连接的硬盘

fdisk -l

[root@iZuf6f2otzp0yw4rl0g8t9Z /]# fdisk -l
Disk /dev/vda: 50 GiB, 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
Disklabel type: dos
Disk identifier: 0x1863aa79

Device     Boot Start       End   Sectors Size Id Type
/dev/vda1  *     2048 104857566 104855519  50G 83 Linux


Disk /dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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

分区初始化进入fdisk命令行(需要根据磁盘名称进行进入)

fdisk /dev/vdb

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

使用p命令查看当前的硬盘状态,使用n进行磁盘的初始化,系统会询问是否需要创建扩展空间或者是主空间,如果只是挂载在新目录这种情况的话,不需要扩展空间,需要创建主空间或者是逻辑空间。

在创建新分区时会自动的选择整个磁盘的空间,如果需要进行分区,可以指定开始的区块和结束的区块。

Command (m for help): p
Disk dev/vdb: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: dos
Disk identifier: 0x9944bbe0

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199): 

Created a new partition 1 of type 'Linux' and of size 100 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

使用w进行保存,如果分区设置错误,可以使用d进行删除,或者直接不保存退出q

创建分区结束需要进行格式化和挂载,格式化为ext4分区,如下命令所示。

[root@iZuf6f2otzp0yw4rl0g8t9Z /]# mkfs -t ext4 /dev/vdb1
mke2fs 1.44.3 (10-July-2018)
Found a dos partition table in /dev/vdb1
Proceed anyway? (y,N) y
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: bd11270a-0269-4981-a4e1-9f37d153700a
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000, 7962624, 11239424, 20480000, 23887872

接下来进行挂载,可以选择临时挂载mount /dev/vdb1 /data或者是自动挂载(使用lsblk -f可以查看硬盘的UUID通过UUID也可以挂载),这里直接写入自动挂载文件中。

[root@iZuf6f2otzp0yw4rl0g8t9Z data]# vim /etc/fstab 


# 
# /etc/fstab
# Created by anaconda on Wed Dec 25 03:29:46 2019
#
# 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.
#
# After editing this file, run 'systemctl daemon-reload' to update systemd
# units generated from this file.
#
UUID=e32cfa7a-df48-4031-8fdf-5eec92ee3039 /                       xfs     defaults        0 0
/dev/vdb1       /data   ext4    defaults        0 0

需要注意的是,挂载的硬盘名称需要正确的书写,在fstab文件中,第一位是挂载的硬盘名称,第二位是挂载的文件夹名称,第三位是硬盘的格式,第四位是文件系统参数(同步、是否自动挂载、是否只读、是否允许挂载,是否允许SUID存在、是否支持磁盘配额、是否默认),第五位是是否被dump备份命令(0不备份, 1 每天备份、 2 不定日期操作),第六位是否检查扇区(开始时)

最后执行mount -a 进行挂载(需要fstab中数据第四位字段挂载参数改写为auto直接defaults也行)

最后可以执行df -h查看文件大小命令。

[root@iZuf6f2otzp0yw4rl0g8t9Z data]# 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  444K  7.8G   1% /run
tmpfs           7.8G     0  7.8G   0% /sys/fs/cgroup
/dev/vda1        50G  2.6G   48G   6% /
tmpfs           1.6G     0  1.6G   0% /run/user/0
/dev/vdb1        98G   61M   93G   1% /data

挂载成功。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值