GVKun编程网logo

centos根分区扩容(centos扩展根分区)

9

在本文中,我们将带你了解centos根分区扩容在这篇文章中,我们将为您详细介绍centos根分区扩容的方方面面,并解答centos扩展根分区常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的C

在本文中,我们将带你了解centos根分区扩容在这篇文章中,我们将为您详细介绍centos根分区扩容的方方面面,并解答centos扩展根分区常见的疑惑,同时我们还将给您一些技巧,以帮助您实现更有效的CentOS 5 LVM 在线扩容根分区、CentOS 5.X LVM 在线扩容根分区、CentOS 7 根目录分区扩容、CentOS 7 系统根目录分区扩容

本文目录一览:

centos根分区扩容(centos扩展根分区)

centos根分区扩容(centos扩展根分区)

操作环境:
[root@linuxidc ~]# uname -a
Linux linuxidc 2.6.32-358.18.1.el6.x86_64#1 SMP Wed Aug 28 17:19:38 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
现状分析:
系统有两个硬盘,第一个硬盘107G,“/”分区空间当时分区时只给了7.7G过小,空间马上占完。现在系统有第二个硬盘sdb大小为16GB,希望把sdb的所有空间加入到“/”分区中,是其空间容量从7.7GB变成7.7GB+16GB(约2.4GB)。(当然如果这里只有一个硬盘sda,有很多空间尚未使用可以进行同样的操作)
操作步骤如下:
第一步、查看本机现有分区情况
[root@linuxidc ~]# df -h
文件系统容量已用可用已用%% 挂载点
/dev/mapper/VolGroup-lv_root
7.7G 7.1G 155M 98% /
tmpfs 3.9G 296K 3.9G 1% /dev/shm
/dev/sda1 485M 64M 396M 14% /boot
/dev/sda3 83G 350M 79G 1% /media
第二步、查看本机的磁盘情况
[root@linuxidc ~]# fdisk -l


disk /dev/sda: 107.4 GB,107374182400 bytes
255 heads,63 sectors/track,13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x000dc0ad


Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2089 16264192 8e Linux LVM
/dev/sda3 2090 13054 88076362+ 83 Linux


disk /dev/mapper/VolGroup-lv_root: 8325 MB,8325693440 bytes
255 heads,1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x00000000


disk /dev/mapper/VolGroup-lv_swap: 8325 MB,1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x00000000
注意:此时还没有在EXSI5.0中添加第二块硬盘
[root@linuxidc ~]#
第三步、添加第二块硬盘


查看此时系统磁盘情况
root@linuxidc ~]# fdisk -l


disk /dev/sda: 107.4 GB,13054cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x000dc0ad


Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinderboundary.
/dev/sda2 64 2089 16264192 8e Linux LVM
/dev/sda3 2090 13054 88076362+ 83 Linux


disk /dev/sdb: 17.2 GB,17179869184 bytes
255 heads,2088 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x00000000


disk /dev/mapper/VolGroup-lv_root: 8325 MB,1012 cylinders
Units = cylinders of 16065 * 512 = 8225280bytes
Sector size (logical/physical): 512 bytes /512 bytes
I/O size (minimum/optimal): 512 bytes / 512bytes
disk identifier: 0x00000000


可以看到我们新添加的硬盘sdb


[root@linuxidc ~]#
第四步、对第二块硬盘sdb进行分区


[root@linuxidc ~]# fdisk /dev/sdb
Device contains neither a valid DOSpartition table,nor Sun,sgi or OSF disklabel
Building a new DOS disklabel with diskidentifier 0xfa4abbdc.
Changes will remain in memory only,untilyou decide to write them.
After that,of course,the prevIoUs contentwon't be recoverable.


Warning: invalid flag 0x0000 of partitiontable 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): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibilityflag
d delete a partition
l list kNown partition types
m print this menu
n add a new partition
o create a new empty DOSpartition table
p print the partition table
q quit without saving changes
s create a new empty Sundisklabel
t change a partition's system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (expertsonly)


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


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


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


说明:上面操作对sdb硬盘进行了分区操作,设为sdb4分区了(当然上面建立的主分区可以为1-4中的任意一个,我这里选择的4)。


