目的:
原數據盤最大是/home。想拆分一部分做/data。如下圖:
拆分后:
解決方案:
首先查看磁盤情況,然后再進行判斷。
我這邊收到的服務器是進行了邏輯卷划分,格式是xfs的。那么我可以進行正對xfs格式的邏輯卷縮容后,重新划分出一個較大的邏輯卷掛載在/data
操作步驟:
1. 查看磁盤情況
# fdisk -l
跟據上面情況可以看出,是做了邏輯卷處理。
2. 查看物理卷
# pvscan
一個物理卷,名叫centos
查看物理卷狀態:
#pvdisplay
物理卷我們不需要操作。
3.查看卷組和邏輯卷
卷組:
# vgdisplay
邏輯卷:
# lvscan
查看邏輯卷詳情
# lvdisplay
[root@vonedaonode2 ~]# lvdisplay --- Logical volume --- LV Path /dev/centos/swap LV Name swap VG Name centos LV UUID GkhFxa-GTcs-Ppy3-Hyuu-vb0U-I8vs-3Q4sgm LV Write Access read/write LV Creation host, time localhost, 2020-03-18 17:59:06 +0800 LV Status available # open 0 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/centos/home LV Name home VG Name centos LV UUID 90OFWF-eKjq-jpQf-Euy8-jPoB-uw2o-tyPPQF LV Write Access read/write LV Creation host, time localhost, 2020-03-18 17:59:06 +0800 LV Status available # open 1 LV Size <141.12 GiB Current LE 36126 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 8192 Block device 253:2 --- Logical volume --- LV Path /dev/centos/root LV Name root VG Name centos LV UUID 0AldrL-0PJy-ivsB-nTBj-gQUb-IZmT-AJfW7T LV Write Access read/write LV Creation host, time localhost, 2020-03-18 17:59:07 +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
對/dev/centos/home邏輯卷進行縮容,/dev/centos/home是xfs格式的。
4. 邏輯卷縮容
xfs不支持縮容,不需要卸載。
重新設置邏輯卷大小:# lvresize -L 20G /dev/mapper/centos-home
查看邏輯卷重新分配的情況,/dev/centos/home已經變小
查看物理卷,物理卷多出121.12G空閑
使df -h查看時生效:# xfs_growfs /dev/mapper/centos-home
發現執行后沒生效:
卸載后重新掛載也是失敗:
修復,失敗:
翻車現場....!!! 所以,不管怎樣,操作之前需要將/home 備份下。翻車后還能補救。
額....新服務器,/home下沒有什么內容.....
格式化重新掛載吧。
# mkfs.xfs -f /dev/mapper/centos-home
查看:
5. 創建邏輯卷
# lvcreate --name data -l 100%Free centos
# lvcreate --name 邏輯卷名稱 -l 大小 卷組名稱
6. 格式化邏輯卷,掛載
# mkfs.xfs /dev/centos/data
# mkdir /data
# mount /dev/centos/data /data
加入到/etc/fstab中: