欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

centos7扩展根分区

发布时间:2024/10/12 编程问答 40 豆豆
生活随笔 收集整理的这篇文章主要介绍了 centos7扩展根分区 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

  购买的云主机,安装centos7后,发现系统根分区只有8.5G,而云主机硬盘大小是110G。

现在想把剩余的硬盘大小找出来,然后扩容至根分区。

  本文主题是:centos扩展根分区。由于阿里云,腾讯云在购买主机时,硬盘大小即为根分区

大小,没有遇到到需要扩容的情况。

  1、查看硬盘大小信息

[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 8.5G 1.5G 7.0G 18% / devtmpfs 231M 0 231M 0% /dev tmpfs 241M 0 241M 0% /dev/shm tmpfs 241M 4.3M 237M 2% /run tmpfs 241M 0 241M 0% /sys/fs/cgroup /dev/sda1 494M 124M 371M 25% /boot tmpfs 49M 0 49M 0% /run/user/0# 发现只有8.5G,总大小没有110G   发现根目录只有8.5G,总大小没有110G,然后使用fdisk -l命令查看,发现剩余的空间在sdb第二个磁盘上:
[root@localhost ~]# fdisk -lDisk /dev/sda: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0x000f1903Device Boot Start End Blocks Id System /dev/sda1 * 2048 1026047 512000 83 Linux /dev/sda2 1026048 20971519 9972736 8e Linux LVMDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/centos-root: 116.5 GB, 116505182208 bytes, 227549184 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytesDisk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes

  发现sdb磁盘有3个分区,分别是:sdb1、sdb2、sdb3,上面截图是我完成后的,所以看到sdb只有一个分区。

  2、删除分区、磁盘分区

  # fdisk /dev/sdb       #将磁盘分区  #先删除分区,再将磁盘分为一个区

  m -----> 打印help信息

  d -----> 删除分区

  p ----->  打印sdb磁盘的分区信息

  n ----->  创建新分区,进到分区项后,按p直接分区,默认分为一个区,自行选择分区数量。

  w ----->  保存分区信息,不然分区无法正确完成。

 

[root@localhost ~]# 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 0xef6f1f81.The device presents a logical sector size that is smaller than the physical sector size. Aligning to a physical sector (or optimal I/O) size boundary is recommended, or performance may be impacted.Command (m for help): m Command actiona toggle a bootable flagb edit bsd disklabelc toggle the dos compatibility flagd delete a partitiong create a new empty GPT partition tableG create an IRIX (SGI) partition tablel list known partition typesm print this menun add a new partitiono create a new empty DOS partition tablep print the partition tableq quit without saving changess create a new empty Sun disklabelt change a partition's system idu change display/entry unitsv verify the partition tablew write table to disk and exitx extra functionality (experts only)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): 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 setCommand (m for help): pDisk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 4096 bytes I/O size (minimum/optimal): 4096 bytes / 4096 bytes Disk label type: dos Disk identifier: 0xef23a9cbDevice Boot Start End Blocks Id System /dev/sdb1 2048 209715199 104856576 83 LinuxCommand (m for help): w The partition table has been altered!Calling ioctl() to re-read partition table. Syncing disks.

 

  3、格式化磁盘

# mkfs.ext4 /dev/sdb  #格式化为ext4格式 [root@localhost ~]# mkfs.ext4 /dev/sdb mke2fs 1.42.9 (28-Dec-2013) /dev/sdb is entire device, not just one partition! Proceed anyway? (y,n) y Discarding device blocks: done Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 6553600 inodes, 26214400 blocks 1310720 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2174746624 800 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, 11239424, 20480000, 23887872Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done

  4、创建物理卷

# pvcreate /dev/sdb [root@localhost ~]# pvcreate /dev/sdb WARNING: ext4 signature detected on /dev/sdb at offset 1080. Wipe it? [y/n]: yWiping ext4 signature on /dev/sdb.Physical volume "/dev/sdb" successfully created

  5、查看卷组名称

# vgdisplay -v
# 查看到我的VG Name为“centos”
[root@localhost ~]# vgdisplay -vUsing volume group(s) on command line.--- Volume group ---VG Name centosSystem ID Format lvm2Metadata Areas 1Metadata Sequence No 3VG Access read/writeVG Status resizableMAX LV 0Cur LV 2Open LV 2Max PV 0Cur PV 1Act PV 1VG Size 9.51 GiBPE Size 4.00 MiBTotal PE 2434Alloc PE / Size 2424 / 9.47 GiBFree PE / Size 10 / 40.00 MiBVG UUID OyB5dN-0LOk-6vb1-Qmtu-1EQp-1GtB-Szuco0--- Logical volume ---LV Path /dev/centos/swapLV Name swapVG Name centosLV UUID 9SLqUm-dXfi-bNle-wdX1-cnZQ-HCun-nGWdXkLV Write Access read/writeLV Creation host, time localhost.localdomain, 2016-06-28 02:34:19 +0800LV Status available# open 2LV Size 1.00 GiBCurrent LE 256Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:1--- Logical volume ---LV Path /dev/centos/rootLV Name rootVG Name centosLV UUID J3ANyS-BTG5-YJ8M-2Zsq-sBUo-YVWg-jyFmvALV Write Access read/writeLV Creation host, time localhost.localdomain, 2016-06-28 02:34:19 +0800LV Status available# open 1LV Size 8.47 GiBCurrent LE 2168Segments 1Allocation inheritRead ahead sectors auto- currently set to 8192Block device 253:0--- Physical volumes ---PV Name /dev/sda2 PV UUID P6xf6f-NPgl-s3Dm-123h-B5e3-NJBh-GbNM1nPV Status allocatableTotal PE / Free PE 2434 / 10

  6、将物理卷扩展到卷组

  # vgextend centos /dev/sdb

[root@localhost ~]# vgextend centos /dev/sdbVolume group "centos" successfully extended

  7、将卷组中的空闲空间扩展到根分区逻辑卷

  #lvextend -l +100%FREE /dev/centos/root

[root@localhost ~]# lvextend -l +100%FREE /dev/mapper/centos-root Size of logical volume centos/root changed from 8.47 GiB (2168 extents) to 108.50 GiB (27777 extents).Logical volume root successfully resized.

  8、刷新根分区

  # xfs_growfs /dev/centos/root

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

  9、查看扩展是否成功

[root@localhost ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos-root 109G 1.5G 108G 2% / devtmpfs 231M 0 231M 0% /dev tmpfs 241M 0 241M 0% /dev/shm tmpfs 241M 4.3M 237M 2% /run tmpfs 241M 0 241M 0% /sys/fs/cgroup /dev/sda1 494M 124M 371M 25% /boot tmpfs 49M 0 49M 0% /run/user/0

  看到根分区已为109G大小,扩展根分区成功!

 

 

转载于:https://www.cnblogs.com/catinsky/p/9318380.html

总结

以上是生活随笔为你收集整理的centos7扩展根分区的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。