您当前所在位置:首页安装教程Linux系统盘是怎样扩容的

Linux系统盘是怎样扩容的

更新:2023-08-09 15:18:37编辑:tooool归类:安装教程人气:94

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

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% /devtmpfs 16G 0 16G 0% /dev/shmtmpfs 16G 8.5M 16G 1% /runtmpfs 16G 0 16G 0% /sys/fs/cgroup/dev/sda1 1014M 138M 877M 14% /boottmpfs 3.2G 0 3.2G 0% /run/user/1000

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

[root@db2 tmpuser] lsblk -f

NAME FSTYPE LABEL UUID MOUNTPOINTsda├─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 volumeslarger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUIDpartition 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): pDisk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00024d66Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 33554431 15727616 8e Linux LVMCommand (m for help): dPartition number (1,2, default 2): 2Partition 2 is deletedCommand (m for help): pDisk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00024d66Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 LinuxCommand (m for help): nPartition type:p primary (1 primary, 0 extended, 3 free)e extendedSelect (default p): pPartition number (2-4, default 2):First sector (2099200-4294967295, default 2099200):Using default value 2099200Last sector, +sectors or +size{K,M,G} (2099200-4294967294, default 4294967294): +85GPartition 2 of type Linux and of size 85 GiB is setCommand (m for help): tPartition number (1,2, default 2):Hex code (type L to list all codes): 8eChanged type of partition Linux to Linux LVMCommand (m for help): pDisk /dev/sda: 2684.4 GB, 2684354560000 bytes, 5242880000 sectorsUnits = sectors of 1 * 512 = 512 bytesSector size (logical/physical): 512 bytes / 512 bytesI/O size (minimum/optimal): 512 bytes / 512 bytesDisk label type: dosDisk identifier: 0x00024d66**加粗样式**Device Boot Start End Blocks Id System/dev/sda1 * 2048 2099199 1048576 83 Linux/dev/sda2 2099200 180357119 89128960 8e Linux LVMCommand (m for help): wThe 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 atthe next reboot or after you run partprobe(8) or kpartx(8)Syncing disks.

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

[root@db2 tmpuser] partprobeError: 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" changed1 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 centerUnable 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=0data = bsize=4096 blocks=3511296, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0data 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% /devtmpfs 16G 0 16G 0% /dev/shmtmpfs 16G 8.5M 16G 1% /runtmpfs 16G 0 16G 0% /sys/fs/cgroup/dev/sda1 1014M 138M 877M 14% /boottmpfs 3.2G 0 3.2G 0% /run/user/1000

图片来自另一片文章

也可以直接查看https://blog.csdn.net/rockstics/article/details/120785485 另一个操作全过程,操作步骤雷同

我告诉你msdn版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

Win10年度更新预览版14352有哪些已知问题 双系统的MacBook苹果笔记本电脑-Mac与Windows

游客 回复需填写必要信息