CentOS根分区扩容方法

本文发布时间: 2019-Mar-22
查看操作系统[[email protected] ~]# uname -aLinux thinkpig007 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(约24GB)。(当然如果这里只有一个硬盘sda,有很多空间尚未使用可以进行同样的操作)操作步骤如下:第一步、查看本机现有分区情况[[email protected] ~]# df -h/dev/mapper/VolGroup-lv_root7.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第二步、查看本机的磁盘情况[[email protected] ~]# fdisk -lDevice Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinder boundary./dev/sda2 64 2089 16264192 8e Linux LVM/dev/sda3 2090 13054 88076362+ 83 Linux注意:此时还没有在EXSI5.0中添加第二块硬盘第三步、添加第二块硬盘查看此时系统磁盘情况[email protected] ~]# fdisk -lDevice Boot Start End Blocks Id System/dev/sda1 * 1 64 512000 83 LinuxPartition 1 does not end on cylinderboundary./dev/sda2 64 2089 16264192 8e Linux LVM/dev/sda3 2090 13054 88076362+ 83 LinuxDisk /dev/sdb: 17.2 GB, 17179869184 bytes255 heads, 63 sectors/track, 2088 cylinders可以看到我们新添加的硬盘sdb第四步、对第二块硬盘sdb进行分区[[email protected] ~]# fdisk /dev/sdbCommand (m for help): nCommand actione extendedp primary partition (1-4)pPartition number (1-4): 4First cylinder (1-2088, default 1):Using default value 1Last cylinder, +cylinders or +size{K,M,G}(1-2088, default 2088):Using default value 2088Command (m for help): wThe partition table has been altered!说明:上面操作对sdb硬盘进行了分区操作,设为sdb4分区了(当然上面建立的主分区可以为1-4中的任意一个,我这里选择的4)。第五步、对新建立的sdb4分区进行格式[[email protected] ~]# mkfs.ext4 /dev/sdb4文件系统标签=操作系统:Linux块大小=4096 (log=2)分块大小=4096 (log=2)正在写入inode表: 完成Creating journal (32768 blocks): 完成说明:将sdb4分区格式化为ext4格式,因为CentOS安装是系统的格式ext4,所以这里要注意一下.第六步、格式后的sdb4分区添加为物理卷[[email protected] ~]# pvcreate /dev/sdb4Physical volume "/dev/sdb4" successfully created第七步、查看当前系统的物理卷(PV)情况[[email protected] ~]# pvdisplayPVName /dev/sda2VGName VolGroupPVSize 15.51 GiB / not usable3.00 MiBAllocatable yes (butfull)PESize 4.00 MiBTotal PE 3970Free PE 0Allocated PE 3970PVUUID Up77sG-sNKf-Ja0k-crBf-N0wz-a5hy-T6sVFhPVName /dev/sdb4VGNamePVSize 15.99 Gi第八步、查看当前卷组情况[[email protected] ~]# vgdisplayVGName VolGroupSystem IDFormat lvm2Metadata Areas 1Metadata Sequence No 3VGAccess read/writeVGStatus resizableVGSize 15.51 GiBPESize 4.00 MiBTotal PE 3970Alloc PE / Size 3970 / 15.51GiBFree PE / Size 0 / 0VGUUID PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd第九步、将分区sdb4转换为扩展分区[[email protected] ~]# vgextend VolGroup/dev/sdb4Volume group "VolGroup" successfully extended第十步、查看当前的逻辑卷[[email protected] ~]# lvdisplay---Logical volume ---LVPath /dev/VolGroup/lv_rootLVName lv_rootVGName VolGroupLVUUID dCIsej-0NWX-bVFe-bT6L-c4eY-oy4G-9lNBOCLVStatus available#open 1LVSize 7.75 GiBCurrent LE 1985说明:这里可以看到“/”根分区的路径名称为:/dev/VolGroup/lv_root第十一步、查看扩展后的卷组情况[[email protected] ~]# vgdisplay---Volume group ---VGName VolGroupSystem IDFormat lvm2Metadata Areas 2Metadata Sequence No 4VGSize 31.50 GiBPESize 4.00 MiBTotal PE 8064Alloc PE / Size 3970 / 15.51GiBFree PE / Size 4094 / 15.99 GiBVGUUID PPrifh-glzl-nnxX-YkBm-xJ1s-rgnw-d1WsJd说明:扩展后的卷子情况,可以看出大小增加了16GB(与第八步中的对比)第十二步、将新增的逻辑卷全部扩展到“/”分区中[[email protected] ~]# lvextend -L +15.99G/dev/VolGroup/lv_rootRounding size to boundary between physical extents: 15.99 GiBExtending logical volume lv_root to 23.75 GiBLogical volume lv_root successfully resized说明:这里sdb4总共有16G,所以把16BG全部添加给根分区。第十三步、查看“/”根分区格式,并重新刷新根分区的大小[[email protected] ~]# e2fsck -f/dev/VolGroup/lv_roote2fsck 1.41.12 (17-May-2010)/dev/VolGroup/lv_root is mounted.e2fsck: 无法继续, 中止.[[email protected] ~]# resize2fs /dev/VolGroup/lv_rootresize2fs 1.41.12 (17-May-2010)Filesystem at /dev/VolGroup/lv_root ismounted on /; on-line resizing requiredold desc_blocks = 1, new_desc_blocks = 2Performing 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”的容量。第十三步、查看刷新后根分区的大小[[email protected] ~]# df -h文件系统容量已用可用已用%% 挂载点/dev/mapper/VolGroup-lv_root24G 7.1G 16G 32% /tmpfs 3.9G 144K 3.9G 1% /dev/shm/dev/sda3 83G 350M 79G 1% /media/Lucene说明:可以看到根分区的大小有7.7G变成了24G,重启一下系统再来看情况。此时就可以继续安装软件了,不会提示空间不足了。


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2019-May-25 12:57pm
栏目列表