linux扩容(增加硬盘)并挂载

2023-02-24 17:15:58 浏览数 (1)

说明:

当Linux系统的硬盘空间不够时,我们需要添加新的硬盘。本文物理添加硬盘的方法略过,只介绍在linux系统的分区、格式化和挂载的内容。

系统环境:Centos 7.0

添加硬盘容量:100G

步骤:

给新硬盘分区
  • 使用fdisk -l 命令查看新加入磁盘
代码语言:javascript复制
[root@localhost.localdomain:/root]
# fdisk -l

Disk /dev/sdb: 107.4 GB, 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


Disk /dev/sda: 32.2 GB, 32212254720 bytes, 62914560 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: 0x000b1951

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    62914559    30944256   8e  Linux LVM

Disk /dev/mapper/centos-swap: 4194 MB, 4194304000 bytes, 8192000 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-root: 27.5 GB, 27489468416 bytes, 53690368 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 /dev/sdb命令进入磁盘进行分区
代码语言:javascript复制
[root@localhost.localdomain:/root]
# 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 0xe3b901db.

Command (m for help): n  <===新建分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p  <===新建主分区
Partition number (1-4, default 1): 1    <===分区序号
First sector (2048-209715199, default 2048):   <===直接回车
Using default value 2048 
Last sector,  sectors or  size{K,M,G} (2048-209715199, default 209715199):  <===直接回车
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): w    <===保存并退出
The partition table has been altered!

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

Command (m for help): p  <===按p查看新分区

Disk /dev/sdb: 107.4 GB, 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
Disk label type: dos
Disk identifier: 0xe3b901db

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   83  Linux  <===新建的分区
格式化分区
  • Centos7.0以上使用mkfs.xfs 命令格式化
代码语言:javascript复制
[root@localhost.localdomain:/root]
# mkfs.xfs /dev/sdb1  <===这里是新分区的路径,上面有。
meta-data=/dev/sdb1              isize=256    agcount=4, agsize=6553536 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=26214144, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal log           bsize=4096   blocks=12799, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
使linux系统开机自动挂载新分区
  • 新建挂载目录
代码语言:javascript复制
mkdir /data
  • 便捷/etc/fstab 文件,保存之后重启系统就可以看到新加的磁盘空间了。
代码语言:javascript复制
[root@localhost.localdomain:/root]
# vim /etc/fstab 

#
# /etc/fstab
# Created by anaconda on Thu Feb 20 22:40:37 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        1 1
UUID=50b753d4-9421-4ce5-9f54-0c7a95568ff9 /boot                   xfs     defaults        1 2
/dev/mapper/centos-swap swap                    swap    defaults        0 0
/dev/sdb1       /data   xfs     defaults        0 0   <===添加内容
  • 重启系统后查看硬盘
代码语言:javascript复制
[root@localhost.localdomain:/root]
# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   26G  955M   25G   4% /
devtmpfs                 3.9G     0  3.9G   0% /dev
tmpfs                    3.9G     0  3.9G   0% /dev/shm
tmpfs                    3.9G  8.5M  3.9G   1% /run
tmpfs                    3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sdb1                100G   33M  100G   1% /data   <===很完美
/dev/sda1                497M   96M  401M  20% /boot

0 人点赞