前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >linux扩容(增加硬盘)并挂载

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

作者头像
用户9949933
发布2023-02-24 17:15:58
12.8K0
发布2023-02-24 17:15:58
举报
文章被收录于专栏:何以解忧 唯有暴富

说明:

当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
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-04-13,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 说明:
  • 步骤:
    • 给新硬盘分区
      • 格式化分区
        • 使linux系统开机自动挂载新分区
        相关产品与服务
        对象存储
        对象存储(Cloud Object Storage,COS)是由腾讯云推出的无目录层次结构、无数据格式限制,可容纳海量数据且支持 HTTP/HTTPS 协议访问的分布式存储服务。腾讯云 COS 的存储桶空间无容量上限,无需分区管理,适用于 CDN 数据分发、数据万象处理或大数据计算与分析的数据湖等多种场景。
        领券
        问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档