Linux系统下centos中在线添加硬盘后不重启在线扩容linux系统目录不重启系统

Centos7 在线添加硬盘不重启系统

CentOS 7在线添加新磁盘,无需重启 现有环境基本都是线下server以及线上虚拟机等,几乎都支持热插拔,热扩容,所以在线添加新磁盘就尤为重要,这样可以无需中断当前服务或进程也可对其进行添加硬盘操作。

1.添加硬盘:

虚拟机在线状态下对其进行添加硬盘操作,

此处添加 2 块 20G 的 scsi 盘






以上则是添加虚拟机磁盘的傻瓜式完整步骤。

添加完两块磁盘后点击确定。

2.进入终端刷新

切回终端查看是否有新加的磁盘

由此可见是没有的。

c 复制代码
[root@compute ~]# lsblk   
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   160G  0 disk 
├─sda1            8:1    0     1G  0 part /boot
└─sda2            8:2    0 158.9G  0 part 
  ├─centos-root 253:0    0   103G  0 lvm  /
  ├─centos-swap 253:1    0   5.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0    50G  0 lvm  /home
sr0              11:0    1   4.2G  0 rom  
[root@compute ~]# 

现在使用下列命令对其进行刷新:

c 复制代码
ls /sys/class/scsi_host/ 
echo '- - -' >/sys/class/scsi_host/host0/scan
echo '- - -' >/sys/class/scsi_host/host1/scan 
echo '- - -' >/sys/class/scsi_host/host2/scan 

再次刷新查看磁盘即可发现磁盘已被刷新出来

c 复制代码
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  150G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0  149G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 91.1G  0 lvm  /home
sdb               8:16   0   60G  0 disk 
sr0              11:0    1  4.2G  0 rom 

即可发现添加刷新成功。

注:图中磁盘大小和命令显示磁盘大小不一致,但操作不影响

Centos7在线添加添加硬盘不重启系统 Success!!!

接下来对添加的磁盘,进行root目录扩容

c 复制代码
[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 0xf94e704a.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 
First sector (2048-125829119, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-125829119, default 125829119): 
Using default value 125829119
Partition 1 of type Linux and of size 60 GiB is set

Command (m for help): 
Command (m for help): w
The partition table has been altered!

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

查看磁盘是否创建成功,会发现sdb下多了一个sdb1,即是成功

c 复制代码
[root@localhost ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0  150G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0  149G  0 part 
  ├─centos-root 253:0    0   50G  0 lvm  /
  ├─centos-swap 253:1    0  7.9G  0 lvm  [SWAP]
  └─centos-home 253:2    0 91.1G  0 lvm  /home
sdb               8:16   0   60G  0 disk 
└─sdb1            8:17   0   60G  0 part 
sr0              11:0    1  4.2G  0 rom 

创建pv卷

c 复制代码
[root@localhost ~]# pvcreate /dev/sdb1 
  Physical volume "/dev/sdb1" successfully created.

创建扩展vg卷

c 复制代码
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  4
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <149.00 GiB
  PE Size               4.00 MiB
  Total PE              38143
  Alloc PE / Size       38142 / 148.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               u2kTsr-4zBE-RIYe-gBgv-bC4W-Zfp0-Qp0r5o
c 复制代码
[root@localhost ~]# vgextend centos /dev/sdb1       
  Volume group "centos" successfully extended

扩展lv卷:(使用lvdisplay ,查看lv卷的路径,确认要扩展的lv卷是哪个)

c 复制代码
[root@localhost ~]# lvdisplay 
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                E3AGUF-VK8W-j8CF-qPec-WyjO-uexw-g2wDvr
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-10-01 00:29:41 +0800
  LV Status              available
  # open                 1
  LV Size                50.00 GiB
  Current LE             12800
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                sYivRD-1Uda-Qt8H-PoHf-zeS2-6Z7h-jP6VQY
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-10-01 00:29:41 +0800
  LV Status              available
  # open                 1
  LV Size                <91.12 GiB
  Current LE             23326
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                0HqPth-SCIV-iySF-VnOk-p0jA-jbm6-M9o6US
  LV Write Access        read/write
  LV Creation host, time localhost, 2022-10-01 00:29:42 +0800
  LV Status              available
  # open                 2
  LV Size                <7.88 GiB
  Current LE             2016
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
c 复制代码
[root@localhost ~]# lvextend -L +59G /dev/centos/root
  Size of logical volume centos/root changed from 50.00 GiB (12800 extents) to 109.00 GiB (27904 extents).
  Logical volume centos/root successfully resized.

修改完会发现并未生效

c 复制代码
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs        50G   19G   32G  38% /
devtmpfs                devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G   12M  3.8G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  142M  873M  14% /boot
/dev/mapper/centos-home xfs        92G   33M   92G   1% /home
tmpfs                   tmpfs     781M     0  781M   0% /run/user/0

对其进行刷新
centos6:

c 复制代码
[root@localhost ~]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

centos7:

c 复制代码
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=3276800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=13107200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=6400, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 13107200 to 28573696

最后再进行查看,会发现centos-root目录下由50G扩展至109G了

c 复制代码
[root@localhost ~]# df -Th
Filesystem              Type      Size  Used Avail Use% Mounted on
/dev/mapper/centos-root xfs       109G   19G   91G  18% /
devtmpfs                devtmpfs  3.8G     0  3.8G   0% /dev
tmpfs                   tmpfs     3.9G     0  3.9G   0% /dev/shm
tmpfs                   tmpfs     3.9G   12M  3.8G   1% /run
tmpfs                   tmpfs     3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sda1               xfs      1014M  142M  873M  14% /boot
/dev/mapper/centos-home xfs        92G   33M   92G   1% /home
tmpfs                   tmpfs     781M     0  781M   0% /run/user/0

热扩容成功!!!

相关推荐
码农土豆6 分钟前
PaddlePaddle飞桨Linux系统Docker版安装
linux·docker·paddlepaddle
Hacker_xingchen11 分钟前
天融信Linux系统安全问题
linux·运维·系统安全
丘狸尾12 分钟前
[cisco 模拟器] ftp服务器配置
android·运维·服务器
黑客老陈20 分钟前
新手小白如何挖掘cnvd通用漏洞之存储xss漏洞(利用xss钓鱼)
运维·服务器·前端·网络·安全·web3·xss
张暮笛21 分钟前
抓取手机HCI日志
linux
大猫和小黄23 分钟前
Windows、CentOS环境下搭建自己的版本管理资料库:GitBlit
linux·服务器·windows·git
Joyner201827 分钟前
【Linux】ubuntu通过远程命令行启动桌面应用
linux·服务器·ubuntu
ghostwritten30 分钟前
Linux Swap: 深入解析 mkswap, mkfs.swap, 和 swapon
linux·运维·服务器
我是唐青枫32 分钟前
Linux xargs 命令使用教程
linux·运维·服务器
gallonyin32 分钟前
【监控】夜莺监控系统各环节资源压力分析
运维·服务器