linux 分区命令(linux 分区扩容)

linux 分区命令(linux 分区扩容)

扫码添加渲大师小管家,免费领取渲染插件、素材、模型、教程合集大礼包!

linux 分区命令(linux 分区扩容)

重要提示:备份数据,备份数据,备份数据

环境:

系统 centos 7

磁盘:只有一块物理磁盘,系统安装时,系统分区给的太小,因此需要在原有磁盘的基础上直接扩容系统分区

适用场景:虚拟机磁盘系统盘扩容,阿里云服务器系统盘扩容

当前系统磁盘挂载情况

[root@db2 tmpuser]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/center-root 14G 2.1G 12G 16% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 8.5M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/1000

查看当前文件系统树状信息

[root@db2 tmpuser]# lsblk -f

NAME FSTYPE LABEL UUID MOUNTPOINT
sda
├─sda1 xfs f3e7dd36-9501-4c90-9449-5fed5ace62a3 /boot
└─sda2 LVM2_member PGTG3k-7LUa-6TlF-oOBx-RIu6-71dB-R3yoL1
├─center-root xfs bd3b1947-6db4-4546-9008-fffcc6f1c9e1 /
└─center-swap swap d3d9c5ef-e552-4b1f-8107-8a3aad03d731 [SWAP]
sr0

 

我们需要扩展系统盘,可以看到系统/ 路径挂在/dev/sda2上,所以需要先对sda2重新进行分区,分区时务必注意起始的扇区位置和之前保持一致

[root@db2 tmpuser]# fdisk /dev/sda

WARNING: The size of this disk is 2.7 TB (2684354560000 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
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.
Command (m for help): p
Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00024d66
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 33554431 15727616 8e Linux LVM
Command (m for help): d
Partition number (1,2, default 2): 2
Partition 2 is deleted
Command (m for help): p
Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00024d66
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
Command (m for help): n
Partition type:
p primary (1 primary, 0 extended, 3 free)
e extended
Select (default p): p
Partition number (2-4, default 2):
First sector (2099200-4294967295, default 2099200):
Using default value 2099200
Last sector, +sectors or +size{K,M,G} (2099200-4294967294, default 4294967294): +85G
Partition 2 of type Linux and of size 85 GiB is set
Command (m for help): t
Partition number (1,2, default 2):
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): p
Disk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Disk identifier: 0x00024d66
**加粗样式**
Device Boot Start End Blocks Id System
/dev/sda1 * 2048 2099199 1048576 83 Linux
/dev/sda2 2099200 180357119 89128960 8e Linux LVM
Command (m for help): 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.

同步分区表,这里报错说旧的分区正在使用,我们应该重启再进行后续操作

[root@db2 tmpuser]# partprobe
Error: Partition(s) 2 on /dev/sda have been written, but we have been unable to inform the kernel of the change, probably because it/they are in use. As a result, the old partition(s) will remain in use. You should reboot now before making further changes.

[root@db2 tmpuser]# reboot

[root@db2 tmpuser]# partprobe ##同步分区表

如果没有报错说明分区表同步成功,接下来进行LVM扩容,pvs查看,pv的大小并没有发生变化,因此我们需要使用pvresize命令重置pv大小

[root@db2 tmpuser]# pvs

PV VG Fmt Attr PSize PFree
/dev/sda2 center lvm2 a-- <15.00g 0

[root@db2 tmpuser]# pvresize /dev/sda2

Physical volume "/dev/sda2" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized

[root@db2 tmpuser]# pvs ##此时pv大小已改变

PV VG Fmt Attr PSize PFree
/dev/sda2 center lvm2 a-- <85.00g 70.00g

##执行vg时报错,根据报错/dev/sda2已经在VG 逻辑卷组中,(分析:VG一旦创建,会自动管理/dev/sda2中的PE单元,即使扩缩容,自己的理解,懂得大神可以评论区说明下,谢谢)

[root@db2 tmpuser]# vgextend center /dev/sda2

Physical volume '/dev/sda2' is already in volume group 'center'
Unable to add physical volume '/dev/sda2' to volume group 'center'
/dev/sda2: physical volume not initialized.

既然已经存在,接下来直接进行LV扩展

[root@db2 tmpuser]# lvextend -l 100%FREE /dev/center/root ##扩展LV

Size of logical volume center/root changed from 13.39 GiB (3429 extents) to 70.00 GiB (17920 extents).
Logical volume center/root successfully resized.

扩展文件系统 如果是ext4格式用resize2fs /dev/mapper/center-root

[root@db2 tmpuser]# xfs_growfs /dev/mapper/center-root

meta-data=/dev/mapper/center-root isize=512 agcount=4, agsize=877824 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0 spinodes=0
data = bsize=4096 blocks=3511296, 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 3511296 to 18350080

查看挂载情况,已经扩容成功

[root@db2 tmpuser]# df -h

Filesystem Size Used Avail Use% Mounted on
/dev/mapper/center-root 70G 2.1G 68G 3% /
devtmpfs 16G 0 16G 0% /dev
tmpfs 16G 0 16G 0% /dev/shm
tmpfs 16G 8.5M 16G 1% /run
tmpfs 16G 0 16G 0% /sys/fs/cgroup
/dev/sda1 1014M 138M 877M 14% /boot
tmpfs 3.2G 0 3.2G 0% /run/user/1000

分享到 :
相关推荐

选择美国服务器租用有哪些考虑因素

选择美国服务器租用考虑的因素有:1。美国服务器的配置。根据业务需求进行选择;2。美国...

Krypt美国服务器好在哪(Krypt服务器)

Krypt是美国知名的服务器租用商之一。成立于1998年5月。在2000-2005年...

亚马逊印度站点好做吗(亚马逊在印度市场)

大家好,今天来介绍亚马逊印度站点好做吗(亚马逊印度站好做吗)的问题,以下是渲大师小编...

nginx启动不了怎么办(nginx启动不起来)

大家好,今天来介绍nginx启动不了怎么办(安装完nginx启动时启动失败如何解决)...

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注