【大数据集群运维】VMware虚拟机扩展Linux的root根目录磁盘空间(Centos7)

一、Centos 关机,选择编辑虚拟机设置,硬盘,在实用工具那里选择“扩展”

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

二、启动客户机操作系统Centos,在操作系统内部对磁盘重新分区和扩容

1 fdisk -l

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


Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278

   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        1306     9972736   8e  Linux LVM

Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000

2其中,可以看到现在的分区情况如下


   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        1306     9972736   8e  Linux LVM

3、创建分区 sda3fdisk /dev/sda

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): n           # 输入 n 表示创建新分区
Command action
   e   extended
   p   primary partition (1-4)
   p                                            # 默认输入P
Partition number (1-4): 3   # 输入 3 表示sda3,因为前面已经有两个了
First cylinder (1306-4568, default 1306):     # 回车,按默认值
Using default value 1306
Last cylinder, +cylinders or +size{K,M,G} (1306-4568, default 4568):   # 回车,按默认值
Using default value 4568

Command (m for help): w     # 输入 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.

再次查看分区情况 fdisk -l

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


Disk /dev/loop1: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/sda: 37.6 GB, 37580963840 bytes
255 heads, 63 sectors/track, 4568 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000c8278

   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        1306     9972736   8e  Linux LVM
/dev/sda3            1306        4568    26206700   83  Linux

Disk /dev/mapper/vg_test001-lv_root: 9135 MB, 9135194112 bytes
255 heads, 63 sectors/track, 1110 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/vg_test001-lv_swap: 1073 MB, 1073741824 bytes
255 heads, 63 sectors/track, 130 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000


Disk /dev/mapper/docker-253:0-264224-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 65536 bytes
Disk identifier: 0x00000000

其中,分区已变为3个(/dev/sda1,/dev/sda2,/dev/sda3)了,但这时还没挂载,还不能用,

4、重启操作系统

5、格式化新分区为ext3

 mkfs -t ext3 /dev/sda3

[root@shuang ~]# mkfs -t ext3 /dev/sda3
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=
OS type: Linux
块大小=4096 (log=2)
分块大小=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1310720 inodes, 5242880 blocks
262144 blocks (5.00%) reserved for the super user
第一个数据块=0
Maximum filesystem blocks=4294967296
160 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

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成

6、将物理硬盘分区初始化为物理卷,以便被LVM使用,输入指令

[root@shuang ~]# lvs
  LV   VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_shuang -wi-ao---- <17.00g                                                    
  swap centos_shuang -wi-ao----   2.00g                                                    
[root@shuang ~]# lvs
pvcreate /dev/sda3  LV   VG            Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root centos_shuang -wi-ao---- <17.00g                                                    
  swap centos_shuang -wi-ao----   2.00g                                                    
[root@shuang ~]# pvcreate /dev/sda3
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: 
  WARNING: Invalid input ''.
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: ^H^H^Hy
  WARNING: Invalid input 'y'.
WARNING: ext3 signature detected on /dev/sda3 at offset 1080. Wipe it? [y/n]: y
  Wiping ext3 signature on /dev/sda3.
  Physical volume "/dev/sda3" successfully created.

7、向卷组中添加物理卷来增加卷组的容量

[root@shuang ~]#  df -h
文件系统                        容量  已用  可用 已用% 挂载点
devtmpfs                        1.2G     0  1.2G    0% /dev
tmpfs                           1.2G     0  1.2G    0% /dev/shm
tmpfs                           1.2G  9.9M  1.2G    1% /run
tmpfs                           1.2G     0  1.2G    0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root   17G  6.4G   11G   38% /
/dev/sda1                      1014M  184M  831M   19% /boot
tmpfs                           229M     0  229M    0% /run/user/0

其中centos_shuang是组名

[root@shuang ~]# vgextend centos_shuang-root  /dev/sda3         
  Volume group "centos_shuang-root" not found
  Cannot process volume group centos_shuang-root
[root@shuang ~]# vgextend centos_shuang  /dev/sda3     
  Volume group "centos_shuang" successfully extended

8、查看可扩展的空间大小

 vgdisplay
 vgdisplay
  --- Volume group ---
  VG Name               centos_shuang
  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               38.99 GiB
  PE Size               4.00 MiB
  Total PE              9982
  Alloc PE / Size       4863 / <19.00 GiB
  Free  PE / Size       5119 / <20.00 GiB
  VG UUID               B8mmPl-Nyh8-N9yN-7OQf-in8I-neL7-zFrK2P

其中 Free PE / Size 就是可供分配的自由空间,最多有 19G,在扩展时输入小于该值

