1. 程式人生 > 實用技巧 >linux系統中縮小邏輯卷

linux系統中縮小邏輯卷

相較於擴容邏輯卷,在對邏輯捲進行縮容操作時,其丟失資料的風險更大。所以在生產環境中執行相應操作時,一定要提前備份好資料。另外linux系統規定,在對

LVM邏輯捲進行縮容操作之前,要先檢查檔案系統的完整性(為了資料安全)。在執行縮容之前先把檔案系統解除安裝。

1、下載邏輯卷裝置的掛載

[root@linuxprobe dev]# df -h  ## 檢視掛載
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root         18G  2.9G   15G  17% /
devtmpfs                     985M     
0 985M 0% /dev tmpfs 994M 80K 994M 1% /dev/shm tmpfs 994M 8.9M 986M 1% /run tmpfs 994M 0 994M 0% /sys/fs/cgroup /dev/sda1 497M 119M 379M 24% /boot /dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0
Server.x86_64 /dev/mapper/vgtest1-lvtest1 287M 2.1M 266M 1% /linuxprobe [root@linuxprobe dev]# umount /linuxprobe/ ## 解除安裝 [root@linuxprobe dev]# df -h ## 檢視掛載 Filesystem Size Used Avail Use% Mounted on /dev/mapper/rhel-root 18G 2.9G 15G 17% / devtmpfs 985M 0 985M 0
% /dev tmpfs 994M 80K 994M 1% /dev/shm tmpfs 994M 8.9M 986M 1% /run tmpfs 994M 0 994M 0% /sys/fs/cgroup /dev/sda1 497M 119M 379M 24% /boot /dev/sr0 3.5G 3.5G 0 100% /run/media/root/RHEL-7.0 Server.x86_64

2、檢查檔案系統的完整性

[root@linuxprobe dev]# e2fsck -f /dev/vgtest1/lvtest1
e2fsck 1.42.9 (28-Dec-2013)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgtest1/lvtest1: 11/76000 files (0.0% non-contiguous), 15759/307200 blocks

3、把邏輯卷lvtest1的容量縮小到100MB

[root@linuxprobe dev]# lvdisplay  ## 檢視當前邏輯卷大小
  --- Logical volume ---
  LV Path                /dev/vgtest1/lvtest1
  LV Name                lvtest1
  VG Name                vgtest1
  LV UUID                oTCZoZ-CymC-Ce3k-JFGo-95ne-6lho-Y6a0Ll
  LV Write Access        read/write
  LV Creation host, time linuxprobe.com, 2020-10-29 16:30:51 +0800
  LV Status              available
  # open                 0
  LV Size                300.00 MiB
  Current LE             75
  Segments               1
  Allocation             inherit
………………
[root@linuxprobe dev]# resize2fs /dev/vgtest1/lvtest1 100M  ## 重置大小
resize2fs 1.42.9 (28-Dec-2013)
Resizing the filesystem on /dev/vgtest1/lvtest1 to 102400 (1k) blocks.
The filesystem on /dev/vgtest1/lvtest1 is now 102400 blocks long.

[root@linuxprobe dev]# lvreduce -L 100M /dev/vgtest1/lvtest1  ## 重置邏輯卷大小
  WARNING: Reducing active logical volume to 100.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvtest1? [y/n]: y
  Reducing logical volume lvtest1 to 100.00 MiB

4、重新掛載

[root@linuxprobe dev]# df -h  ## 檢視掛載
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   18G  2.9G   15G  17% /
devtmpfs               985M     0  985M   0% /dev
tmpfs                  994M   80K  994M   1% /dev/shm
tmpfs                  994M  8.9M  986M   1% /run
tmpfs                  994M     0  994M   0% /sys/fs/cgroup
/dev/sda1              497M  119M  379M  24% /boot
/dev/sr0               3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
[root@linuxprobe dev]# mount -a  ## 掛載
[root@linuxprobe dev]# df -h  ## 檢視掛載
Filesystem                   Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root         18G  2.9G   15G  17% /
devtmpfs                     985M     0  985M   0% /dev
tmpfs                        994M   80K  994M   1% /dev/shm
tmpfs                        994M  8.9M  986M   1% /run
tmpfs                        994M     0  994M   0% /sys/fs/cgroup
/dev/sda1                    497M  119M  379M  24% /boot
/dev/sr0                     3.5G  3.5G     0 100% /run/media/root/RHEL-7.0 Server.x86_64
/dev/mapper/vgtest1-lvtest1   93M  1.6M   85M   2% /linuxprobe
[root@linuxprobe dev]# lvdisplay ## 檢視詳細資訊
  --- Logical volume ---
  LV Path                /dev/vgtest1/lvtest1
  LV Name                lvtest1
  VG Name                vgtest1
  LV UUID                oTCZoZ-CymC-Ce3k-JFGo-95ne-6lho-Y6a0Ll
  LV Write Access        read/write
  LV Creation host, time linuxprobe.com, 2020-10-29 16:30:51 +0800
  LV Status              available
  # open                 1
  LV Size                100.00 MiB
  Current LE             25
……………………