第五步、对新建立的sdb4分区进行格式


[root@linuxidc ~]# mkfs.ext4 /dev/sdb4
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks,Stripe width=0 blocks
1048576 inodes,4192957 blocks
209647 blocks (5.00%) reserved for thesuper user
第一个数据块=0
Maximum filesystem blocks=4294967296
128 block groups
32768 blocks per group,32768 fragments pergroup
8192 inodes per group
Superblock backups stored on blocks:
32768,98304,163840,229376,294912,819200,884736,1605632,2654208,
4096000


正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystemaccounting information: done完成


This filesystem will be automaticallychecked every 20 mounts or
180 days,whichever comes first. Use tune2fs -c or -i to override.


说明:将sdb4分区格式化为ext4格式,因为CentOS安装是系统的格式ext4,所以这里要注意一下。


第六步、格式后的sdb4分区添加为物理卷
[root@linuxidc ~]# pvcreate /dev/sdb4
Physical volume "/dev/sdb4" successfully created

第七步、查看当前系统的物理卷(PV)情况


[root@linuxidc ~]# pvdisplay
---Physical volume ---
PVName /dev/sda2
VGName VolGroup
PVSize 15.51 GiB / not usable3.00 MiB
Allocatable yes (butfull)
PESize 4.00 MiB
Total PE 3970
Free PE 0
Allocated PE 3970
PVUUID Up77sG-sNKf-Ja0k-crBf-N0wz-a5hy-T6sVFh


"/dev/sdb4" is a new physical volume of "15.99 GiB"
---NEW Physical volume ---
PVName /dev/sdb4
VGName
PVSize 15.99 GiB
Allocatable NO
PESize 0
Total PE 0
Free PE 0
Allocated PE 0
PVUUID Gqnw7N-HooX-S2Nz-1NIZ-YpOe-g0jo-grG1rQ
说明:可以看到添加的新物理卷sdb4,大小都符合我们添加时的设置


第八步、查看当前卷组情况
[root@linuxidc ~]# vgdisplay
---Volume group ---
VGName VolGroup
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VGAccess read/write
VGStatus resizable
MAXLV 0
CurLV 2
Open LV 2
MaxPV 0
CurPV 1
ActPV 1
VGSize 15.51 GiB
PESize 4.00 MiB
Total PE 3970
Alloc PE / Size 3970 / 15.51GiB
Free PE / Size 0 / 0
VGUUID PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd


第九步、将分区sdb4转换为扩展分区


[root@linuxidc ~]# vgextend VolGroup/dev/sdb4
Volume group "VolGroup" successfully extended


第十步、查看当前的逻辑卷


[root@linuxidc ~]# lvdisplay
---Logical volume ---
LVPath /dev/VolGroup/lv_root
LVName lv_root
VGName VolGroup
LVUUID dCIsej-0NWX-bVFe-bT6L-c4eY-oy4G-9lNBOC
LVWrite Access read/write
LVCreation host,time,
Lvstatus available
#open 1
LVSize 7.75 GiB
Current LE 1985
Segments 1
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:0


---Logical volume ---
LVPath /dev/VolGroup/lv_swap
LVName lv_swap
VGName VolGroup
LVUUID K5bxJo-2SmM-6NCU-mBJP-Qzp1-ZODH-nbLK0k
LVWrite Access read/write
LVCreation host,
Lvstatus available
#open 1
LVSize 7.75 GiB
Current LE 1985
Segments 1
Allocation inherit
Read ahead sectors auto
-currently set to 256
Block device 253:1


说明:这里可以看到“/”根分区的路径名称为:/dev/VolGroup/lv_root


第十一步、查看扩展后的卷组情况
[root@linuxidc ~]# vgdisplay
---Volume group ---
VGName VolGroup
System ID
Format lvm2
Metadata Areas 2
Metadata Sequence No 4
VGAccess read/write
VGStatus resizable
MAXLV 0
CurLV 2
Open LV 2
MaxPV 0
CurPV 2
ActPV 2
VGSize 31.50 GiB
PESize 4.00 MiB
Total PE 8064
Alloc PE / Size 3970 / 15.51GiB
Free PE / Size 4094 / 15.99 GiB
VGUUID PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd
说明:扩展后的卷子情况,可以看出大小增加了16GB(与第八步中的对比)


