1. 程式人生 > >LVM 管理之二:縮減 LV 大小

LVM 管理之二:縮減 LV 大小

轉載http://francs3.blog.163.com/blog/static/4057672720122299250175/

今天學習了 RHEL6 縮減 LV 大小,下面的例子目標是將LV "/dev/mapper/vg_redhat6-lv_pgdata_01"
縮小 86 M。    
 

--1 當前LVM 資訊

 

 /dev/mapper/vg_redhat6-lv_root
                       13G  7.7G  4.6G  63% /
tmpfs                 250M  264K  250M   1% /dev/shm
/dev/sda1             485M   31M  429M   7% /boot
/dev/sr0              2.9G  2.9G     0 100% /media/RHEL_6.2 i386 Disc 1
/dev/mapper/vg_redhat6-lv_pgdata_01
                      786M
  593M  154M  80% /database/skytf/pgdata1

   
                     

--2 解除安裝檔案系統 ( unmount )

 

 [[email protected] ~]# umount /dev/mapper/vg_redhat6-lv_pgdata_01

 

--3 檢查檔案系統( e2fsck )

 

 [[email protected] ~]# e2fsck /dev/mapper/vg_redhat6-lv_pgdata_01
e2fsck 1.41.12 (17-May-2010)
/dev/mapper/vg_redhat6-lv_pgdata_01: clean, 236/49152 files, 154817/179200 blocks

   

   
--4 縮小檔案系統 ( resize2fs )

 

 [[email protected] ~]# resize2fs -f /dev/mapper/vg_redhat6-lv_pgdata_01 700M
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_redhat6-lv_pgdata_01 to 179200 (4k) blocks.
The filesystem on /dev/mapper/vg_redhat6-lv_pgdata_01 is now 179200 blocks long.         

                
 
--5 縮小LV大小( lvreduce )

 

 [[email protected] ~]# lvreduce -L 700M /dev/mapper/vg_redhat6-lv_pgdata_01
  WARNING: Reducing active logical volume to 700.00 MiB
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lv_pgdata_01? [y/n]: y
  Reducing logical volume lv_pgdata_01 to 700.00 MiB
  Logical volume lv_pgdata_01 successfully resized       

     
 
--6 檢視當前 LV 大小

 [[email protected] ~]# lvs
  LV           VG         Attr   LSize   Origin Snap%  Move Log Copy%  Convert
  lv_pgdata_01 vg_redhat6 -wi-a- 700.00m                                     
  lv_root      vg_redhat6 -wi-ao  13.10g                                     
  lv_swap      vg_redhat6 -wi-ao   1.91g  


  
 備註: 邏輯卷  lv_pgdata_01 已經縮減成 700M了。
 

--7 重新掛載檔案系統,檢視 

 [[email protected] ~]# mount  -t ext4 /dev/mapper/vg_redhat6-lv_pgdata_01 /database/skytf/pgdata1
[[email protected] ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_redhat6-lv_root
                       13G  7.7G  4.6G  63% /
tmpfs                 250M  264K  250M   1% /dev/shm
/dev/sda1             485M   31M  429M   7% /boot
/dev/sr0              2.9G  2.9G     0 100% /media/RHEL_6.2 i386 Disc 1
/dev/mapper/vg_redhat6-lv_pgdata_01
                      688M  593M   61M  91% /database/skytf/pgdata1      

       
                    
       備註:目錄 /database/skytf/pgdata1  已成功縮減到 700M 左右。         
       --8 總結
 
    在縮減LV 大小前,首先得先縮減檔案系統大小。