9、扩充磁盘空间

lvextend -L+19G  /dev/mapper/centos_shuang-root     /dev/sda3  
lvextend -L+19G  /dev/mapper/centos_shuang-root     /dev/sda3  
  Size of logical volume centos_shuang/root changed from <17.00 GiB (4351 extents) to <36.00 GiB (9215 extents).
  Logical volume centos_shuang/root successfully resized.

10、使用e2fsck指令检查文件系统错误

e2fsck -a /dev/mapper/centos_shuang-root
e2fsck -a /dev/mapper/centos_shuang-root
/dev/mapper/centos_shuang-root is mounted.
e2fsck: 无法继续, 中止.

查看lv空间是否扩充成功

lvdisplay
[root@shuang ~]#  lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos_shuang/swap
  LV Name                swap
  VG Name                centos_shuang
  LV UUID                bc72KO-b6hy-IvVN-MXSk-OUKM-7JTV-EcPJ2E
  LV Write Access        read/write
  LV Creation host, time shuang, 2020-01-09 13:54:14 +0800
  LV Status              available
  # open                 2
  LV Size                2.00 GiB
  Current LE             512
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos_shuang/root
  LV Name                root
  VG Name                centos_shuang
  LV UUID                j37rXa-Ug0E-Y2sE-hz6m-QpEw-LX1X-LLCgTo
  LV Write Access        read/write
  LV Creation host, time shuang, 2020-01-09 13:54:15 +0800
  LV Status              available
  # open                 1
  LV Size                <36.00 GiB
  Current LE             9215
  Segments               2
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0

11、使用Centeros7指令 xfs_growfs /dev/mapper/centos_shuang-root 将LV空间同步到文件系统根目录中

 xfs_growfs    /dev/mapper/centos_shuang-root            
meta-data=/dev/mapper/centos_shuang-root isize=512    agcount=4, agsize=1113856 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=4455424, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 4455424 to 9436160

12 验证查看是否同步成功

在CenterOS7系列中xfs同步要用下面这个命令

xfs_growfs

CenterOS6系列中xfs同步要用下面这两个命令都可

dumpe2fs
resize2fs -f
[root@shuang ~]# df -h    
文件系统                        容量  已用  可用 已用% 挂载点
devtmpfs                        1.2G     0  1.2G    0% /dev
tmpfs                           1.2G     0  1.2G    0% /dev/shm
tmpfs                           1.2G  9.9M  1.2G    1% /run
tmpfs                           1.2G     0  1.2G    0% /sys/fs/cgroup
/dev/mapper/centos_shuang-root   36G  6.4G   30G   18% /
/dev/sda1                      1014M  184M  831M   19% /boot
tmpfs                           229M     0  229M    0% /run/user/0

根目录 36G,扩容成功!

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
centos-root根目录磁盘空间不足时,不想删除数据的解决方法是通过扩容来增加磁盘空间。以下是解决步骤: 1. 查看磁盘空间使用情况:使用命令`df -h`来查看当前磁盘使用情况,确认根目录空间不足的情况。 2. 查看硬盘分区情况:使用命令`fdisk -l`来查看硬盘分区情况,确定待扩容的分区。 3. 创建一个新的分区:使用fdisk命令来创建一个新的分区,并将其分配给根目录。具体步骤是输入`fdisk /dev/sda`进入fdisk分区工具,选择需要创建分区的硬盘(通常是/dev/sda),依次执行`n`(新建分区)、`p`(主分区)、`3`(分区号,根据情况选择)、设置分区的起始和结束位置、`w`(保存分区表)。 4. 格式化新分区:使用命令`mkfs.ext4 /dev/sda3`将新分区格式化为ext4文件系统。 5. 挂载新分区:使用命令`mount /dev/sda3 /mnt`来将新分区挂载到/mnt目录。 6. 复制文件到新分区:使用命令`cp -rfp /bin/* /mnt`将根目录下的文件和目录复制到新分区。 7. 更新/etc/fstab文件:使用编辑器打开/etc/fstab文件,将新分区的信息添加到该文件中,以使系统能够自动挂载新分区。 8. 卸载原根目录:使用命令`umount /`来卸载原根目录。 9. 挂载新根目录:使用命令`mount /dev/sda3 /`来将新分区挂载为新的根目录。 10. 重启系统:使用命令`reboot`重启系统,使修改生效。 通过以上步骤,可以在不删除数据的情况下扩容centos-root根目录磁盘空间。请注意,在进行任何磁盘操作前,请备份重要数据以防意外情况发生。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

牵牛刘先生

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值