当前位置:   article > 正文

centos 调整home分区xfs_CentOS 7扩展根分区

: xfs signature detected on /dev/sdb1 at offset 0. wipe it? [y/n]

682644cafac501d24ee579fb5b06eb5e.png
from 人类身份验证 - SegmentFault

VirtualBox中安装了CentOS 7,给同事用来做kafka和zookeeper测试服务器。昨晚kafka意外终止,看了日志发现是/root只分配了1GiB大小,已接近饱和。开始bing,总结一下步骤:

列出各分区使用情况:

  1. # df -Th
  2. Filesystem Type Size Used Avail Use% Mounted on
  3. /dev/mapper/centos-root xfs 997M 994M 2.9M 100% /
  4. devtmpfs devtmpfs 915M 0 915M 0% /dev
  5. tmpfs tmpfs 921M 0 921M 0% /dev/shm
  6. tmpfs tmpfs 921M 17M 905M 2% /run
  7. tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
  8. /dev/mapper/centos-usr xfs 4.9G 1.6G 3.4G 33% /usr
  9. /dev/sda1 xfs 97M 66M 31M 69% /boot
  10. /dev/mapper/centos-var xfs 2.4G 473M 1.9G 21% /var

可以看见 /dev/mapper/centos-root 已经使用了100%,我们准备为它扩容。

在VirtualBox中添加一块新的虚拟磁盘:

先关闭操作系统。在VirtualBox中选中当前VM,设置->存储->控制器->SATA控制器,点击图标“添加虚拟硬盘”,新建一个虚拟硬盘。我增加了一块3GiB大小的虚拟磁盘,保存后再次启动虚拟机。

创建新分区

先看一下现有磁盘情况:

# fdisk -l

结果:

  1. Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
  2. Units = sectors of 1 * 512 = 512 bytes
  3. Sector size (logical/physical): 512 bytes / 512 bytes
  4. I/O size (minimum/optimal): 512 bytes / 512 bytes
  5. Disk label type: dos
  6. Disk identifier: 0x000940ec
  7. Device Boot Start End Blocks Id System
  8. /dev/sda1 * 2048 206847 102400 83 Linux
  9. /dev/sda2 206848 41943039 20868096 8e Linux LVM
  10. Disk /dev/sdb: 3221 MB, 3221225472 bytes, 6291456 sectors
  11. Units = sectors of 1 * 512 = 512 bytes
  12. Sector size (logical/physical): 512 bytes / 512 bytes
  13. I/O size (minimum/optimal): 512 bytes / 512 bytes
  14. Disk /dev/mapper/centos-swap: 2097 MB, 2097152000 bytes, 4096000 sectors
  15. Units = sectors of 1 * 512 = 512 bytes
  16. Sector size (logical/physical): 512 bytes / 512 bytes
  17. I/O size (minimum/optimal): 512 bytes / 512 bytes
  18. Disk /dev/mapper/centos-usr: 5242 MB, 5242880000 bytes, 10240000 sectors
  19. Units = sectors of 1 * 512 = 512 bytes
  20. Sector size (logical/physical): 512 bytes / 512 bytes
  21. I/O size (minimum/optimal): 512 bytes / 512 bytes
  22. Disk /dev/mapper/centos-root: 1048 MB, 1048576000 bytes, 2048000 sectors
  23. Units = sectors of 1 * 512 = 512 bytes
  24. Sector size (logical/physical): 512 bytes / 512 bytes
  25. I/O size (minimum/optimal): 512 bytes / 512 bytes
  26. ...
  27. ...
  28. ...

已经可以看到新磁盘/dev/sdb

对新磁盘进行分区:

# fdisk /dev/sdb

在fdisk的交互模式中,依次输入:

  1. n --创建新分区
  2. p --创建主分区
  3. <回车> --默认分区编号
  4. <回车> --默认起始扇区位置。
  5. <回车> --默认结束扇区位置。
  6. w --写入分区表

这样就把整个磁盘分成了一个区。
再看一下现有磁盘情况:

# fdisk -l

已经多出了一个新分区:

  1. Device Boot Start End Blocks Id System
  2. /dev/sdb1 2048 6291455 3144704 83 Linux

将新分区用于扩展/root

