boot lvm 分区_Linux如何在线对逻辑分区扩容
Linux如何在線對(duì)邏輯分區(qū)擴(kuò)容
1.前言
目前絕大部分IaaS平臺(tái)基本都會(huì)選擇類似Vmware Vsphere+SAN存算分離的架構(gòu),或者選擇類似Nutanix、Vmware Vsan或者深信服等存算一體的超融合架構(gòu)。
不管何種方式,都會(huì)遇到已掛載目錄磁盤空間不足的情況,部分分區(qū)空間使用不夠情況。
希望在不影響現(xiàn)有業(yè)務(wù)的情況下,動(dòng)態(tài)將某個(gè)掛載點(diǎn)目錄擴(kuò)容。
如果這些分區(qū)在裝系統(tǒng)的時(shí)候使用了lvm(前提是這些分區(qū)要是lvm邏輯卷分區(qū)),那么就可以輕松進(jìn)行擴(kuò)容或縮容。
1.1 環(huán)境介紹
| 操作系統(tǒng) | Red Hat Enterprise Linux Server release 7.8 (Maipo) |
| CPU | 4C |
| 內(nèi)存 | 16G |
| 硬盤1(原有硬盤) | 120G |
| 硬盤2(擬添加的硬盤) | 500G ?,希望掛載在/root下,將原有/root進(jìn)行動(dòng)態(tài)擴(kuò)容 |
2.幾個(gè)常用命令介紹
2.1 fdisk命令
fdisk一般用來磁盤分區(qū),也可以用來查看磁盤分區(qū)情況。
/dev/sda1和/dev/sda2是兩個(gè)主分區(qū),其中前者是啟動(dòng)分區(qū)。
注意/dev/sda2是LVM文件系統(tǒng),這個(gè)是后續(xù)動(dòng)態(tài)擴(kuò)容的關(guān)鍵點(diǎn)。
后續(xù)兩個(gè)就是邏輯卷分別是:
Disk /dev/mapper/rhel-root: 119.2 GB
Disk /dev/mapper/rhel-swap: 8455 MB
[root@test1?~]#?fdisk?-lDisk?/dev/sda:?128.8?GB,?128849018880?bytes,?251658240?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:?0x000bcae5
???Device?Boot??????Start?????????End??????Blocks???Id??System
/dev/sda1???*????????2048?????2099199?????1048576???83??Linux
/dev/sda2?????????2099200???251412479???124656640???8e??Linux?LVM
Disk?/dev/mapper/rhel-root:?119.2?GB,?119185342464?bytes,?232783872?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/rhel-swap:?8455?MB,?8455716864?bytes,?16515072?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
2.2 lsblk命令
lsblk命令用于列出所有可用塊設(shè)備的信息,而且還能顯示他們之間的依賴關(guān)系,這個(gè)命令很好用,因?yàn)榭梢宰岆娔X上的磁盤和分區(qū)信息很清晰。
[root@test1?~]#?lsblkNAME??????????MAJ:MIN?RM???SIZE?RO?TYPE?MOUNTPOINT
sda?????????????8:0????0???120G??0?disk
├─sda1??????????8:1????0?????1G??0?part?/boot
└─sda2??????????8:2????0?118.9G??0?part
??├─rhel-root?253:0????0???111G??0?lvm??/
??└─rhel-swap?253:1????0???7.9G??0?lvm??[SWAP]
sr0????????????11:0????1??1024M??0?rom?
這里同樣看出系統(tǒng)已有一塊硬盤sda,具備兩個(gè)分區(qū),分別是sda1和sda2。
其中sda2分區(qū)有兩個(gè)邏輯卷,分別就是上述對(duì)應(yīng)的rhel-root和rhel-swap。
注意:這里rhel-root和rhel-swap,兩者都被“-”分割開。
rhel是vg,是卷組(Volume Group, VG)
后者root和swap是邏輯卷(Logical Volume, LV)。
正是在邏輯卷上做文件系統(tǒng)。也正是邏輯卷創(chuàng)建之后,其大小可以伸縮。
2.3 df命令
linux中df命令的功能是用來檢查linux服務(wù)器的文件系統(tǒng)的磁盤空間占用情況。可以利用該命令來獲取硬盤被占用了多少空間,目前還剩下多少空間等信息。顯示指定磁盤文件的可用空間。
df這個(gè)命令讀取的數(shù)據(jù)計(jì)劃都是針對(duì)整個(gè)文件系統(tǒng)的,主要在super block內(nèi)信息,因此讀取速度非常快速。
[root@test1?~]#?df?-ThFilesystem????????????Type??????Size??Used?Avail?Use%?Mounted?on
devtmpfs??????????????devtmpfs??3.9G?????0??3.9G???0%?/dev
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/dev/shm
tmpfs?????????????????tmpfs?????3.9G??8.9M??3.9G???1%?/run
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/sys/fs/cgroup
/dev/mapper/rhel-root?xfs???????111G???98G???13G??89%?/
/dev/sda1?????????????xfs??????1014M??137M??878M??14%?/boot
tmpfs?????????????????tmpfs?????799M?????0??799M???0%?/run/user/0
注:
1、tmpfs,臨時(shí)文件系統(tǒng),是一種基于內(nèi)存的文件系統(tǒng)。和ramdisk不同,后者是個(gè)塊設(shè)備,前者是個(gè)文件系統(tǒng)。
2、df下是不顯示swap分區(qū)的。所以這里只顯示/dev/mapper/rhel-root。
可以看出來rhel-root是xfs文件系統(tǒng)
在RHEL7系統(tǒng)中比較大的變化之一就是在文件系統(tǒng)方面使用XFS替換了Ext4,XFS作為最新RHEL7中默認(rèn)的文件管理系統(tǒng),它的日志型文件管理系統(tǒng)的優(yōu)勢(shì)在意外宕機(jī)后尤其明顯,可以快速的恢復(fù)可能被破壞的文件,另外經(jīng)過優(yōu)化后日志功能對(duì)硬盤性能影響非常小,同時(shí)最大支持18EB的存儲(chǔ)容量滿足了幾乎所有需求。
3.正式擴(kuò)容
熱添加一塊硬盤
在虛擬機(jī)管理平臺(tái)上,熱添加一塊硬盤。
【驗(yàn)證】
[root@test1?~]#?fdisk?-lDisk?/dev/sda:?128.8?GB,?128849018880?bytes,?251658240?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:?0x000bcae5
???Device?Boot??????Start?????????End??????Blocks???Id??System
/dev/sda1???*????????2048?????2099199?????1048576???83??Linux
/dev/sda2?????????2099200???251412479???124656640???8e??Linux?LVM
Disk?/dev/mapper/rhel-root:?119.2?GB,?119185342464?bytes,?232783872?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/rhel-swap:?8455?MB,?8455716864?bytes,?16515072?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/sdb:?536.9?GB,?536870912000?bytes,?1048576000?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
從最后可以看出/dev/sdb為536.9 GB容量,這里是沒有任何分區(qū)的。
查看當(dāng)前pv、vg以及l(fā)v的情況。
[root@test1?~]#?pvdisplay??---?Physical?volume?---
??PV?Name???????????????/dev/sda2
??VG?Name???????????????rhel
??PV?Size???????????????118.88?GiB?/?not?usable?3.00?MiB
??Allocatable???????????yes
??PE?Size???????????????4.00?MiB
??Total?PE??????????????30433
??Free?PE???????????????1
??Allocated?PE??????????30432
??PV?UUID???????????????6c2uwi-e0el-9kdl-UexC-5Qut-LbCv-eNfrQ0
[root@test1?~]#?vgdisplay
??---?Volume?group?---
??VG?Name???????????????rhel
??System?ID
??Format????????????????lvm2
??Metadata?Areas????????1
??Metadata?Sequence?No??3
??VG?Access?????????????read/write
??VG?Status?????????????resizable
??MAX?LV????????????????0
??Cur?LV????????????????2
??Open?LV???????????????2
??Max?PV????????????????0
??Cur?PV????????????????1
??Act?PV????????????????1
??VG?Size???????????????<118.88?GiB
??PE?Size???????????????4.00?MiB
??Total?PE??????????????30433
??Alloc?PE?/?Size???????30432?/?<118.88?GiB
??Free??PE?/?Size???????1?/?4.00?MiB
??VG?UUID???????????????UeFmSr-CGD1-JNp1-XwtC-40xI-SVF6-CezPm6
[root@test1?~]#?lvdisplay
??---?Logical?volume?---
??LV?Path????????????????/dev/rhel/swap
??LV?Name????????????????swap
??VG?Name????????????????rhel
??LV?UUID????????????????4k1EM3-EYGL-0BKL-oei6-UNBW-BOBC-259HY4
??LV?Write?Access????????read/write
??LV?Creation?host,?time?localhost.localdomain,?2020-09-20?15:25:16?+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
??---?Logical?volume?---
??LV?Path????????????????/dev/rhel/root
??LV?Name????????????????root
??VG?Name????????????????rhel
??LV?UUID????????????????wEU6li-W6fr-7TfV-3OJ2-5o0i-mbez-rptO1M
??LV?Write?Access????????read/write
??LV?Creation?host,?time?localhost.localdomain,?2020-09-20?15:25:16?+0800
??LV?Status??????????????available
??#?open?????????????????1
??LV?Size????????????????111.00?GiB
??Current?LE?????????????28416
??Segments???????????????1
??Allocation?????????????inherit
??Read?ahead?sectors?????auto
??-?currently?set?to?????8192
??Block?device???????????253:0
關(guān)于pv、vg以及l(fā)v的關(guān)系詳見下圖:
#?創(chuàng)建一個(gè)新的pv[root@test1?~]#?pvcreate?/dev/sdb
WARNING:?dos?signature?detected?on?/dev/sdb?at?offset?510.?Wipe?it??[y/n]:?y
??Wiping?dos?signature?on?/dev/sdb.
??Physical?volume?"/dev/sdb"?successfully?created.
#?驗(yàn)證
[root@test1?~]#?pvscan
??PV?/dev/sda2???VG?rhel????????????lvm2?[<118.88?GiB?/?4.00?MiB?free]
??PV?/dev/sdb???????????????????????lvm2?[500.00?GiB]
??Total:?2?[<618.88?GiB]?/?in?use:?1?[<118.88?GiB]?/?in?no?VG:?1?[500.00?GiB]
注意要選擇dev/sdb這個(gè)新加的硬盤
擴(kuò)展vg
[root@test1?~]#?vgextend?rhel?/dev/sdb??Volume?group?"rhel"?successfully?extended
[root@test1?~]#?pvscan
??PV?/dev/sda2???VG?rhel????????????lvm2?[<118.88?GiB?/?4.00?MiB?free]
??PV?/dev/sdb????VG?rhel????????????lvm2?[<500.00?GiB?/?<500.00?GiB?free]
??Total:?2?[<618.88?GiB]?/?in?use:?2?[<618.88?GiB]?/?in?no?VG:?0?[0???]
擴(kuò)展lv
#?擴(kuò)展前[root@test1?~]#?lvscan
??ACTIVE????????????'/dev/rhel/swap'?[<7.88?GiB]?inherit
??ACTIVE????????????'/dev/rhel/root'?[111.00?GiB]?inherit?
#?擴(kuò)展500G
[root@test1?~]#?lvextend?-L?+500G?/dev/rhel/root
??Size?of?logical?volume?rhel/root?changed?from?111.00?GiB?(28416?extents)?to?611.00?GiB?(156416?extents).
??Logical?volume?rhel/root?successfully?resized.
#?驗(yàn)證
[root@test1?~]#?lvscan
??ACTIVE????????????'/dev/rhel/swap'?[<7.88?GiB]?inherit
??ACTIVE????????????'/dev/rhel/root'?[611.00?GiB]?inherit
這時(shí)候通過lsblk查看,/root已經(jīng)擴(kuò)展到611G空間
[root@test1?~]#?lsblkNAME??????????MAJ:MIN?RM???SIZE?RO?TYPE?MOUNTPOINT
sda?????????????8:0????0???120G??0?disk
├─sda1??????????8:1????0?????1G??0?part?/boot
└─sda2??????????8:2????0?118.9G??0?part
??├─rhel-root?253:0????0???611G??0?lvm??/
??└─rhel-swap?253:1????0???7.9G??0?lvm??[SWAP]
sdb?????????????8:16???0???500G??0?disk
└─rhel-root???253:0????0???611G??0?lvm??/
sr0????????????11:0????1??1024M??0?rom?
但是通過df命令發(fā)現(xiàn)實(shí)際并沒有正式擴(kuò)容
[root@test1?~]#?df?-ThFilesystem????????????Type??????Size??Used?Avail?Use%?Mounted?on
devtmpfs??????????????devtmpfs??3.9G?????0??3.9G???0%?/dev
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/dev/shm
tmpfs?????????????????tmpfs?????3.9G??8.9M??3.9G???1%?/run
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/sys/fs/cgroup
/dev/mapper/rhel-root?xfs???????111G???99G???13G??89%?/
/dev/sda1?????????????xfs??????1014M??137M??878M??14%?/boot
tmpfs?????????????????tmpfs?????799M?????0??799M???0%?/run/user/0
這里需要用xfs_growfs對(duì)邏輯分區(qū)做最后調(diào)整
[root@test1?~]#?xfs_growfs?/dev/rhel/rootmeta-data=/dev/mapper/rhel-root??isize=512????agcount=4,?agsize=7274496?blks
?????????=???????????????????????sectsz=512???attr=2,?projid32bit=1
?????????=???????????????????????crc=1????????finobt=0?spinodes=0
data?????=???????????????????????bsize=4096???blocks=29097984,?imaxpct=25
?????????=???????????????????????sunit=0??????swidth=0?blks
naming???=version?2??????????????bsize=4096???ascii-ci=0?ftype=1
log??????=internal???????????????bsize=4096???blocks=14208,?version=2
?????????=???????????????????????sectsz=512???sunit=0?blks,?lazy-count=1
realtime?=none???????????????????extsz=4096???blocks=0,?rtextents=0
data?blocks?changed?from?29097984?to?160169984
#?驗(yàn)證,可以看到這里已經(jīng)是611G空間大小了。
[root@test1?~]#?df?-Th
Filesystem????????????Type??????Size??Used?Avail?Use%?Mounted?on
devtmpfs??????????????devtmpfs??3.9G?????0??3.9G???0%?/dev
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/dev/shm
tmpfs?????????????????tmpfs?????3.9G??8.9M??3.9G???1%?/run
tmpfs?????????????????tmpfs?????3.9G?????0??3.9G???0%?/sys/fs/cgroup
/dev/mapper/rhel-root?xfs???????611G???99G??513G??17%?/
/dev/sda1?????????????xfs??????1014M??137M??878M??14%?/boot
tmpfs?????????????????tmpfs?????799M?????0??799M???0%?/run/user/0
需要注意的是,針對(duì)部分老系統(tǒng),還是用ext3或者ext4的,最后一步邏輯分區(qū)調(diào)整大小的命令有所區(qū)別。
1、針對(duì)的是ext2、ext3、ext4文件系統(tǒng),使用resize2fs 命令。增大和縮小都支持
2、針對(duì)的是xfs文件系統(tǒng),使用的事xfs_growfs 命令,但是只支持增大。
至此,針對(duì)使用lvm文件分區(qū)前提下的在線擴(kuò)容使用完畢,對(duì)現(xiàn)有業(yè)務(wù)和應(yīng)用是沒有影響的。
生產(chǎn)環(huán)境下不建議,所需要的空間不應(yīng)該由縮容其他分區(qū)得到,而是直接利用IaaS平臺(tái)的虛擬化手段熱添加硬盤。
by 2020年10月11日 張誠(chéng)
總結(jié)
以上是生活随笔為你收集整理的boot lvm 分区_Linux如何在线对逻辑分区扩容的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用python做简单的地理聚类分析案例_
- 下一篇: cairosvg在linux中的安装_直