Centos7 xfs filesystem LVM 擴容與 縮減
裝好 ELK5.5後突然發現昨天請 noc 安裝 CentOS7 的時候竟然 /root 只有切50GB 剩下空間再 /home
想透過lvm縮擴容,使用resize2fs的時候竟然出現 Bad magic number in super-block while,
經過查詢後原來是 resize2fs 只有支援 ext2 ext3 ext4 ,Centos7 以後系統預設使用xfs
上網查詢了下 Redhat 官網竟然說 xfs 無法reduced 只能 enlarge, 差點崩潰 .....
想透過lvm縮擴容,使用resize2fs的時候竟然出現 Bad magic number in super-block while,
經過查詢後原來是 resize2fs 只有支援 ext2 ext3 ext4 ,Centos7 以後系統預設使用xfs
上網查詢了下 Redhat 官網竟然說 xfs 無法reduced 只能 enlarge, 差點崩潰 .....
爬文後的結論就是 接把 LVM 當中的 /home LV 幹掉 後重新切一個 LV
就會有剩餘的空間可以再透過lvextened 到 我要的 /root 的LV當中
就會有剩餘的空間可以再透過lvextened 到 我要的 /root 的LV當中
- xfs filesystem 無法線上縮減只能擴容
- 採用方法是
1. Backup the data
2. Remove current LV
3. Create a smaller LV
4. Restore the data
5. Extend VG size to LV
6. xfsgrow LV
## 查看原本LV 大小 root 50GB , home 91.12GB
[root@ELK /]# lvdisplay
--- Logical volume ---
LV Path /dev/cl_elk/swap
LV Name swap
VG Name cl_elk
LV UUID qiw9ZR-CnX8-2ivf-L4AN-qK4c-0IOF-bnNOn6
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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/cl_elk/root
LV Name root
VG Name cl_elk
LV UUID 9OZzCE-LaAj-hqnd-e30c-kIAD-P6Ie-Bta7Lb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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
--- Logical volume ---
LV Path /dev/cl_elk/home
LV Name home
VG Name cl_elk
LV UUID aBUwG6-3MY6-p3RI-MA37-ZUCI-DLCW-W1h826
LV Write Access read/write
LV Creation host, time ELK, 2017-07-12 14:02:14 +0800
LV Status available
# open 1
LV Size 91.12 GiB
Current LE 23327
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
## xfsdump 備份原本的 home目錄資料
[root@ELK ~]# xfsdump -l 0 -f /home.image /dev/mapper/cl_elk-home
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control
============================= dump label dialog ==============================
please enter label for this dump session (timeout in 300 sec)
-> 20170712-dump
session label entered: "20170712-dump"
--------------------------------- end dialog ---------------------------------
xfsdump: WARNING: most recent level 0 dump was interrupted, but not resuming that dump since resume (-R) option not specified
xfsdump: level 0 dump of ELK:/home
xfsdump: dump date: Wed Jul 12 14:38:59 2017
xfsdump: session id: f8f18a13-c481-4a34-a97f-8a8b7c7a4c7b
xfsdump: session label: "20170712-dump"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 34368 bytes
============================= media label dialog =============================
please enter label for media in drive 0 (timeout in 300 sec)
-> home-old
media label entered: "home-old"
--------------------------------- end dialog ---------------------------------
xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 25608 bytes
xfsdump: dump size (non-dir files) : 1632 bytes
xfsdump: dump complete: 11 seconds elapsed
xfsdump: Dump Summary:
xfsdump: stream 0 /home.image OK (success)
xfsdump: Dump Status: SUCCESS
## 移除 cl_elk-home 的LV 因為要縮小空間 所以剛透過xfsdump 備份後幹掉重新做
[root@ELK /]# lvremove /dev/mapper/cl_elk-home
Do you really want to remove active logical volume cl_elk/home? [y/n]: y
Logical volume "home" successfully removed
## 原本 /dev/mapper/cl_elk-home 已消失被幹掉了
[root@ELK /]# lvdisplay
--- Logical volume ---
LV Path /dev/cl_elk/swap
LV Name swap
VG Name cl_elk
LV UUID qiw9ZR-CnX8-2ivf-L4AN-qK4c-0IOF-bnNOn6
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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/cl_elk/root
LV Name root
VG Name cl_elk
LV UUID 9OZzCE-LaAj-hqnd-e30c-kIAD-P6Ie-Bta7Lb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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
## 查看現在VG有多少空間 91.12g , 正好是剛剛幹掉 /dev/mapper/cl_elk-home 之後跑出來的 91.12g
[root@ELK /]# vgs
VG #PV #LV #SN Attr VSize VFree
cl_elk 1 2 0 wz--n- 149.00g 91.12g
## 重新建立一個 LV 給 home 並給予10G空間 , 故意取名和剛剛的 LV名稱一樣 這樣就不需要修改 /etc/fstab 開機後就會自動MOUNT上因為名稱一樣
[root@ELK /]# lvcreate -L 10G -n home cl_elk
WARNING: xfs signature detected on /dev/cl_elk/home at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/cl_elk/home.
Logical volume "home" created.
## 查看VG發現減少10GB 剩下 81.12GB 因為剛剛切給
[root@ELK /]# vgs
VG #PV #LV #SN Attr VSize VFree
cl_elk 1 3 0 wz--n- 149.00g 81.12g
##剛剛切好的 LV 格式化為 xfs
[root@ELK /]# mkfs.xfs -f /dev/cl_elk/home
meta-data=/dev/cl_elk/home isize=512 agcount=4, agsize=655360 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=2621440, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
## 查看 LV 有剛剛重新建立好的 /dev/mapper/cl_elk-home 10GB size
[root@ELK ~]# lvdisplay
--- Logical volume ---
LV Path /dev/cl_elk/root
LV Name root
VG Name cl_elk
LV UUID 9OZzCE-LaAj-hqnd-e30c-kIAD-P6Ie-Bta7Lb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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
--- Logical volume ---
LV Path /dev/cl_elk/home
LV Name home
VG Name cl_elk
LV UUID aBUwG6-3MY6-p3RI-MA37-ZUCI-DLCW-W1h826
LV Write Access read/write
LV Creation host, time ELK, 2017-07-12 14:02:14 +0800
LV Status available
# open 0
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
## 將 /home mount 回去 ( 因為LV名稱 PATH都一樣不需要修改 /etc/fstab ) , 並且透過 xfsrestore 將 剛剛 xfsdump的檔案導回,相關目錄
[root@ELK /]# mount /home
[root@ELK ~]# xfsrestore -f /home.image /home
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description:
xfsrestore: hostname: ELK
xfsrestore: mount point: /home
xfsrestore: volume: /dev/mapper/cl_elk-home
xfsrestore: session time: Wed Jul 12 13:31:18 2017
xfsrestore: level: 0
xfsrestore: session label: "20170712-dump"
xfsrestore: media label: "home-old"
xfsrestore: file system id: a66f4384-a507-44ce-bb3d-85afe9f2ec78
xfsrestore: session id: 788ed49a-0b11-41a0-9426-ec39d1a2f00e
xfsrestore: media id: 8aeb6294-4936-49e3-bb1e-925bde9e247e
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 2 directories and 4 entries processed
xfsrestore: directory post-processing
xfsrestore: restoring non-directory files
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore: stream 0 /home.image OK (success)
xfsrestore: Restore Status: SUCCESS
## VG 剩餘 81.12GB
[root@ELK /]# vgs
VG #PV #LV #SN Attr VSize VFree
cl_elk 1 3 0 wz--n- 149.00g 81.12g
## 將剩餘的 VG 容量擴充到 /dev/mapper/cl_elk-root 變成 131.12GB
[root@ELK /]# lvextend /dev/mapper/cl_elk-root -L +81.12G
Rounding size to boundary between physical extents: 81.12 GiB.
Size of logical volume cl_elk/root changed from 50.00 GiB (12800 extents) to 131.12 GiB (33567 extents).
Logical volume cl_elk/root successfully resized.
[root@ELK /]# lvdisplay
--- Logical volume ---
LV Path /dev/cl_elk/swap
LV Name swap
VG Name cl_elk
LV UUID qiw9ZR-CnX8-2ivf-L4AN-qK4c-0IOF-bnNOn6
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +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/cl_elk/root
LV Name root
VG Name cl_elk
LV UUID 9OZzCE-LaAj-hqnd-e30c-kIAD-P6Ie-Bta7Lb
LV Write Access read/write
LV Creation host, time localhost.localdomain, 2017-07-11 18:14:33 +0800
LV Status available
# open 1
LV Size 131.12 GiB
Current LE 33567
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:0
--- Logical volume ---
LV Path /dev/cl_elk/home
LV Name home
VG Name cl_elk
LV UUID 4Z3UZu-gKae-jZrW-iCmH-YWBR-Aeqd-3gbqre
LV Write Access read/write
LV Creation host, time ELK, 2017-07-12 14:08:26 +0800
LV Status available
# open 1
LV Size 10.00 GiB
Current LE 2560
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 8192
Block device 253:2
## VG 容量已經被分配完畢 VFree 0
[root@ELK /]# vgs
VG #PV #LV #SN Attr VSize VFree
cl_elk 1 3 0 wz--n- 149.00g 0
## 這邊查看實體 還是只有 47GB 是因為LV擴充了 但是filesystem需要 resize 系統才會抓到完整容量
[root@ELK /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl_elk-root 50G 3.4G 47G 7% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 25M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/cl_elk-home 10G 33M 10G 1% /home
## xfs_growfs resize
[root@ELK /]# xfs_growfs /dev/mapper/cl_elk-root -d
meta-data=/dev/mapper/cl_elk-root isize=512 agcount=4, agsize=3276800 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=13107200, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal bsize=4096 blocks=6400, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0
data blocks changed from 13107200 to 34372608
## 查看 已經擴充到和 LV 一樣的大小 128GB
[root@ELK /]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl_elk-root 132G 3.4G 128G 3% /
devtmpfs 7.8G 0 7.8G 0% /dev
tmpfs 7.8G 0 7.8G 0% /dev/shm
tmpfs 7.8G 25M 7.8G 1% /run
tmpfs 7.8G 0 7.8G 0% /sys/fs/cgroup
/dev/sda1 1014M 184M 831M 19% /boot
tmpfs 1.6G 0 1.6G 0% /run/user/0
/dev/mapper/cl_elk-home 10G 33M 10G 1% /hom
參考資料 :
我覺得這個滿不錯的~~
回覆刪除感謝分享
收錄了