先看一下卷分组:

  1. # vgdisplay -v
  2. Finding all volume groups
  3. Finding volume group "centos"
  4. --- Volume group ---
  5. VG Name centos
  6. System ID
  7. Format lvm2
  8. Metadata Areas 1
  9. Metadata Sequence No 6
  10. VG Access read/write
  11. VG Status resizable
  12. MAX LV 0
  13. Cur LV 5
  14. Open LV 5
  15. Max PV 0
  16. Cur PV 1
  17. Act PV 1
  18. VG Size 19.90 GiB
  19. PE Size 4.00 MiB
  20. Total PE 5094
  21. Alloc PE / Size 5093 / 19.89 GiB
  22. Free PE / Size 1 / 4.00 MiB
  23. VG UUID vtJL08-7Jxi-5IqK-3fUg-Pben-682a-wiv2GL
  24. --- Logical volume ---
  25. LV Path /dev/centos/root
  26. LV Name root
  27. VG Name centos
  28. LV UUID ZWTgoT-AMWs-g54v-dZA1-NQUj-mqGa-8tmr4U
  29. LV Write Access read/write
  30. LV Creation host, time localhost, 2016-07-03 21:59:31 -0400
  31. LV Status available
  32. # open 1
  33. LV Size 1000.00 MiB
  34. Current LE 250
  35. Segments 1
  36. Allocation inherit
  37. Read ahead sectors auto
  38. currently set to 256
  39. Block device 253:2
  40. ...
  41. ...
  42. ...
  43. --- Physical volumes ---
  44. PV Name /dev/sda2
  45. PV UUID fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC
  46. PV Status allocatable
  47. Total PE / Free PE 5094 / 1

可以看到当前卷分组名为"centos"。

为之前新增的分区创建物理卷:

# pvcreate /dev/sdb1

提示是否擦除xfs签名,我选了y:

  1. WARNING: xfs signature detected on /dev/sdb1 at offset 0. Wipe it? [y/n] y
  2. Wiping xfs signature on /dev/sdb1.
  3. Physical volume "/dev/sdb1" successfully created

查看结果:

# pvdisplay

已经看到新创建的3GiB大小的物理卷:

  1. --- Physical volume ---
  2. PV Name /dev/sda2
  3. VG Name centos
  4. PV Size 19.90 GiB / not usable 3.00 MiB
  5. Allocatable yes
  6. PE Size 4.00 MiB
  7. Total PE 5094
  8. Free PE 1
  9. Allocated PE 5093
  10. PV UUID fiVH1e-lwfi-63Lr-oIlK-GDZI-dcuZ-T04VlC
  11. "/dev/sdb1" is a new physical volume of "3.00 GiB"
  12. --- NEW Physical volume ---
  13. PV Name /dev/sdb1
  14. VG Name
  15. PV Size 3.00 GiB
  16. Allocatable NO
  17. PE Size 0
  18. Total PE 0
  19. Free PE 0
  20. Allocated PE 0
  21. PV UUID VGXSAn-UiZ0-Fy40-eQxb-53xA-5hZM-3eGPg0

扩展卷分组,"centos"是vgdisplay命令查到的卷分组名:

# vgextend centos /dev/sdb1

提示成功扩展。

下面查看一下逻辑卷:

# lvdisplay

可以看到/dev/centos/root目前的LV Size是1000MiB。

下面扩展逻辑卷/dev/centos/root:

# lvextend -L +3G /dev/centos/root

注:+3G是我们新增加的分区大小。

扩展后,还要执行一步:

# xfs_growfs /dev/centos/root

将文件系统扩大。
完成。

因为安装CentOS用的xfs分区,所以使用命令 xfs_growfs扩展文件系统大小。否则的话使用resize2fs命令。

查看结果:

# df -Th

/root已经扩充到4GiB:

  1. Filesystem Type Size Used Avail Use% Mounted on
  2. /dev/mapper/centos-root xfs 4.0G 995M 3.1G 25% /
  3. devtmpfs devtmpfs 915M 0 915M 0% /dev
  4. tmpfs tmpfs 921M 0 921M 0% /dev/shm
  5. tmpfs tmpfs 921M 8.4M 913M 1% /run
  6. tmpfs tmpfs 921M 0 921M 0% /sys/fs/cgroup
  7. /dev/mapper/centos-usr xfs 4.9G 1.6G 3.4G 33% /usr
  8. /dev/mapper/centos-home xfs 9.8G 391M 9.4G 4% /home
  9. /dev/mapper/centos-var xfs 2.4G 469M 1.9G 20% /var
  10. /dev/sda1 xfs 97M 66M 31M 69% /boot
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/羊村懒王/article/detail/166460
推荐阅读
相关标签
  

闽ICP备14008679号