第十二步、将新增的逻辑卷全部扩展到“/”分区中


[root@linuxidc ~]# lvextend -L +15.99G/dev/VolGroup/lv_root
Rounding size to boundary between physical extents: 15.99 GiB
Extending logical volume lv_root to 23.75 GiB
Logical volume lv_root successfully resized


说明:这里sdb4总共有16G,所以把16BG全部添加给根分区。


第十三步、查看“/”根分区格式,并重新刷新根分区的大小
[root@linuxidc ~]# e2fsck -f/dev/VolGroup/lv_root
e2fsck 1.41.12 (17-May-2010)
/dev/VolGroup/lv_root is mounted.
e2fsck: 无法继续,中止.


[root@linuxidc ~]# resize2fs /dev/VolGroup/lv_root
resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/VolGroup/lv_root ismounted on /; on-line resizing required
old desc_blocks = 1,new_desc_blocks = 2
Performing an on-line resize of/dev/VolGroup/lv_root to 6224896 (4k) blocks.
The filesystem on /dev/VolGroup/lv_root isNow 6224896 blocks long.
说明:命令resize2fs即刷新根分区“/dev/VolGroup/lv_root”的容量。


第十三步、查看刷新后根分区的大小


[root@linuxidc ~]# df -h
文件系统容量已用可用已用%% 挂载点
/dev/mapper/VolGroup-lv_root
24G 7.1G 16G 32% /
tmpfs 3.9G 144K 3.9G 1% /dev/shm
/dev/sda3 83G 350M 79G 1% /media/Lucene


说明:可以看到根分区的大小有7.7G变成了24G,重启一下系统再来看情况。此时就可以继续安装软件了,不会提示空间不足了。

CentOS 5 LVM 在线扩容根分区

CentOS 5 LVM 在线扩容根分区

说明:
Linux 2.6以上内核支持ext3的在线扩容

第一种情况:直接添加一个新硬盘
# df -h 看看现在硬盘的情况
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
                      6.7G  5.2G  1.3G  81% /
/dev/sda1              99M   12M   82M  13% /boot
tmpfs                 633M     0  633M   0% /dev/shm

# fdisk -l 可以看到新添加的硬盘/dev/sdb
Disk /dev/sda: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *           1          13      104391   83  Linux
/dev/sda2              14        1044     8281507+  8e  Linux LVM

Disk /dev/sdb: 8589 MB, 8589934592 bytes
255 heads, 63 sectors/track, 1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn''t contain a valid partition table

# lvm
lvm>vgdisplay 可以先看卷组是否还有剩余空间可以扩展,有的话直接扩展,没有或不够的话把新的硬盘添加进去
  --- Volume group ---
  VG Name               VolGroup00
  System ID            
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               7.88 GB
  PE Size               32.00 MB
  Total PE              252
  Alloc PE / Size       252 / 7.88 GB
  Free  PE / Size       0 / 0  

  VG UUID               0U8dPB-UTJZ-Mdv5-eZJM-Xj7f-gR1M-63BcCh

lvm>pvcreate /dev/sdb  使用新的整个硬盘创建一个lvm物理卷
lvm>vgextend /dev/VolGroup00 /dev/sdb  把新的物理卷添加到卷组中
lvm>vgdisplay 可以看到已分配空间和剩余未分配空间 All PE / Size 和 Free PE / Size
 --- Volume group ---
  VG Name               VolGroup00
  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               15.84 GB
  PE Size               32.00 MB
  Total PE              507
  Alloc PE / Size       252 / 7.88 GB
  Free  PE / Size       255 / 7.97 GB

  VG UUID               0U8dPB-UTJZ-Mdv5-eZJM-Xj7f-gR1M-63BcCh

