将未分配的磁盘扩展到现有的lvm

即时通讯在我的ubuntu服务器上使用vmware,初始设置是10GB磁盘利用率,使用lvextend将其增加到15GB,并增加了5GB共20GB。

下面显示我的fdisk -l

 Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0002948a Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 501758 20969471 10233857 5 Extended /dev/sda3 499712 501757 1023 83 Linux /dev/sda4 20969472 31457279 5243904 8e Linux LVM /dev/sda5 501760 20969471 10233856 8e Linux LVM 

/ dev / sda4实际上是我的/ dev / sda5的扩展

 root@media:~# pvscan PV /dev/sda5 VG media lvm2 [9.76 GiB / 0 free] PV /dev/sda4 VG media lvm2 [5.00 GiB / 0 free] Total: 2 [14.76 GiB] / in use: 2 [14.76 GiB] / in no VG: 0 [0 ] 

我仍然有一个未分配的磁盘在我的/ dev / sda ,如上所述,我想用它。

但是当我在我的fdisk /dev/sda创build一个新的分区来获得额外的5GB时,我得到了这个1023块。

 Device Boot Start End Blocks Id System /dev/sda3 499712 501757 1023 83 Linux 

通过忽略以上,并在我的/ dev / sda上创build另一个分区,这显示..

 All primary partitions are in use Adding logical partition 6 No free sectors available 

没有这个我似乎不能创build另一个分区

/dev/sda3 499712 501757 1023 83 Linux

发生。 有人可以帮助我做错了吗?

基本上,我想到的是逐渐增加我的服务器的分区大小。 从10 + 5 + 5 +等等…

windows能够扩展未分配的空间而不会出现任何问题并重新启动。 即时通讯非常新的Linux,我希望有人能帮助我了解我的问题发生了什么。

 root@media:~# pvs PV VG Fmt Attr PSize PFree /dev/sda4 media lvm2 a- 5.00g 0 /dev/sda5 media lvm2 a- 9.76g 0 root@media:~# lvs LV VG Attr LSize Origin Snap% Move Log Copy% Convert root media -wi-ao 13.76g swap_1 media -wi-ao 1.00g root@media:~# vgs VG #PV #LV #SN Attr VSize VFree media 2 2 0 wz--n- 14.76g 0 

为什么不让你的生活更轻松,并使用LVM作为扩展? 如果我在你的位置,我会从服务器备份数据(20 GB是不是很多),然后:

 umount <respective mount point> lvremove media vgremove media pvremove /dev/sda4 pvremove /dev/sda5 

分区/dev/sda

  fdisk /dev/sda p -> print d 5 -> delete /dev/sda5 d 4 -> delete /dev/sda4 d 3 -> delete /dev/sda3 d 2 -> delete /dev/sda2 p -> print to confirm your changes n -> create new partition, take the defaults to acquire the max disk space possible for it, choose primary partition (LVM will manage it afterwards) t -> change the type of the partition to LVM w 

由于正在使用/dev/sda1 ,所以更改将在重新引导后显示。 然后fdisk -l /dev/sda会输出:

 Disk /dev/sda: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0x0002948a Device Boot Start End Blocks Id System /dev/sda1 * 2048 499711 248832 83 Linux /dev/sda2 499712 20969471 10233857 8e Linux LVM 

/dev/sda2添加到LVM,创build卷组和分区:

 pvcreate /dev/sda2 vgcreate media /dev/sda2 lvcreate --size 14G --name root media lvcreate --size 1G --name swap_1 media (in my experience `--extents` is more precise than `--size`. Verify by `vgdisplay` there are no Free Extents) Create filesystems and enable swap for the newly created logical volumes. 

这种设置的优点:灵活性。 逻辑卷大小可能小于卷组,因此文件系统也会变小。 然后为了增加大小,使用lvextend并在之后增加文件系统。

缺点:必须删除所有分区,备份和恢复数据。