Linux 下在线扩容的几种方式及说明
在生产环境中磁盘空间不足,但又不方便停机维护的状况不可避免. 以下操作可以在部分情况下在线扩容而不需要停机. 扩容操作从空间来源上来说有两种方式,原磁盘增加空间和新增磁盘. Linux下磁盘分区也主要会分两种,LVM和EXT[3/4] 从空间目的地来说也会有两种,扩展原有分区和新增分区并挂载. 但总的流程基本一致,即 追加空间 --> 让kernel 识别刷新容量 --> 对新加空间进行分区操作 --> 交付文件系统使用 .
发布日期:2022-02-01 13:46:19
浏览次数:32
分类:技术文章
本文共 5266 字,大约阅读时间需要 17 分钟。
以下主要针对VM环境下的Linux在线扩容
流程圖
在VM中新增磁盘并交付系统使用
和Windows不一样,Linux下新增磁盘或对原磁盘增加容量并不会自动被kernel识别到.
VM 中加入新的磁盘
过程略
扫描SCSI 总线以识别到新加入的设备
echo “- - -” > /sys/class/scsi_host/host0/scan
此处的host0,指的是第一个scsi host adapter ,对应ESXI中磁盘的设备节点SCSI(0:1)中的0.
传送的"- - -" 中的三个"-" 表示扫描所有 channel (first -), every target (second -), and every device i.e. disk/lun(third -)为识别到的新磁盘分区
[root]# fdisk /dev/sdbCommand (m for help):nCommand action e extended p primary partition (1 - 4 )pPartition number (1 - 4 ):1First cylinder (1-261,default 1):Using default value 1Last cylinder or + size or +sizeM or +sizeK(1-261, default 261):Using default value 261Command (m for help): wThe partition table has been altered!Calling ioctr() to re-read partition table.Syncing disks
为新分区准备文件系统
[root]# msfs -t ext3 /dev/sdb1mke2fs 1.39 (29-May-2006)Filesystem label=OS type:LinuxBlock size=4096 (log=2)Fragment size=4096(log=2)...Writing inode tables: doneCreating journal (4096 blocks): doneWriting superblocks and filesystem accounting information: doneThis filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
建立目录,并将新空间挂载
[root]#mkdir /tmp/dd[root]#mount /dev/sdb1 /tmp/dd
为以后自动挂载,编辑/etc/fstab
/dev/sdb1 /tmp/dd ext3 defaults 0 0设备 挂载点 文件系统 挂载规则 dump order
挂载规则:
auto 开机自动挂载 default 按照大多数永久文件系统的缺省值设置挂载定义 noauto 开机不自动挂载 nouser 只有超级用户可以挂载 ro 按只读权限挂载 rw 按可读可写权限挂载 user 任何用户都可以挂载 order 指fsck(启动时fsck检查的顺序)。为0就表示不检查,(/)分区永远都 是1,其它的分区只能从2开始,当数字相同就同时检查(但不能有两1)。在VM中对已有磁盘扩容
VM中增加现有磁盘大小
过程略
注意:如果此磁盘存在快照,则无法操作.原因显而易见.重新扫描改变大小的磁盘
[root@ksyoweb01 ~]# echo 1> /sys/class/block/sda/device/rescan #kernel 3.x[root@ksyoweb01 ~]#echo 1>/sys/class/scsi_device/0:0:1:0/device/block:sdb/device/rescan #kernel 2.x
重新分区以使用新增的空间
[root@ksyoweb01 ~]# fdisk /dev/sdb命令 (m 以獲得說明):d分割區編號 (1,2, default 2): 2Partition 2 is deleted命令 (m 以獲得說明):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分割區編號 (2-4, default 2): 2起初 sector (1026048-92274687, 預設 1026048):使用預設值 1026048最後 sector, +sectors 或 +大小{K,M,G} (1026048-92274687, 預設 92274687):使用預設值 92274687Partition 2 of type Linux and of size 43.5 GiB is set**如果是分配给LVM的则需要指定type**命令 (m 以獲得說明):t分割區編號 (1,2, default 2): 2Hex code (type L to list all codes): 8eChanged type of partition 'Linux' to 'Linux LVM'呼叫 ioctl() 以重新讀取分割表。WARNING: Re-reading the partition table failed with error 16: 裝置或系統資源忙碌中.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)同步磁碟。
注意:
较旧版核心在写入分区表的提示为 The new table will be used at the next reboot. 这表明在线扩容梦想破灭,只能重启.通知系统分区表的变化 partprobe:
[root@ksyoweb01 ~]# partprobe Error: /dev/sda 上的分割區 2 已被寫入,但是我們並無法將變更通報內核,或許是因為它/它們正在使用中,結果造成繼續使用舊的分割區。在進行進一步的變更之前,您應該立刻重新開機。
如果出现上面的提示,表示很不幸必须得重启.
改变文件系统的大小
root@test:~# resize2fs /dev/sdb2resize2fs 1.42.9 (4-Feb-2014)Filesystem at /dev/sdb2 is mounted on /; on-line resizing requiredold_desc_blocks = 2, new_desc_blocks = 4The filesystem on /dev/vda1 is now 12976128 blocks long.
LVM 情况下操作
[root@ksyoweb01 ~]# pvdisplay
— Physical volume — PV Name /dev/sda2 VG Name centos PV Size 39.51 GiB / not usable 2.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 10114 Free PE 11 Allocated PE 10103 PV UUID JLiFFR-TWvr-E6uW-x77q-dZl1-MfrZ-T2PhUw[root@ksyoweb01 ~]# pvresize /dev/sda2
Physical volume “/dev/sda2” changed 1 physical volume(s) resized / 0 physical volume(s) not resized [root@ksyoweb01 ~]# pvdisplay — Physical volume — PV Name /dev/sda2 VG Name centos PV Size 43.51 GiB / not usable 2.00 MiB Allocatable yes PE Size 4.00 MiB Total PE 11138 Free PE 1035 Allocated PE 10103 PV UUID JLiFFR-TWvr-E6uW-x77q-dZl1-MfrZ-T2PhUw [root@ksyoweb01 ~]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos lvm2 a-- 43.51g 4.04g [root@ksyoweb01 ~]# vgs VG #PV #LV #SN Attr VSize VFree centos 1 2 0 wz–n- 43.51g 4.04g [root@ksyoweb01 ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos -wi-ao---- 35.59g swap centos -wi-ao---- 3.88g [root@ksyoweb01 ~]# lvextend -L +4G -f -r /dev/centos/root Size of logical volume centos/root changed from 35.59 GiB (9111 extents) to 39.59 GiB (10135 extents). Logical volume centos/root successfully resized. meta-data=/dev/mapper/centos-root isize=256 agcount=4, agsize=2332416 blks = sectsz=512 attr=2, projid32bit=1 = crc=0 finobt=0 data = bsize=4096 blocks=9329664, imaxpct=25 = sunit=0 swidth=0 blks naming =version 2 bsize=4096 ascii-ci=0 ftype=0 log =internal bsize=4096 blocks=4555, version=2 = sectsz=512 sunit=0 blks, lazy-count=1 realtime =none extsz=4096 blocks=0, rtextents=0 data blocks changed from 9329664 to 10378240[root@ksyod03 kyosfcs]# resize2fs -p /dev/VolGroup00/LogVol02
resize2fs 1.39 (29-May-2006) Filesystem at /dev/VolGroup00/LogVol02 is mounted on /oracle; on-line resizing r Performing an on-line resize of /dev/VolGroup00/LogVol02 to 144433152 (4k) blocks. The filesystem on /dev/VolGroup00/LogVol02 is now 144433152 blocks long. #注: -p 是指打印進度所以,很明显.如果后续可能会有在线空间扩展需求的,请使用LVM,不然的话,在线空间扩展只是个梦.
转载地址:https://blog.csdn.net/shidb/article/details/99713808 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2024年03月02日 16时28分47秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
java iso 8601_如何在iOS上获得ISO 8601日期?
2019-04-21
windows8怎么下载python_win8怎么安装python
2019-04-21
linux猜数字程序,用linux实现猜数字小游戏源码
2019-04-21
linux下堆栈溢出实例,堆栈溢出在Linux上沉默?
2019-04-21
python创建nc文件_工具箱第2期 用python玩转NC
2019-04-21
拆分文件_文件拆分与合并
2019-04-21
开发优势_小程序开发优势好处有哪些
2019-04-21
4光影补丁_我的世界seus光影包
2019-04-21
aria手机下载_Aria2App
2019-04-21
汇编指令msr_ARM汇编:MRS和MSR指令
2019-04-21
lsof查看占用高_lsof解决磁盘占用过高,查询却无大文件处理一例!
2021-06-24
java ee6教程_Java EE 极简教程(六):框架的选择
2021-06-24
java io流过滤流_IO流分类详细介绍和各种字节流类介绍与使用 过滤流 字节流
2021-06-24
java预处理指令_Java程序员学C++_1_C++中的预处理命令 | 学步园
2021-06-24
java中的%不对 如何处理_Java心得--异常及其处理
2021-06-24
java 上传速度计算_java常见3种文件上传速度对比和文件上传方法详细代码
2021-06-24