lvm>lvextend -L +7.9G /dev/VolGroup00/LogVol00 扩展逻辑卷大小
lvm>vgdisplay
lvm>pvdisplay
lvm>lvdisplay 可以看到已经添加了
 --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol00
  VG Name                VolGroup00
  LV UUID                QtNkTM-TeSo-WnZD-fSUr-6k1F-5aLX-zAIfSQ
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                14.78 GB
  Current LE             473
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0
  
  --- Logical volume ---
  LV Name                /dev/VolGroup00/LogVol01
  VG Name                VolGroup00
  LV UUID                bhTEBX-t8XK-zGku-NCzx-eolz-Anvj-jUMUER
  LV Write Access        read/write
  LV Status              available
  # open                 1
  LV Size                1.00 GB
  Current LE             32
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1

lvm>quit
# resize2fs -p /dev/VolGroup00/LogVol00  修改文件系统大小以实现扩充空间
# df -h

第二种情况:只添加一个新分区
# df -h 可以看到新添加的硬盘/dev/sdb1
# lvm
lvm>pvcreate /dev/sdb1  使用新的硬盘创建一个lvm物理卷
lvm>vgextend /dev/VolGroup00 /dev/sdb1
lvm>vgdisplay 可以看到已分配空间和剩余未分配空间 All PE / Size 和 Free PE / Size
lvm>lvextend -L +5G /dev/VolGroup00/LogVol00
lvm>vgdisplay
lvm>pvdisplay
lvm>lvdisplay
lvm>quit
# resize2fs -p /dev/VolGroup00/LogVol00  扩展
# df -h

本文同步分享在 博客“xjsunjie”(51CTO)。
如有侵权,请联系 support@oschina.cn 删除。
本文参与“OSC源创计划”,欢迎正在阅读的你也加入,一起分享。

CentOS 5.X LVM 在线扩容根分区

CentOS 5.X LVM 在线扩容根分区

说明:
Linux 2.6以上内核支持ext3的在线扩容

第一种情况:直接添加一个新硬盘
# df -h 看看现在硬盘的情况
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
6.7G 5.2G 1.3G 81% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 633M 0 633M 0% /dev/shm

# fdisk -l 可以看到新添加的硬盘/dev/sdb
disk /dev/sda: 8589 MB,8589934592 bytes
255 heads,63 sectors/track,1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1044 8281507+ 8e Linux LVM

disk /dev/sdb: 8589 MB,8589934592 bytes
255 heads,1044 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

disk /dev/sdb doesn't contain a valid partition table

# lvm
lvm>vgdisplay 可以先看卷组是否还有剩余空间可以扩展,有的话直接扩展,没有或不够的话把新的硬盘添加进去
--- Volume group ---
VG Name VolGroup00
System ID
Format lvm2
Metadata Areas 1
Metadata Sequence No 3
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 2
Open LV 2
Max PV 0
Cur PV 1
Act PV 1
VG Size 7.88 GB
PE Size 32.00 MB
Total PE 252
Alloc PE / Size 252 / 7.88 GB
Free PE / Size 0 / 0

VG UUID 0U8dPB-UTJZ-Mdv5-eZJM-Xj7f-gR1M-63BcCh

lvm>pvcreate /dev/sdb 使用新的整个硬盘创建一个lvm物理卷
lvm>vgextend /dev/VolGroup00 /dev/sdb 把新的物理卷添加到卷组中
lvm>vgdisplay 可以看到已分配空间和剩余未分配空间 All PE / Size 和 Free PE / Size
--- Volume group ---
VG Name VolGroup00
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 15.84 GB
PE Size 32.00 MB
Total PE 507
Alloc PE / Size 252 / 7.88 GB
Free PE / Size 255 / 7.97 GB

VG UUID 0U8dPB-UTJZ-Mdv5-eZJM-Xj7f-gR1M-63BcCh

lvm>lvextend -L +7.9G /dev/VolGroup00/LogVol00 扩展逻辑卷大小
lvm>vgdisplay
lvm>pvdisplay
lvm>lvdisplay 可以看到已经添加了
--- Logical volume ---
LV Name /dev/VolGroup00/LogVol00
VG Name VolGroup00
LV UUID QtNkTM-TeSo-WnZD-fSUr-6k1F-5aLX-zaifSQ
LV Write Access read/write
LV Status available
# open 1
LV Size 14.78 GB
Current LE 473
Segments 2
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:0

