Centos 邏輯卷擴(kuò)容

CentOS 7看了日志發(fā)現(xiàn)是/root只分配了1GiB大小,已接近飽和??偨Y(jié)一下步驟:

列出各分區(qū)使用情況:

# df -Th

Filesystem? ? ? ? ? ? ? Type? ? ? Size? Used Avail Use% Mounted on/dev/mapper/centos-root xfs? ? ? 997M? 994M? 2.9M 100% /devtmpfs? ? ? ? ? ? ? ? devtmpfs? 915M? ? 0? 915M? 0% /devtmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? ? 0? 921M? 0% /dev/shmtmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? 17M? 905M? 2% /runtmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? ? 0? 921M? 0% /sys/fs/cgroup/dev/mapper/centos-usr? xfs? ? ? 4.9G? 1.6G? 3.4G? 33% /usr/dev/sda1? ? ? ? ? ? ? xfs? ? ? ? 97M? 66M? 31M? 69% /boot/dev/mapper/centos-var? xfs? ? ? 2.4G? 473M? 1.9G? 21% /var

可以看見/dev/mapper/centos-root已經(jīng)使用了100%,我們準(zhǔn)備為它擴(kuò)容。

在VirtualBox中添加一塊新的虛擬磁盤:

先關(guān)閉操作系統(tǒng)。在VirtualBox中選中當(dāng)前VM,設(shè)置->存儲(chǔ)->控制器->SATA控制器,點(diǎn)擊圖標(biāo)“添加虛擬硬盤”,新建一個(gè)虛擬硬盤。我增加了一塊3GiB大小的虛擬磁盤,保存后再次啟動(dòng)虛擬機(jī)。

創(chuàng)建新分區(qū)

先看一下現(xiàn)有磁盤情況:

# fdisk -l

結(jié)果:

Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x000940ec? Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System/dev/sda1? *? ? ? ? 2048? ? ? 206847? ? ? 102400? 83? Linux/dev/sda2? ? ? ? ? 206848? ? 41943039? ? 20868096? 8e? Linux LVMDisk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-swap: 2097 MB, 2097152000 bytes, 4096000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-usr: 5242 MB, 5242880000 bytes, 10240000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/mapper/centos-root: 1048 MB, 1048576000 bytes, 2048000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytes.........

已經(jīng)可以看到新磁盤/dev/sdb。

對新磁盤進(jìn)行分區(qū):

# fdisk /dev/sdb

在fdisk的交互模式中,依次輸入:

n? --創(chuàng)建新分區(qū)

p? --創(chuàng)建主分區(qū)

<回車>? --默認(rèn)分區(qū)編號

<回車>? --默認(rèn)起始扇區(qū)位置。(無特殊需求,默認(rèn)就好)

<回車>? --默認(rèn)結(jié)束扇區(qū)位置。(可默認(rèn),若自己制定大小,格式為 +100GB)

w? --寫入分區(qū)表

這樣就把整個(gè)磁盤分成了一個(gè)區(qū)。

再看一下現(xiàn)有磁盤情況:

# fdisk -l

已經(jīng)多出了一個(gè)新分區(qū):

? Device Boot? ? ? Start? ? ? ? End? ? ? Blocks? Id? System/dev/sdb1? ? ? ? ? ? 2048? ? 6291455? ? 3144704? 83? Linux

將新分區(qū)用于擴(kuò)展/root

先看一下卷分組:

# vgdisplay -v

Finding all volume groups? ? Finding volume group "centos"? --- Volume group ---? VG Name? ? ? ? ? ? ? centos? System ID? ? ? ? ? ? ? Format? ? ? ? ? ? ? ? lvm2? Metadata Areas? ? ? ? 1? Metadata Sequence No? 6? VG Access? ? ? ? ? ? read/write? VG Status? ? ? ? ? ? resizable? MAX LV? ? ? ? ? ? ? ? 0? Cur LV? ? ? ? ? ? ? ? 5? Open LV? ? ? ? ? ? ? 5? Max PV? ? ? ? ? ? ? ? 0? Cur PV? ? ? ? ? ? ? ? 1? Act PV? ? ? ? ? ? ? ? 1? VG Size? ? ? ? ? ? ? 19.90 GiB? PE Size? ? ? ? ? ? ? 4.00 MiB? Total PE? ? ? ? ? ? ? 5094? Alloc PE / Size? ? ? 5093 / 19.89 GiB? Free? PE / Size? ? ? 1 / 4.00 MiB? VG UUID? ? ? ? ? ? ? vtJL08-7Jxi-5IqK-3fUg-Pben-682a-wiv2GL? ? --- Logical volume ---? LV Path? ? ? ? ? ? ? ? /dev/centos/root? LV Name? ? ? ? ? ? ? ? root? VG Name? ? ? ? ? ? ? ? centos? LV UUID? ? ? ? ? ? ? ? ZWTgoT-AMWs-g54v-dZA1-NQUj-mqGa-8tmr4U? LV Write Access? ? ? ? read/write? LV Creation host, time localhost, 2016-07-03 21:59:31 -0400? LV Status? ? ? ? ? ? ? available? # open? ? ? ? ? ? ? ? 1? LV Size? ? ? ? ? ? ? ? 1000.00 MiB? Current LE? ? ? ? ? ? 250? Segments? ? ? ? ? ? ? 1? Allocation? ? ? ? ? ? inherit? Read ahead sectors? ? auto? currently set to? ? 256? Block device? ? ? ? ? 253:2? ...? ...? ...? --- Physical volumes ---? PV Name? ? ? ? ? ? ? /dev/sda2? ? ? PV UUID? ? ? ? ? ? ? fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC? PV Status? ? ? ? ? ? allocatable? Total PE / Free PE? ? 5094 / 1?

