实验室的服务器是CentOS6.4的系统,默认采用了LVM。这带来了很大的便利,灵活的卷调整是其中之一。有关于LVM的介绍在这里。
碰巧需要对卷大小进行一次调整,CentOS默认安装为”/home”分配了较大的卷而”/”分配了较小的卷,这不符合目前实验室的使用需求,因此需要对卷大小进行调整,过程记录如下。
1 2 |
操作系统:CentOS6.4 文件系统:LVM + Ext4 |
查看当前LVM相关信息
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
[root@server003 ~]# pvdisplay --- Physical volume --- PV Name /dev/sda2 VG Name vg_server003 PV Size 418.14 GiB / not usable 3.00 MiB Allocatable yes (but full) PE Size 4.00 MiB Total PE 107042 Free PE 0 Allocated PE 107042 PV UUID GTugxC-XdOn-zkAv-gacM-jtWo-0dJf-OsxoD1 [root@server003 ~]# vgdisplay --- Volume group --- VG Name vg_server003 System ID Format lvm2 Metadata Areas 1 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 3 Open LV 3 Max PV 0 Cur PV 1 Act PV 1 VG Size 418.13 GiB PE Size 4.00 MiB Total PE 107042 Alloc PE / Size 107042 / 418.13 GiB Free PE / Size 0 / 0 VG UUID qknhd2-bSCt-70Is-FCt8-jawb-fKn9-xAfSRr [root@server003 ~]# lvdisplay --- Logical volume --- LV Path /dev/vg_server003/lv_root LV Name lv_root VG Name vg_server003 LV UUID WUin0B-g3tq-P9To-cekJ-T266-afwO-ySxhN1 LV Write Access read/write LV Creation host, time server003, 2014-06-12 15:47:01 +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 256 Block device 253:0 --- Logical volume --- LV Path /dev/vg_server003/lv_home LV Name lv_home VG Name vg_server003 LV UUID fFPJRF-V58y-N0qV-88YG-pz9I-w2Pe-kaX2cJ LV Write Access read/write LV Creation host, time server003, 2014-06-12 15:47:08 +0800 LV Status available # open 1 LV Size 344.51 GiB Current LE 88194 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:2 --- Logical volume --- LV Path /dev/vg_server003/lv_swap LV Name lv_swap VG Name vg_server003 LV UUID NTRZJO-ydBo-SbVq-hcI3-AmVU-oui0-8PTgoP LV Write Access read/write LV Creation host, time server003, 2014-06-12 15:47:50 +0800 LV Status available # open 1 LV Size 23.62 GiB Current LE 6048 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 |
缩小/home所使用的卷大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
[root@server003 ~]# umount /home [root@server003 ~]# resize2fs /dev/vg_server003/lv_home 18G resize2fs 1.41.12 (17-May-2010) 请先运行 'e2fsck -f /dev/vg_server003/lv_home'. [root@server003 ~]# e2fsck -f /dev/vg_server003/lv_home e2fsck 1.41.12 (17-May-2010) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/vg_server003/lv_home: 246/22585344 files (3.7% non-contiguous), 1471842/90310656 blocks [root@server003 ~]# resize2fs /dev/vg_server003/lv_home 18G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg_server003/lv_home to 4718592 (4k) blocks. The filesystem on /dev/vg_server003/lv_home is now 4718592 blocks long. [root@server003 ~]# lvreduce -L 118.13G /dev/vg_server003/lv_home Rounding size to boundary between physical extents: 118.13 GiB WARNING: Reducing active logical volume to 118.13 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce lv_home? [y/n]: y Reducing logical volume lv_home to 118.13 GiB Logical volume lv_home successfully resized [root@server003 ~]# resize2fs /dev/vg_server003/lv_home resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vg_server003/lv_home to 30967808 (4k) blocks. The filesystem on /dev/vg_server003/lv_home is now 30967808 blocks long. |
重新挂载卷,大小以修改成功
1 2 3 4 5 6 7 |
[root@server003 ~]# mount /dev/vg_server003/lv_home /home [root@server003 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_server003-lv_root 50G 2.8G 44G 6% / tmpfs 24G 236K 24G 1% /dev/shm /dev/sda1 485M 40M 421M 9% /boot /dev/mapper/vg_server003-lv_home 117G 206M 111G 1% /home |
修改”/”所使用的卷大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
[root@server003 ~]# lvextend -l +100%FREE /dev/vg_server003/lv_root Extending logical volume lv_root to 276.38 GiB Logical volume lv_root successfully resized [root@server003 ~]# resize2fs /dev/vg_server003/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/vg_server003/lv_root is mounted on /; on-line resizing required old desc_blocks = 4, new_desc_blocks = 18 Performing an on-line resize of /dev/vg_server003/lv_root to 72450048 (4k) blocks. The filesystem on /dev/vg_server003/lv_root is now 72450048 blocks long. [root@server003 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_server003-lv_root 273G 2.8G 256G 2% / tmpfs 24G 236K 24G 1% /dev/shm /dev/sda1 485M 40M 421M 9% /boot /dev/mapper/vg_server003-lv_home 117G 206M 111G 1% /home |