--- Logical volume ---
LV Name /dev/VolGroup00/LogVol01
VG Name VolGroup00
LV UUID bhTEBX-t8XK-zGku-NCzx-eolz-Anvj-jUMUER
LV Write Access read/write
LV Status available
# open 1
LV Size 1.00 GB
Current LE 32
Segments 1
Allocation inherit
Read ahead sectors auto
- currently set to 256
Block device 253:1

lvm>quit
# resize2fs -p /dev/VolGroup00/LogVol00 修改文件系统大小以实现扩充空间
# df -h

第二种情况:只添加一个新分区
# df -h 可以看到新添加的硬盘/dev/sdb1
# lvm
lvm>pvcreate /dev/sdb1 使用新的硬盘创建一个lvm物理卷
lvm>vgextend /dev/VolGroup00 /dev/sdb1
lvm>vgdisplay 可以看到已分配空间和剩余未分配空间 All PE / Size 和 Free PE / Size
lvm>lvextend -L +5G /dev/VolGroup00/LogVol00
lvm>vgdisplay
lvm>pvdisplay
lvm>lvdisplay
lvm>quit
# resize2fs -p /dev/VolGroup00/LogVol00 扩展
# df -h

CentOS 7 根目录分区扩容

CentOS 7 根目录分区扩容

  1. 查看现有磁盘信息,可以看出根分区有 96G
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   96G  2.0G   94G   3% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G  8.5M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1               1014M  163M  852M  17% /boot
tmpfs                    396M     0  396M   0% /run/user/0
  1. 查看新增加的磁盘信息
  • fdisk
[root@localhost ~]# fdisk -l

Disk /dev/sda: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209715199   103808000   8e  Linux LVM

Disk /dev/mapper/centos-root: 102.1 GB, 102131302400 bytes, 199475200 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-swap: 4160 MB, 4160749568 bytes, 8126464 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


  • parted
[root@localhost ~]# parted -l
Model: QEMU QEMU HARDDISK (scsi)
Disk /dev/sda: 500GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags: 

Number  Start   End     Size    Type     File system  Flags
 1      1049kB  1075MB  1074MB  primary  xfs          boot
 2      1075MB  107GB   106GB   primary               lvm


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-swap: 4161MB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

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


Model: Linux device-mapper (linear) (dm)
Disk /dev/mapper/centos-root: 102GB
Sector size (logical/physical): 512B/512B
Partition Table: loop
Disk Flags: 

Number  Start  End    Size   File system  Flags
 1      0.00B  102GB  102GB  xfs



  1. 根据以上信息,对新增加的磁盘进行分区
[root@localhost ~]# fdisk /dev/sda 
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.


Command (m for help): m
Command action
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition''s system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)

Command (m for help): p

Disk /dev/sda: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209715199   103808000   8e  Linux LVM

Command (m for help): n
Partition type:
   p   primary (2 primary, 0 extended, 2 free)
   e   extended
Select (default p): p
Partition number (3,4, default 3): 
First sector (209715200-977272831, default 209715200): 
Using default value 209715200
Last sector, +sectors or +size{K,M,G} (209715200-977272831, default 977272831): 
Using default value 977272831
Partition 3 of type Linux and of size 366 GiB is set

