Centos给根目录扩容教程 -亲测好用

亲测好用

一、问题与目的

原因是磁盘空间已满,正好有时间,研究一下怎么对Centos进行扩容

二、解决方法

1、首先,通过命令df -h 观察磁盘占用情况

可以发现根目录已经被写满了,这会导致所有写操作都无法进行

2、先关闭虚拟机,然后在VMware的设置中选择添加一块新的硬盘(一直点下一步就可以了)

我选择了扩容40G

3、重启虚拟机后通过命令lsblk可以发现多了一个分区sdb(原来只有sda)

所以接下来对sdb进行分区操作

4、对sdb进行分区操作

1.[root@itcast ~]# fdisk /dev/sdb

2.Welcome to fdisk (util-linux 2.23.2).

3.

4.Changes will remain in memory only, until you decide to write them.

5.Be careful before using the write command.

6.

7.Device does not contain a recognized partition table

8.Building a new DOS disklabel with disk identifier 0xdeeb604b.

9.

10.Command (m for help): m #这个是帮助 可忽略

11.Command action

12. a toggle a bootable flag

13. b edit bsd disklabel

14. c toggle the dos compatibility flag

15. d delete a partition

16. g create a new empty GPT partition table

17. G create an IRIX (SGI) partition table

18. l list known partition types

19. m print this menu

20. n add a new partition

21. o create a new empty DOS partition table

22. p print the partition table

23. q quit without saving changes

24. s create a new empty Sun disklabel

25. t change a partition's system id

26. u change display/entry units

27. v verify the partition table

28. w write table to disk and exit

29. x extra functionality (experts only)

31.Command (m for help): n #输入n新建一个分区

32.Partition type:

33. p primary (0 primary, 0 extended, 4 free)

34. e extended

35.Select (default p): p #输入p,将分区创建为主分区

36.Partition number (1-4, default 1): 1

37.First sector (2048-83886079, default 2048): #默认 回车

38.Using default value 2048

39.Last sector, +sectors or +size{K,M,G} (2048-83886079, default 83886079):

40.Using default value 83886079

41.Partition 1 of type Linux and of size 40 GiB is set

42.

43.Command (m for help): t #输入t改变分区类型

44.Selected partition 1

45.Hex code (type L to list all codes): 8e #输入8e对应LVM

46.Changed type of partition 'Linux' to 'Linux LVM'

47.

48.Command (m for help): w #保存

49.The partition table has been altered!

50.

51.Calling ioctl() to re-read partition table.

52.Syncing disks.

53.

再次观察发现有了sdb1分区

1.[root@itcast ~]# lsblk

2.NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT

3.sda 8:0 0 40G 0 disk

4.├─sda1 8:1 0 200M 0 part /boot

5.└─sda2 8:2 0 39.8G 0 part

6. ├─centos-root 253:0 0 30G 0 lvm /

7. └─centos-swap 253:1 0 9.8G 0 lvm [SWAP]

8.sdb 8:16 0 40G 0 disk

9.└─sdb1 8:17 0 40G 0 part

10.sr0 11:0 1 1024M 0 rom

5、查看根分区的文件系统类型

命令 parted -l

6、格式化sdb1

1.[root@itcast ~]# mkfs.xfs /dev/sdb1

2.meta-data=/dev/sdb1 isize=512 agcount=4, agsize=2621376 blks

3. = sectsz=512 attr=2, projid32bit=1

4. = crc=1 finobt=0, sparse=0

5.data = bsize=4096 blocks=10485504, imaxpct=25

6. = sunit=0 swidth=0 blks

7.naming =version 2 bsize=4096 ascii-ci=0 ftype=1

8.log =internal log bsize=4096 blocks=5119, version=2

9. = sectsz=512 sunit=0 blks, lazy-count=1

10.realtime =none extsz=4096 blocks=0, rtextents=0

7、查看卷组信息(记住LV Path 和 VG Name)

8、开始扩容

1.[root@itcast ~]# pvcreate /dev/sdb1 #将sdb1分区变为pv

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

3. Wiping xfs signature on /dev/sdb1.

4. Physical volume "/dev/sdb1" successfully created.

5.[root@itcast ~]# vgextend centos /dev/sdb1 #将/dev/sdc1卷加入根目录所在的卷组名centos

6. Couldn't create temporary archive name. ##报错啦!

7.

  • 发现报错了,"Couldn't create temporary archive name" 错误通常与 Logical Volume Manager (LVM) 中的缺少或损坏的临时文件有关。所以我们清理一下/tmp目录

执行 rm -rf /tmp/*

1.[root@itcast ~]# vgextend centos /dev/sdb1

2. Volume group "centos" successfully extended

成功了

接着查看卷组信息 (记住Free PE)

命令 vgdisplay centos

把所有空间分配给根分区

1.[root@itcast ~]# lvextend -l +10239 /dev/centos/root #10239=free pe 注意这里

2. Size of logical volume centos/root changed from 30.00 GiB (7680 extents) to

3. Logical volume centos/root successfully resized.

最后是文件系统的扩容

1.[root@itcast ~]# xfs_growfs /dev/centos/root

2.meta-data=/dev/mapper/centos-root isize=512 agcount=4, agsize=1966080 blks

3. = sectsz=512 attr=2, projid32bit=1

4. = crc=1 finobt=0 spinodes=0

5.data = bsize=4096 blocks=7864320, imaxpct=25

6. = sunit=0 swidth=0 blks

7.naming =version 2 bsize=4096 ascii-ci=0 ftype=1

8.log =internal bsize=4096 blocks=3840, version=2

9. = sectsz=512 sunit=0 blks, lazy-count=1

10.realtime =none extsz=4096 blocks=0, rtextents=0

11.data blocks changed from 7864320 to 18349056

Done!

  • 25
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值