CentOS6.5增長掛載點容量

一.背景:由於公司虛擬機 (/) 目錄容量太小,致使一些任務不能正常執行,須要給虛擬機擴容app

二.操做:ide

 初始磁盤狀況:  ui

 1.使用 df 命令查看磁盤與目錄的容量:spa

[root@shaonian ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root   48G   22G   25G  47% /
tmpfs                         3.8G     0  3.8G   0% /dev/shm
/dev/xvda1                    485M   33M  427M   8% /boot
/dev/mapper/VolGroup-lv_home  4.7G  138M  4.4G   4% /home
cm_processes                  3.8G  808K  3.8G   1% /var/run/cloudera-scm-agent/process

 2.使用 fdisk -l 命令查看磁盤分區:命令行

[root@shaonian ~]# fdisk -l

Disk /dev/xvdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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/xvda: 64.4 GB, 64424509440 bytes
255 heads, 63 sectors/track, 7832 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: 0x000e9377

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1          64      512000   83  Linux
Partition 1 does not end on cylinder boundary.
/dev/xvda2              64        7833    62401536   8e  Linux LVM

Disk /dev/xvdd: 119 MB, 119891968 bytes
255 heads, 63 sectors/track, 14 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/VolGroup-lv_root: 52.3 GB, 52344913920 bytes
255 heads, 63 sectors/track, 6363 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/VolGroup-lv_swap: 6442 MB, 6442450944 bytes
255 heads, 63 sectors/track, 783 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/VolGroup-lv_home: 5108 MB, 5108662272 bytes
255 heads, 63 sectors/track, 621 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

發現執行 fdisk -l 顯示的第一行,顯示出的 /dev/xvdb 分區,並無被使用。這就是是管理人員分出給磁盤擴容用的磁盤空間,咱們接下來要用這個分區爲(/)目錄擴容code

3.接着執行 fdisk /dev/xvdb ,進入 fdisk 命令行給磁盤分區blog

[root@shaonian ~]# fdisk /dev/xvdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xd259beb1.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').

Command (m for help): p

Disk /dev/xvdb: 85.9 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 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: 0xd259beb1

    Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1): 
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-10443, default 10443): 
Using default value 10443

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

能夠看出,輸入fdisk /dev/xvdb  命令後,提示咱們輸入命令,咱們依次輸入如下命令:ci

p 查看已有分區,因爲這個分區是新的,因此爲空rem

n 新建分區:虛擬機

  p 新建主分區

1 輸入分區號,由於以前沒有分區,因此這是第一個分區,分區號爲1

接下來 First cylinder 和 Last cylinder 咱們直接點擊回車,默認使用所有空間

t 改變分區類型

8e 改變分區類型爲 LVM

w 寫入改變

此時系統將改變分區,而後退出 fdisk 命令行。若是沒有自動退出,輸入 q 退出。

4. 用 mkfs 命令對分區進行格式化

mkfs -t ext3 /dev/xvdb1

此時將進入漫長的等待......

 

5.添加 LVM到原來的 LVM組

lvm  進入lvm管理

lvm> pvcreate /dev/xvdb1  建立虛擬分區

lvm> vgextend VolGroup  /dev/xvdb1  把剛剛建立的分區添加到虛擬分區組

lvm>lvextend -L +79.5 /dev/mapper/VolGroup-lv_root  擴展容量(能夠看到 /dev/mapper/VolGroup-lv_root)就是咱們執行 df -h 時 (/)目錄的文件系統)

lvm> quit  退出

6. 文件系統擴容

resize2fs /dev/mapper/VolGroup-lv_root

 

至此,擴容所有完成,此時再次執行 df -h :

[root@shaonian ~]# df -h
Filesystem                    Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup-lv_root  127G   22G   99G  18% /
tmpfs                         3.8G     0  3.8G   0% /dev/shm
/dev/xvda1                    485M   33M  427M   8% /boot
/dev/mapper/VolGroup-lv_home  4.7G  138M  4.4G   4% /home
cm_processes                  3.8G  792K  3.8G   1% /var/run/cloudera-scm-agent/process

能夠看到 (/)目錄的容量大大增長了

 

PS:順便一提,一共擴容了三臺虛擬機,其中兩臺都是很順利的,有一臺不知道什麼緣由(多是其中某一步操做錯誤),在執行

lvm> vgextend VolGroup /dev/mapper/Group-lv_root

操做時,出現了以下錯誤:

Couldn't find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.

運行 pvscan 查看 pv:

lvm> pvscan
  Couldn't find device with uuid cRdLUx-1ttO-JUKw-K2Bu-FOw2-EIrk-87Xdl3.
  Couldn't find device with uuid 7Ef30A-6qRY-bBP0-CTH9-f6ut-kE8x-ch4c2j.
  PV /dev/xvda2       VG VolGroup   lvm2 [59.51 GiB / 0    free]
  PV unknown device   VG VolGroup   lvm2 [80.00 GiB / 80.00 GiB free]
  PV unknown device   VG VolGroup   lvm2 [80.00 GiB / 80.00 GiB free]
  PV /dev/xvdb4       VG VolGroup   lvm2 [80.00 GiB / 80.00 GiB free]
  Total: 4 [299.50 GiB] / in use: 4 [299.50 GiB] / in no VG: 0 [0   ]

發現 有兩行 出現了 unknown device 

執行

lvm> vgreduce --removemissing  VolGroup

便可。

相關文章
相關標籤/搜索