Centos6

在centos 6上擴展分區

  • June 18, 2015

我有一個 VPS,它似乎在某處缺少一些空間。它應該是 150GB,但只有 50GB。我一直在嘗試擴展分區,但即使在指南的幫助下,我似乎也無法知道如何擴展。

這是在 CentOS 6 上安裝了 Plesk 11 的 VPS。

任何指導將不勝感激。我想使用 vda2 分區中剩餘的所有空間。

[root@www ~]# lsblk
NAME                        MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
vda                         252:0    0  150G  0 disk
├─vda1                      252:1    0  500M  0 part /boot
└─vda2                      252:2    0 49.5G  0 part
 ├─vg_plesk-lv_root (dm-0) 253:0    0   48G  0 lvm  /
 ├─vg_plesk-lv_swap (dm-1) 253:1    0    1G  0 lvm  [SWAP]
 └─vg_plesk-lv_tmp (dm-2)  253:2    0  512M  0 lvm  /tmp

[root@www ~]# vgscan
 Reading all physical volumes.  This may take a while...
 Found volume group "vg_plesk" using metadata type lvm2

[root@www ~]# lvm vgdisplay
 --- Volume group ---
 VG Name               vg_plesk
 System ID
 Format                lvm2
 Metadata Areas        1
 Metadata Sequence No  6
 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               49.51 GiB
 PE Size               4.00 MiB
 Total PE              12674
 Alloc PE / Size       12674 / 49.51 GiB
 Free  PE / Size       0 / 0
 VG UUID               8Hsz6T-yQVv-GerB-32Qe-ZvIQ-BQvA-uYqft5

(parted) print all
Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg_plesk-lv_tmp: 537MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End    Size   File system  Flags
1      0.00B  537MB  537MB  ext4


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg_plesk-lv_swap: 1074MB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system     Flags
1      0.00B  1074MB  1074MB  linux-swap(v1)


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/vg_plesk-lv_root: 51.5GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End     Size    File system  Flags
1      0.00B  51.5GB  51.5GB  ext4


Model: Virtio Block Device (virtblk)
Disk /dev/vda: 161GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
1      1049kB  525MB   524MB   primary  ext4         boot
2      525MB   53.7GB  53.2GB  primary               lvm

添加輸出:

[root@www ~]# fdisk -l

Disk /dev/vda: 161.1 GB, 161061273600 bytes
16 heads, 63 sectors/track, 312076 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00034f7d

  Device Boot      Start         End      Blocks   Id  System
/dev/vda1   *           3        1018      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/vda2            1018      104026    51915776   8e  Linux LVM
Partition 2 does not end on cylinder boundary.

Disk /dev/mapper/vg_plesk-lv_root: 51.5 GB, 51547996160 bytes
255 heads, 63 sectors/track, 6267 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_plesk-lv_swap: 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_plesk-lv_tmp: 536 MB, 536870912 bytes
255 heads, 63 sectors/track, 65 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@www ~]# pvdisplay
 --- Physical volume ---
 PV Name               /dev/vda2
 VG Name               vg_plesk
 PV Size               49.51 GiB / not usable 2.00 MiB
 Allocatable           yes (but full)
 PE Size               4.00 MiB
 Total PE              12674
 Free PE               0
 Allocated PE          12674
 PV UUID               oFD1tJ-wJt1-MlBK-NKfq-4MMF-ZUCG-kZQZVx

我似乎無法找出這 100GB 的免費空間在哪里或如何分配它。

好的,有些命令很重要;

首先執行“fdisk -l”,查看列出的內容,然後執行“pvdisplay”查看您的 PV 是如何佈局的,可能磁碟上有未分區的空間(在這種情況下,只需創建一個帶有'8e’ 類型,然後將其添加到 PV,擴展 VG,然後擴展 LV)或者它在 PV 但不在 VG 中,在這種情況下,只需擴展 VG,然後擴展 LV。

編輯 - 根據您的輸出,您需要做的是,全部作為 root/sudo,鍵入;

fdisk /dev/fda

fdisk 應用程序將啟動,輸入“n”並輸入,您將看到;

Command action
  e   extended
  p   primary partition (1-4)

鍵入“p”

然後系統會詢問您的分區號,這將是 3(三),按 Enter

Partition number (1-4): 3

然後您將被要求提供第一個圓柱體,只需接受系統上彈出的任何內容(不是下面的值,這只是為了向您展示它的樣子);

First cylinder (197-621, default 197):<RETURN>
Using default value 197

然後它會要求最後一個氣缸,再次接受它拋出的任何東西,而不是我下面的例子

Last cylinder or +size or +sizeM or +sizeK (197-621, default 621): +128M

現在輸入“p”並輸入以顯示分區表,它應該看起來像這樣;

  Device Boot    Start       End    Blocks   Id  System
/dev/vda1             1       196    395104   8e  LVM
/dev/vda2           197       262    133056   8e  LVM
/dev/vda3           197       262    133056   8e  Linux

現在輸入’t’輸入,首先會要求你輸入分區號,你的是3(三),按輸入,然後你會被要求輸入分區類型程式碼,你的是'8e’(表示LVM ),按輸入,它應該看起來像這樣;

Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (LVM)   

現在輸入 ‘p’ 並再次輸入,輸出應如下所示;

  Device Boot    Start       End    Blocks   Id  System
/dev/vda1             1       196    395104   8e  LVM
/dev/vda2           197       262    133056   8e  LVM
/dev/vda3           197       262    133056   8e  LVM

現在輸入’w’來寫出這個配置,你會回到你的shell提示符下,然後可以像往常一樣擴展PV、VG和LV。

引用自:https://serverfault.com/questions/699470