最近心头一直有一座大山压在身上,亲爱的fedora空间不够了,动不动就是只剩下1~2G可用空间。各种可怜。 更恶心的是,在linux下 而手头又一直没有可以调整windows那尊敬的NTFS分区的软件 -- 没错,linux可以把windows的将近400G的巨大分区格式化掉-- 但是数据怎么办?手头又没有可靠的移动硬盘可以帮我临时存储下数据。 谢谢二学长提供的DiskGenius,在windows那边把那大分区给缩了30来G的空闲硬盘。 再次感谢二学长保证我硬盘即便搞崩了,他依然能把数据抢救出来,我毅然决然踏上了裸奔调整分区路 -- 万一真崩了,也只能祈求上天给他神力,帮我抢救回数据了。

提示符说明: 表示直接回车。由于本次调整分区,只有唯一一段刚削下来的还热乎着的分区,所以直接默认而不会出错 除了[usr@yu yu] 后面跟随的 # 符号是系统的输入提示符号,其余地方的是表示我的注释开始符号 省略若干无意义的提示

[yu@yu ~]$ su
Password:
[root@yu yu]# vgdisplay
  --- Volume group ---
  VG Name               vg_yu
  System ID
  Format                lvm2
.......
  Total PE              921
  Alloc PE / Size       921 / 28.78 GiB
  Free  PE / Size       0 / 0       <<
.......

[root@yu yu]# fdisk /dev/sda
Command (m for help): p  #查看硬盘分区
                         #发现刚从win那儿削下来的30+G

Command (m for help): n  #new 一个
# 下面两者
First cylinder (aaaa-bbbbb, default aaaa):
Last cylinder, +cylinders or +size{K,M,G} (aaaa-bbbb, default bbbb):

Command (m for help): t
Partition number (1-x) :  #随便选个,我的是 7

Hex code (type L to list codes): 8e

Command (m for help): p # 再次查看,发现多了个 sda7

Command (m for help): w # 内容写进去

系统提示: 需要重启. 重启后继续....

[root@yu yu]# partprobe
[root@yu yu]# pvcreate /dev/sda7
  Writing physical volume data to disk "/dev/sda7"
  Physical volume "/dev/sda7" successfully created
[root@yu yu]# vgextend vg_yu /dev/sda7
  Volume group "vg_yu" successfully extended

[root@yu yu]# vgdisplay
.....
  VG Size               59.38 GiB
  PE Size               32.00 MiB
  Total PE              1900
  Alloc PE / Size       921 / 28.78 GiB
  Free  PE / Size       979 / 30.59 GiB
....

[root@yu yu]# lvresize -L 59.38G /dev/vg_yu/lv_root
Rounding up size to full physical extent 59.41 GiB
  Extending logical volume lv_root to 59.41 GiB
  Insufficient free space: 1164 extents needed, but only 979 available

nani !? 和 vgdisplay中描述不符啊 -L 59G -- 1151 extents needed, but only 979 available -L 58G -- 1119 extents needed, but only 979 available 所以1G == 32 = 1151 - 1119 140(=1119-979)/32 = 4.35 58 - 4.35 = 58.65

# lvresize -L 53.65G /dev/vg_yu/lv_root
  Rounding up size to full physical extent 53.66 GiB
  Extending logical volume lv_root to 53.66 GiB

额... 再来算 53.66 / 980 = 0.0548 ... 尝试下 53.6 = 53.66 - 0.06

[root@yu yu]# lvresize -L 53.6G /dev/vg_yu/lv_root        #终于搞定
  Rounding up size to full physical extent 53.62 GiB
  Extending logical volume lv_root to 53.62 GiB
  Logical volume lv_root successfully resized

[root@yu yu]# resize2fs /dev/vg_yu/lv_root
resize2fs 1.42.3 (14-May-2012)
Filesystem at /dev/vg_yu/lv_root is mounted on /; on-line resizing required
old_desc_blocks = 2, new_desc_blocks = 4
The filesystem on /dev/vg_yu/lv_root is now 14057472 blocks long.

[root@yu yu]# vgdisplay
  --- Volume group ---
  VG Name               vg_yu
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  5
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                2
  Act PV                2
  VG Size               59.38 GiB
  PE Size               32.00 MiB
  Total PE              1900
  Alloc PE / Size       1900 / 59.38 GiB
  Free  PE / Size       0 / 0
  VG UUID               GD8Qv1-93yP-XU5o-qXb8-QQju-Qwrc-zT9u1h

再次查看,发现Free PE / Size 又空了

[root@yu yu]# df -h
Filesystem                 Size  Used Avail Use% Mounted on
devtmpfs                   1.9G     0  1.9G   0% /dev
tmpfs                      1.9G  228K  1.9G   1% /dev/shm
tmpfs                      1.9G  1.2M  1.9G   1% /run
/dev/mapper/vg_yu-lv_root   53G   16G   36G  31% /
tmpfs                      1.9G     0  1.9G   0% /sys/fs/cgroup
tmpfs                      1.9G     0  1.9G   0% /media
/dev/sda5                   32G   15G   17G  47% /mnt/tool
/dev/sda6                  297G  276G   22G  93% /mnt/data
/dev/sda1                   78G   58G   21G  74% /mnt/sys
/dev/sda3                  485M  122M  338M  27% /boot

搞定收工

来自的你,很高兴你能看到这儿。若本文对你有所用处,或者内容有什么不足之处,敬请毫不犹豫给个回复。谢谢!