boot lvm 分区_Linux如何在线对逻辑分区扩容
Linux如何在線對邏輯分區擴容
1.前言
目前絕大部分IaaS平臺基本都會選擇類似Vmware Vsphere+SAN存算分離的架構,或者選擇類似Nutanix、Vmware Vsan或者深信服等存算一體的超融合架構。
不管何種方式,都會遇到已掛載目錄磁盤空間不足的情況,部分分區空間使用不夠情況。
希望在不影響現有業務的情況下,動態將某個掛載點目錄擴容。
如果這些分區在裝系統的時候使用了lvm(前提是這些分區要是lvm邏輯卷分區),那么就可以輕松進行擴容或縮容。
1.1 環境介紹
| 操作系統 | Red Hat Enterprise Linux Server release 7.8 (Maipo) |
| CPU | 4C |
| 內存 | 16G |
| 硬盤1(原有硬盤) | 120G |
| 硬盤2(擬添加的硬盤) | 500G ?,希望掛載在/root下,將原有/root進行動態擴容 |
2.幾個常用命令介紹
2.1 fdisk命令
fdisk一般用來磁盤分區,也可以用來查看磁盤分區情況。
/dev/sda1和/dev/sda2是兩個主分區,其中前者是啟動分區。
注意/dev/sda2是LVM文件系統,這個是后續動態擴容的關鍵點。
后續兩個就是邏輯卷分別是:
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命令用于列出所有可用塊設備的信息,而且還能顯示他們之間的依賴關系,這個命令很好用,因為可以讓電腦上的磁盤和分區信息很清晰。
[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?
這里同樣看出系統已有一塊硬盤sda,具備兩個分區,分別是sda1和sda2。
其中sda2分區有兩個邏輯卷,分別就是上述對應的rhel-root和rhel-swap。
注意:這里rhel-root和rhel-swap,兩者都被“-”分割開。
rhel是vg,是卷組(Volume Group, VG)
后者root和swap是邏輯卷(Logical Volume, LV)。
正是在邏輯卷上做文件系統。也正是邏輯卷創建之后,其大小可以伸縮。
2.3 df命令
linux中df命令的功能是用來檢查linux服務器的文件系統的磁盤空間占用情況。可以利用該命令來獲取硬盤被占用了多少空間,目前還剩下多少空間等信息。顯示指定磁盤文件的可用空間。
df這個命令讀取的數據計劃都是針對整個文件系統的,主要在super block內信息,因此讀取速度非常快速。
[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,臨時文件系統,是一種基于內存的文件系統。和ramdisk不同,后者是個塊設備,前者是個文件系統。
2、df下是不顯示swap分區的。所以這里只顯示/dev/mapper/rhel-root。
可以看出來rhel-root是xfs文件系統
在RHEL7系統中比較大的變化之一就是在文件系統方面使用XFS替換了Ext4,XFS作為最新RHEL7中默認的文件管理系統,它的日志型文件管理系統的優勢在意外宕機后尤其明顯,可以快速的恢復可能被破壞的文件,另外經過優化后日志功能對硬盤性能影響非常小,同時最大支持18EB的存儲容量滿足了幾乎所有需求。
3.正式擴容
熱添加一塊硬盤
在虛擬機管理平臺上,熱添加一塊硬盤。
【驗證】
[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容量,這里是沒有任何分區的。
查看當前pv、vg以及lv的情況。
[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
關于pv、vg以及lv的關系詳見下圖:
#?創建一個新的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.
#?驗證
[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這個新加的硬盤
擴展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???]
擴展lv
#?擴展前[root@test1?~]#?lvscan
??ACTIVE????????????'/dev/rhel/swap'?[<7.88?GiB]?inherit
??ACTIVE????????????'/dev/rhel/root'?[111.00?GiB]?inherit?
#?擴展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.
#?驗證
[root@test1?~]#?lvscan
??ACTIVE????????????'/dev/rhel/swap'?[<7.88?GiB]?inherit
??ACTIVE????????????'/dev/rhel/root'?[611.00?GiB]?inherit
這時候通過lsblk查看,/root已經擴展到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命令發現實際并沒有正式擴容
[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對邏輯分區做最后調整
[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
#?驗證,可以看到這里已經是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
需要注意的是,針對部分老系統,還是用ext3或者ext4的,最后一步邏輯分區調整大小的命令有所區別。
1、針對的是ext2、ext3、ext4文件系統,使用resize2fs 命令。增大和縮小都支持
2、針對的是xfs文件系統,使用的事xfs_growfs 命令,但是只支持增大。
至此,針對使用lvm文件分區前提下的在線擴容使用完畢,對現有業務和應用是沒有影響的。
生產環境下不建議,所需要的空間不應該由縮容其他分區得到,而是直接利用IaaS平臺的虛擬化手段熱添加硬盤。
by 2020年10月11日 張誠
總結
以上是生活随笔為你收集整理的boot lvm 分区_Linux如何在线对逻辑分区扩容的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 用python做简单的地理聚类分析案例_
- 下一篇: mysql查看系统可用字符集_MySQL