linux调整磁盘空间大小

注意:给linux重新调整分区的前提是:安装系统的时候必须采用的是lvm分区,如果是标准分区后期是无法调整的。

系统可能没有相关命令,先安装一下 yum  install  lvm2  -y


[root@zhanglw-c ~]# fdisk -l

Disk /dev/sda: 21.5 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c7854

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1         131     1048576   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2             131        2592    19763200   8e  Linux LVM

Disk /dev/mapper/vg_zhanglwc-LogVol03: 8422 MB, 8422162432 bytes
255 heads, 63 sectors/track, 1023 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_zhanglwc-LogVol02: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_zhanglwc-LogVol01: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_zhanglwc-LogVol00: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_zhanglwc-LogVol03
                      7.6G  997M  6.3G  14% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             976M   32M  893M   4% /boot
/dev/mapper/vg_zhanglwc-LogVol00
                      4.8G   10M  4.6G   1% /home
/dev/mapper/vg_zhanglwc-LogVol01
                      4.8G   10M  4.6G   1% /picclife
[root@zhanglw-c ~]# umount /home  ------卸载home分区------
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# df -h    ------home分区不见了------
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_zhanglwc-LogVol03
                      7.6G  997M  6.3G  14% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             976M   32M  893M   4% /boot
/dev/mapper/vg_zhanglwc-LogVol01
                      4.8G   10M  4.6G   1% /picclife
[root@zhanglw-c ~]#  
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# resize2fs -p /dev/mapper/vg_zhanglwc-LogVol00 2G  ------ home分区减少到2G ------
resize2fs 1.41.12 (17-May-2010)
请先运行 'e2fsck -f /dev/mapper/vg_zhanglwc-LogVol00'.

[root@zhanglw-c ~]# e2fsck -f /dev/mapper/vg_zhanglwc-LogVol00   ------上一步提示需要执行这个命令,那就执行------
e2fsck 1.41.12 (17-May-2010)
第一步: 检查inode,块,和大小
第二步: 检查目录结构
第3步: 检查目录连接性
Pass 4: Checking reference counts
第5步: 检查簇概要信息
/dev/mapper/vg_zhanglwc-LogVol00: 11/327680 files (0.0% non-contiguous), 55902/1310720 blocks
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# resize2fs -p /dev/mapper/vg_zhanglwc-LogVol00 2G  ------然后再次执行 将home分区减少到2G ------
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/mapper/vg_zhanglwc-LogVol00 to 524288 (4k) blocks.
Begin pass 2 (max = 32768)
正在重定位块            XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 40)
正在扫描inode表          XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/mapper/vg_zhanglwc-LogVol00 is now 524288 blocks long.

[root@zhanglw-c ~]# mount /home  ------再挂载home分区,看大小减少了2G,由原来的 4.8G 到了 1.9G ------
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_zhanglwc-LogVol03
                      7.6G  997M  6.3G  14% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             976M   32M  893M   4% /boot
/dev/mapper/vg_zhanglwc-LogVol01
                      4.8G   10M  4.6G   1% /picclife
/dev/mapper/vg_zhanglwc-LogVol00
                      1.9G  7.5M  1.8G   1% /home
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# lvreduce -L 2G /dev/mapper/vg_zhanglwc-LogVol00  -----我认为这个命令是将已经减少的100G空间拿到系统公共的区域,可以被其他分区加载和利用。
  WARNING: Reducing active and open logical volume to 2.00 GiB.
  THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce vg_zhanglwc/LogVol00? [y/n]: y
  Size of logical volume vg_zhanglwc/LogVol00 changed from 5.00 GiB (1280 extents) to 2.00 GiB (512 extents).
  Logical volume LogVol00 successfully resized.
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# vgdisplay  
这里会显示可用空间,忘记复制结果了


[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# lvextend -L +2G /dev/mapper/vg_zhanglwc-LogVol01  ------将空闲出来的2G 指定给 /picclife 挂载点 ------
  Size of logical volume vg_zhanglwc/LogVol01 changed from 5.00 GiB (1280 extents) to 7.00 GiB (1792 extents).
  Logical volume LogVol01 successfully resized.
[root@zhanglw-c ~]#
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# resize2fs -p /dev/mapper/vg_zhanglwc-LogVol01  ------重新定制一下/picclife 挂载点的大小  ------
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/mapper/vg_zhanglwc-LogVol01 is mounted on /picclife; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 1
Performing an on-line resize of /dev/mapper/vg_zhanglwc-LogVol01 to 1835008 (4k) blocks.
The filesystem on /dev/mapper/vg_zhanglwc-LogVol01 is now 1835008 blocks long.

[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# 
[root@zhanglw-c ~]# df -h    ------最后查询/picclife 挂载点的大小 由原来的 4.8G 增加到 6.8G ------
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/vg_zhanglwc-LogVol03
                      7.6G  997M  6.3G  14% /
tmpfs                 491M     0  491M   0% /dev/shm
/dev/sda1             976M   32M  893M   4% /boot
/dev/mapper/vg_zhanglwc-LogVol01
                      6.8G   12M  6.5G   1% /picclife
/dev/mapper/vg_zhanglwc-LogVol00
                      1.9G  7.5M  1.8G   1% /home
[root@zhanglw-c ~]# 

你可能感兴趣的:(linux)