可以看到當(dāng)前卷分組名為"centos"。

為之前新增的分區(qū)創(chuàng)建物理卷:

# pvcreate /dev/sdb1

提示是否擦除xfs簽名,我選了y:

WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n] y

? Wiping xfs signature on /dev/sdb1.

? Physical volume "/dev/sdb1" successfully created

這里遇到錯(cuò)誤: Device /dev/vdd2 not found (or ignored by filtering). ,重啟機(jī)器就好了。

查看結(jié)果:

# pvdisplay

已經(jīng)看到新創(chuàng)建的3GiB大小的物理卷:

--- Physical volume ---

? PV Name? ? ? ? ? ? ? /dev/sda2

? VG Name? ? ? ? ? ? ? centos

? PV Size? ? ? ? ? ? ? 19.90 GiB / not usable 3.00 MiB

? Allocatable? ? ? ? ? yes

? PE Size? ? ? ? ? ? ? 4.00 MiB

? Total PE? ? ? ? ? ? ? 5094

? Free PE? ? ? ? ? ? ? 1

? Allocated PE? ? ? ? ? 5093

? PV UUID? ? ? ? ? ? ? fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC


? "/dev/sdb1" is a new physical volume of "3.00 GiB"

? --- NEW Physical volume ---

? PV Name? ? ? ? ? ? ? /dev/sdb1

? VG Name? ? ? ? ? ? ?

? PV Size? ? ? ? ? ? ? 3.00 GiB

? Allocatable? ? ? ? ? NO

? PE Size? ? ? ? ? ? ? 0?

? Total PE? ? ? ? ? ? ? 0

? Free PE? ? ? ? ? ? ? 0

? Allocated PE? ? ? ? ? 0

? PV UUID? ? ? ? ? ? ? VGXSAn-UiZ0-Fy40-eQxb-53xA-5hZM-3eGPg0

擴(kuò)展卷分組,"centos"是vgdisplay命令查到的卷分組名:

# vgextend centos /dev/sdb1

提示成功擴(kuò)展。

下面查看一下邏輯卷:

# lvdisplay

可以看到/dev/centos/root目前的LV Size是1000MiB。

下面擴(kuò)展邏輯卷/dev/centos/root:

# lvextend -L +3G /dev/centos/root

注:+3G是我們新增加的分區(qū)大小。

擴(kuò)展后,還要執(zhí)行一步:

# xfs_growfs /dev/centos/root

將文件系統(tǒng)擴(kuò)大。

完成。

因?yàn)榘惭bCentOS用的xfs分區(qū),所以使用命令xfs_growfs擴(kuò)展文件系統(tǒng)大小。否則的話使用resize2fs命令。

查看結(jié)果:

# df -Th

/root已經(jīng)擴(kuò)充到4GiB:

Filesystem? ? ? ? ? ? ? Type? ? ? Size? Used Avail Use% Mounted on

/dev/mapper/centos-root xfs? ? ? 4.0G? 995M? 3.1G? 25% /

devtmpfs? ? ? ? ? ? ? ? devtmpfs? 915M? ? 0? 915M? 0% /dev

tmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? ? 0? 921M? 0% /dev/shm

tmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? 8.4M? 913M? 1% /run

tmpfs? ? ? ? ? ? ? ? ? tmpfs? ? 921M? ? 0? 921M? 0% /sys/fs/cgroup

/dev/mapper/centos-usr? xfs? ? ? 4.9G? 1.6G? 3.4G? 33% /usr

/dev/mapper/centos-home xfs? ? ? 9.8G? 391M? 9.4G? 4% /home

/dev/mapper/centos-var? xfs? ? ? 2.4G? 469M? 1.9G? 20% /var

/dev/sda1? ? ? ? ? ? ? xfs? ? ? ? 97M? 66M? 31M? 69% /boot

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容