Command (m for help): t
Partition number (1-3, default 3): 
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext''d (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 8e
Changed type of partition ''Linux'' to ''Linux LVM''

Command (m for help): p

Disk /dev/sda: 500.4 GB, 500363689984 bytes, 977272832 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: 0x0009051f

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     2099199     1048576   83  Linux
/dev/sda2         2099200   209715199   103808000   8e  Linux LVM
/dev/sda3       209715200   977272831   383778816   8e  Linux LVM

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.

重启系统后,登陆系统。(一定要重启系统,否则可能无法继续下面的操作扩充新分区)

同时在进行下一步之前,说明一下 pv、vg、lv 的关系。

一个硬盘 f 分区组成一个 pv(物理卷) 一个或者多个 pv 组成一个 vg(卷组) 一个 vg 可以划分出多个 lv(逻辑卷)

  1. 查看物理卷
[root@localhost ~]# lvs
  LV   VG     Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos -wi-ao---- <95.12g                                                    
  swap centos -wi-ao----  <3.88g 
  1. 创建物理卷
  • 格式化分区(非必需,先格式化后面创建物理卷还是会擦除)
# 查看系统的文件类型
[root@localhost ~]# df -T
Filesystem              Type     1K-blocks    Used Available Use% Mounted on
/dev/mapper/centos-root xfs       99688900 2028996  97659904   3% /
devtmpfs                devtmpfs   2010736       0   2010736   0% /dev
tmpfs                   tmpfs      2022628       0   2022628   0% /dev/shm
tmpfs                   tmpfs      2022628    8676   2013952   1% /run
tmpfs                   tmpfs      2022628       0   2022628   0% /sys/fs/cgroup
/dev/sda1               xfs        1038336  166632    871704  17% /boot
tmpfs                   tmpfs       404528       0    404528   0% /run/user/0

# 格式化为xfs
[root@localhost ~]# mkfs.xfs /dev/sda3
meta-data=/dev/sda3              isize=512    agcount=4, agsize=23986176 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=95944704, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=46848, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
  • 创建物理卷
[root@localhost ~]# pvcreate /dev/sda3
WARNING: xfs signature detected on /dev/sda3 at offset 0. Wipe it? [y/n]: y
  Wiping xfs signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.
  1. 查看物理卷信息
[root@localhost ~]# pvdisplay 
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos
  PV Size               <99.00 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              25343
  Free PE               1
  Allocated PE          25342
  PV UUID               00mdqs-YJl2-Oq3k-OlGb-7mbi-iTtz-HJl7cw
   
  "/dev/sda3" is a new physical volume of "366.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sda3
  VG Name               
  PV Size               366.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               6PYry3-VIRi-7DUc-5erS-yCEo-Laxu-ZkoYPo
   
[root@localhost ~]# vgdisplay 
  --- Volume group ---
  VG Name               centos
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               <99.00 GiB
  PE Size               4.00 MiB
  Total PE              25343
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       1 / 4.00 MiB
  VG UUID               yde5y3-OOS3-UmyT-iHwv-zwJ5-yE63-9ZHI9O
   
  1. 将新增加的分区 /dev/sda3 加入到根目录分区中,也就是上面的 VG Name: centos
[root@localhost ~]# vgextend centos /dev/sda3
  Volume group "centos" successfully extended
  1. 重新查看卷组信息
[root@localhost ~]# 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               464.99 GiB
  PE Size               4.00 MiB
  Total PE              119038
  Alloc PE / Size       25342 / 98.99 GiB
  Free  PE / Size       93696 / 366.00 GiB
  VG UUID               yde5y3-OOS3-UmyT-iHwv-zwJ5-yE63-9ZHI9O
   
  1. 进行卷扩容
  • 扩容前
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root   96G  2.0G   94G   3% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G  8.5M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1               1014M  163M  852M  17% /boot
tmpfs                    396M     0  396M   0% /run/user/0
  • 进行卷扩容
[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root
  Size of logical volume centos/root changed from <95.12 GiB (24350 extents) to <461.12 GiB (118046 extents).
  Logical volume centos/root successfully resized.
  1. 调整卷分区大小
[root@localhost ~]# xfs_growfs /dev/mapper/centos-root
meta-data=/dev/mapper/centos-root isize=512    agcount=4, agsize=6233600 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=24934400, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=12175, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 24934400 to 120879104
  1. 最后,查看磁盘信息可以看出根目录分区大小已成功扩容。
[root@localhost ~]# df -h
Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/centos-root  462G  2.0G  460G   1% /
devtmpfs                 2.0G     0  2.0G   0% /dev
tmpfs                    2.0G     0  2.0G   0% /dev/shm
tmpfs                    2.0G  8.5M  2.0G   1% /run
tmpfs                    2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1               1014M  163M  852M  17% /boot
tmpfs                    396M     0  396M   0% /run/user/0

CentOS 7 系统根目录分区扩容

CentOS 7 系统根目录分区扩容

说明:系统版本为 Linux version 3.10.0-327.el7.x86_64

1. 查看现有磁盘信息,可以看出根分区有 45G

[root@DEV-CMDB-DB02 ~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/centos_mb--centos7-root   45G  9.8G   35G  23% /
devtmpfs                             5.9G     0  5.9G   0% /dev
tmpfs                                5.9G   84K  5.9G   1% /dev/shm
tmpfs                                5.9G  8.9M  5.9G   1% /run
tmpfs                                5.9G     0  5.9G   0% /sys/fs/cgroup
/dev/sda1                            497M  142M  356M  29% /boot
tmpfs                                1.2G   16K  1.2G   1% /run/user/42
tmpfs                                1.2G     0  1.2G   0% /run/user/0

2. 查看新增加的磁盘信息

[root@DEV-CMDB-DB02 ~]# fdisk -l

Disk /dev/sda: 53.7 GB, 53687091200 bytes, 104857600 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: 0x000e0945

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

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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_mb--centos7-root: 47.7 GB, 47747956736 bytes, 93257728 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_mb--centos7-swap: 5368 MB, 5368709120 bytes, 10485760 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

3. 根据以上信息,对新增加的磁盘进行分区

[root@DEV-CMDB-DB02 ~]# fdisk /dev/sdb
Welcome to fdisk (util-linux 2.23.2).

Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0x232defba.

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x232defba

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-209715199, default 209715199): 
Using default value 209715199
Partition 1 of type Linux and of size 100 GiB is set

Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): L

 0  Empty           24  NEC DOS         81  Minix / old Lin bf  Solaris        
 1  FAT12           27  Hidden NTFS Win 82  Linux swap / So c1  DRDOS/sec (FAT-
 2  XENIX root      39  Plan 9          83  Linux           c4  DRDOS/sec (FAT-
 3  XENIX usr       3c  PartitionMagic  84  OS/2 hidden C:  c6  DRDOS/sec (FAT-
 4  FAT16 <32M      40  Venix 80286     85  Linux extended  c7  Syrinx         
 5  Extended        41  PPC PReP Boot   86  NTFS volume set da  Non-FS data    
 6  FAT16           42  SFS             87  NTFS volume set db  CP/M / CTOS / .
 7  HPFS/NTFS/exFAT 4d  QNX4.x          88  Linux plaintext de  Dell Utility   
 8  AIX             4e  QNX4.x 2nd part 8e  Linux LVM       df  BootIt         
 9  AIX bootable    4f  QNX4.x 3rd part 93  Amoeba          e1  DOS access     
 a  OS/2 Boot Manag 50  OnTrack DM      94  Amoeba BBT      e3  DOS R/O        
 b  W95 FAT32       51  OnTrack DM6 Aux 9f  BSD/OS          e4  SpeedStor      
 c  W95 FAT32 (LBA) 52  CP/M            a0  IBM Thinkpad hi eb  BeOS fs        
 e  W95 FAT16 (LBA) 53  OnTrack DM6 Aux a5  FreeBSD         ee  GPT            
 f  W95 Ext''d (LBA) 54  OnTrackDM6      a6  OpenBSD         ef  EFI (FAT-12/16/
10  OPUS            55  EZ-Drive        a7  NeXTSTEP        f0  Linux/PA-RISC b
11  Hidden FAT12    56  Golden Bow      a8  Darwin UFS      f1  SpeedStor      
12  Compaq diagnost 5c  Priam Edisk     a9  NetBSD          f4  SpeedStor      
14  Hidden FAT16 <3 61  SpeedStor       ab  Darwin boot     f2  DOS secondary  
16  Hidden FAT16    63  GNU HURD or Sys af  HFS / HFS+      fb  VMware VMFS    
17  Hidden HPFS/NTF 64  Novell Netware  b7  BSDI fs         fc  VMware VMKCORE 
18  AST SmartSleep  65  Novell Netware  b8  BSDI swap       fd  Linux raid auto
1b  Hidden W95 FAT3 70  DiskSecure Mult bb  Boot Wizard hid fe  LANstep        
1c  Hidden W95 FAT3 75  PC/IX           be  Solaris boot    ff  BBT            
1e  Hidden W95 FAT1 80  Old Minix      
Hex code (type L to list all codes): 8e
Changed type of partition ''Linux'' to ''Linux LVM''

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x232defba

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048   209715199   104856576   8e  Linux LVM

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

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

4. 创建物理卷

[root@DEV-CMDB-DB02 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created

5. 查看物理卷信息

[root@DEV-CMDB-DB02 ~]# pvdisplay
  --- Physical volume ---
  PV Name               /dev/sda2
  VG Name               centos_mb-centos7
  PV Size               49.51 GiB / not usable 3.00 MiB
  Allocatable           yes 
  PE Size               4.00 MiB
  Total PE              12674
  Free PE               10
  Allocated PE          12664
  PV UUID               8WbgjB-T1Lf-kqUD-qPFw-UwJu-B9Lc-GAUTUB
   
  "/dev/sdb1" is a new physical volume of "100.00 GiB"
  --- NEW Physical volume ---
  PV Name               /dev/sdb1
  VG Name               
  PV Size               100.00 GiB
  Allocatable           NO
  PE Size               0   
  Total PE              0
  Free PE               0
  Allocated PE          0
  PV UUID               HOknRs-TnMy-wtfX-sGqD-5RK9-dk9q-ze13fj
[root@DEV-CMDB-DB02 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_mb-centos7
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  3
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                2
  Open LV               2
  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       12664 / 49.47 GiB
  Free  PE / Size       10 / 40.00 MiB
  VG UUID               aN2D2P-Rk1y-wGFz-5l2I-5CcD-7s88-Z8czc7

6. 将新增加的分区 /dev/sdb1 加入到根目录分区 centos_mb-centos7 中

[root@DEV-CMDB-DB02 ~]# vgextend centos_mb-centos7 /dev/sdb1
  Volume group "centos_mb-centos7" successfully extended

7. 重新查看卷组信息

[root@DEV-CMDB-DB02 ~]# vgdisplay
  --- Volume group ---
  VG Name               centos_mb-centos7
  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               149.50 GiB
  PE Size               4.00 MiB
  Total PE              38273
  Alloc PE / Size       12664 / 49.47 GiB
  Free  PE / Size       25609 / 100.04 GiB
  VG UUID               aN2D2P-Rk1y-wGFz-5l2I-5CcD-7s88-Z8czc7

9. 进行卷扩容

[root@DEV-CMDB-DB02 ~]# lvextend -l +100%FREE /dev/mapper/centos_mb--centos7-root
  Size of logical volume centos_mb-centos7/root changed from 44.47 GiB (11384 extents) to 144.50 GiB (36993 extents).
  Logical volume root successfully resized.

10. 调整卷分区大小

[root@DEV-CMDB-DB02 ~]# xfs_growfs /dev/mapper/centos_mb--centos7-root
meta-data=/dev/mapper/centos_mb--centos7-root isize=256    agcount=4, agsize=2914304 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0        finobt=0
data     =                       bsize=4096   blocks=11657216, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=5692, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 11657216 to 37880832

最后,查看磁盘信息可以看出根目录分区大小已成功扩容

[root@DEV-CMDB-DB02 ~]# df -h
Filesystem                           Size  Used Avail Use% Mounted on
/dev/mapper/centos_mb--centos7-root  145G  9.8G  135G   7% /
devtmpfs                             5.9G     0  5.9G   0% /dev
tmpfs                                5.9G   84K  5.9G   1% /dev/shm
tmpfs                                5.9G  8.9M  5.9G   1% /run
tmpfs                                5.9G     0  5.9G   0% /sys/fs/cgroup
/dev/sda1                            497M  142M  356M  29% /boot
tmpfs                                1.2G   16K  1.2G   1% /run/user/42
tmpfs                                1.2G     0  1.2G   0% /run/user/0

 

关于centos根分区扩容centos扩展根分区的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于CentOS 5 LVM 在线扩容根分区、CentOS 5.X LVM 在线扩容根分区、CentOS 7 根目录分区扩容、CentOS 7 系统根目录分区扩容的相关知识,请在本站寻找。

本文标签: