esxi上爲基於LVM的centos7的根目錄擴容

概念:聽說默認centos都是基於LVM的html

LVM:LVM是邏輯盤卷管理(Logical Volume Manager)的簡稱,它是Linux環境下對磁盤分區進行管理的一種機制.node

LVM 更加詳細的說明可點這裏:http://www.cnblogs.com/mchina/p/linux-centos-logical-volume-manager-lvm.htmllinux

fdisk 命令用法http://blog.sina.com.cn/s/blog_66b448620100ibay.htmlcentos

查看磁盤空間,根目錄過小了,但願增長磁盤app

在vsphere上修改磁盤的大小,重啓進來。ide

[root@ucx-auto ~]# df -lh
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   30G   23G  7.1G  76% /
devtmpfs                 5.8G     0  5.8G   0% /dev
tmpfs                    5.8G     0  5.8G   0% /dev/shm
tmpfs                    5.8G  8.9M  5.8G   1% /run
tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/sda1                497M  155M  343M  32% /boot
tmpfs                    1.2G     0  1.2G   0% /run/user/0

1、查看下LVorm

[root@ucx-auto ~]# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                trGefC-4mxg-BkS6-sywT-ie3O-deA3-WC0EDQ
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-07-26 17:38:31 +0800
  LV Status              available
  # open                 2
  LV Size                2.02 GiB
  Current LE             516
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                MRmrQV-MDKZ-ZJbQ-cvDP-nMEY-hWJk-xFCceo
  LV Write Access        read/write
  LV Creation host, time localhost, 2016-07-26 17:38:31 +0800
  LV Status              available
  # open                 1
  LV Size                66.49 GiB
  Current LE             17022
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1

二:查看機器所掛硬盤個數及分區狀況htm

[root@ucx-auto ~]# fdisk -l

Disk /dev/sda: 75.2 GB, 75161927680 bytes, 146800640 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 label type: dos
Disk identifier: 0x000cfb48

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048    67108863    33041408   8e  Linux LVM


Disk /dev/mapper/centos-swap: 2164 MB, 2164260864 bytes, 4227072 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 /dev/mapper/centos-root: 31.7 GB, 31666995200 bytes, 61849600 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

如上 有一塊磁盤/dev/sda 有兩個分區。就用了33G,說明還有未分區的blog

 

三:/dev/sda進行分區,作這個時候忘記截圖了 ,大概是下面這樣,若是讓你輸入分區號,順延下去便可。ip

 

[root@ucx-auto ~]$ fdisk /dev/sda
Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
最後一步出現這樣的提示。
 
這個時候[root@ucx-auto ~]# fdisk -l  能夠看到多了個分區
/dev/sda3        67108864   146800639    39845888   83  Linux
 
可是是ls /dev|grep sda3 是還看不到的,由於還沒格式化
 
四:格式化分區
[root@fz02 ~]# partprobe
 
注意看下根目錄到磁盤類型,選擇合適的type

 

[root@ucx-auto dev]# mkfs -t ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
2490368 inodes, 9961472 blocks
498073 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
304 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information:
done
 
[root@ucx-auto dev]# lvs
  LV   VG     Attr       LSize  Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- 29.49g                                                 
  swap centos -wi-ao----  2.02g   
 
五,建立物理卷
[root@ucx-auto dev]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: ^C  Interrupted...

  Aborted wiping of ext3.
  1 existing signature left on the device.
  Aborting pvcreate on /dev/sda3.
[root@ucx-auto dev]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]:
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created
 
六。
  1. 查看下名字
[root@ucx-auto dev]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   30G   23G  7.1G  76% /
devtmpfs                 5.8G     0  5.8G   0% /dev
tmpfs                    5.8G     0  5.8G   0% /dev/shm
tmpfs                    5.8G  8.9M  5.8G   1% /run
tmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup
/dev/sda1                497M  155M  343M  32% /boot
tmpfs                    1.2G     0  1.2G   0% /run/user/0
 
 2.增長卷組的空間
[root@ucx-auto dev]# vgextend /dev/mapper/centos-root /dev/sda3  【注意這裏哦,卷組的名字是-前的】
  Invalid volume group name centos/root.
  Run `vgextend --help' for more information.

[root@ucx-auto dev]# vgextend /dev/mapper/centos /dev/sda3
  Volume group "centos" successfully extended
好了,卷組擴好了。
 
3,查看下卷組
[root@ucx-auto dev]# vgdisplay
  --- Volume group ---
  VG Name               centos
  System ID
  Format                lvm2
  Metadata Areas        2
  Metadata Sequence No  4
  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               69.50 GiB
  PE Size               4.00 MiB
  Total PE              17793
  Alloc PE / Size       8066 / 31.51 GiB  分配的
  Free  PE / Size       9727 / 38.00 GiB   空閒的
  VG UUID               8iYw2C-aqVR-C0eb-nRF4-v9q7-ZEyh-pxrRQB
 
可看到有個free pe能夠供LV 分配
 
 
七, 六中擴容完畢VG ,就能夠用VG中的Free空間來擴容LV ,
 
[root@ucx-auto dev]# sudo lvextend  -L +37G /dev/mapper/centos-root /dev/sda3  【注意下名字哦,如今是有LV 了,centos是LG名】
  Size of logical volume centos/root changed from 29.49 GiB (7550 extents) to 66.49 GiB (17022 extents).
  Logical volume root successfully resized.
 
1.檢查下文件系統的正確性
[root@ucx-auto dev]# e2fsck -f /dev/mapper/centos-root
e2fsck 1.42.9 (28-Dec-2013)
/dev/mapper/centos-root is mounted.
e2fsck: Cannot continue, aborting.
 
2.從新定義大小,不懂爲毛一直錯
[root@ucx-auto dev]# resize2fs /dev/mapper/centos-root
resize2fs 1.42.9 (28-Dec-2013)
resize2fs: Bad magic number in super-block while trying to open /dev/mapper/centos-root
Couldn't find valid filesystem superblock.

3.換個姿式再來一次

[root@ucx-auto dev]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=1932800 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=7731200, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=3775, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7731200 to 17430528

4.看到根目錄已經擴大了

[root@ucx-auto dev]# df -lhFilesystem               Size  Used Avail Use% Mounted on/dev/mapper/centos-root   67G   23G   45G  34% /devtmpfs                 5.8G     0  5.8G   0% /devtmpfs                    5.8G     0  5.8G   0% /dev/shmtmpfs                    5.8G  8.9M  5.8G   1% /runtmpfs                    5.8G     0  5.8G   0% /sys/fs/cgroup/dev/sda1                497M  155M  343M  32% /boottmpfs                    1.2G     0  1.2G   0% /run/user/0

相關文章
相關標籤/搜索