centos7 parted 扩容
Posted laijx
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了centos7 parted 扩容相关的知识,希望对你有一定的参考价值。
(系统:vmware上的centos7.4 ,使用工具:parted分区命令。)
最近发现磁盘不够用了,需要加点。## WARNING ! 下面是实验过程,不代表生产环境。若有重要数据请操作前备份。
但是直接加还不够,还得分区。闲话不说,开始。
首先,在vm上已经加了空间,这里先加个10G试试手。(原来是20G,由于是SSD,存储空间吃紧)
然后启动虚机,df -h 查看状态
[[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 40G 1.8G 36G 5% / devtmpfs 983M 0 983M 0% /dev tmpfs 992M 0 992M 0% /dev/shm tmpfs 992M 8.5M 984M 1% /run tmpfs 992M 0 992M 0% /sys/fs/cgroup /dev/sdb1 20G 44M 19G 1% /data tmpfs 199M 0 199M 0% /run/user/0 [[email protected] ~]#
要对磁盘进行分区,首先得卸载,因为一会儿要重建分区:
[[email protected] ~]# umount /dev/sdb1
现在,parted出马了:(这里需要注意别把sdb打成了sdb1,别问我为什么要提醒=·)
[[email protected] ~]# parted /dev/sdb GNU Parted 3.1 Using /dev/sdb Welcome to GNU Parted! Type ‘help‘ to view a list of commands. (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 34.4GB Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 1049kB 21.0GB 21.0GB primary ext4 (parted)
这里我们看到整个盘有34G,但是分区,也就是sdb1只分了21G,现在我们进行扩容。
(parted) unit s
(parted) (parted) p Model: VMware, VMware Virtual S (scsi) Disk /dev/sdb: 67108864s Sector size (logical/physical): 512B/512B Partition Table: msdos Disk Flags: Number Start End Size Type File system Flags 1 2048s 41015295s 41013248s primary ext4 (parted)
这里用unit s 将显示单位设置为扇区,是为了方便后面分区。
先删除已有分区,rm 1
再设置我们需要的分区格式:ext4,起始扇区:2048,结束扇区,这里我们以大小替代:32G
(parted) rm 1 (parted) (parted) (parted) (parted) mkpart primary ext4 2048 32G (parted) (parted) q Information: You may need to update /etc/fstab. [[email protected] ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda1 40G 1.8G 36G 5% / devtmpfs 983M 0 983M 0% /dev tmpfs 992M 0 992M 0% /dev/shm tmpfs 992M 8.5M 984M 1% /run tmpfs 992M 0 992M 0% /sys/fs/cgroup tmpfs 199M 0 199M 0% /run/user/0 /dev/sdb1 20G 44M 19G 1% /data [[email protected] ~]#
退出parted之后我们再df看,发现未生效,因为还有几个命令要敲:
[[email protected] ~]# umount /dev/sdb1 先卸载 [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# e2fsck -f /dev/sdb1 检测磁盘是否有错误 e2fsck 1.42.9 (28-Dec-2013) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/sdb1: 11/1286144 files (0.0% non-contiguous), 124769/5126656 blocks [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# resize2fs /dev/sdb1 扩展数据盘大小,如果文件格式为xfs,则使用命令:xfs_growfs /dev/sdb1 resize2fs 1.42.9 (28-Dec-2013) Resizing the filesystem on /dev/sdb1 to 7812352 (4k) blocks. The filesystem on /dev/sdb1 is now 7812352 blocks long. [[email protected] ~]# [[email protected] ~]# [[email protected] ~]# mount -a 重新挂载 [[email protected] ~]# [[email protected] ~]# df -Th Filesystem Type Size Used Avail Use% Mounted on /dev/sda1 ext4 40G 1.8G 36G 5% / devtmpfs devtmpfs 983M 0 983M 0% /dev tmpfs tmpfs 992M 0 992M 0% /dev/shm tmpfs tmpfs 992M 8.5M 984M 1% /run tmpfs tmpfs 992M 0 992M 0% /sys/fs/cgroup tmpfs tmpfs 199M 0 199M 0% /run/user/0 /dev/sdb1 ext4 30G 44M 28G 1% /data [[email protected] ~]# [[email protected] ~]#
成功扩容至30G。
以上是关于centos7 parted 扩容的主要内容,如果未能解决你的问题,请参考以下文章