如何扩展Linux系统分区大小

简介: 如何扩展Linux系统分区大小

1.分区大小


[root@rhel76 ~]# df -Th
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        30G  4.3G   26G  15% /
devtmpfs              devtmpfs  2.0G     0  2.0G   0% /dev
tmpfs                 tmpfs     2.0G     0  2.0G   0% /dev/shm
tmpfs                 tmpfs     2.0G   13M  2.0G   1% /run
tmpfs                 tmpfs     2.0G     0  2.0G   0% /sys/fs/cgroup
/dev/sda1             xfs       950M  164M  786M  18% /boot
/dev/mapper/rhel-u01  xfs        28G   33M   28G   1% /u01
tmpfs                 tmpfs     394M  4.0K  394M   1% /run/user/42
tmpfs                 tmpfs     394M   48K  394M   1% /run/user/0
可以看出/分区已经明明显不足,需要扩展

51bc1595791e49b0b4bb505bd2d2802e.png


2.裸盘划分


[root@rhel76 ~]# ll /dev/sd*
brw-rw----. 1 root disk 8,  0 Nov 28 23:34 /dev/sda
brw-rw----. 1 root disk 8,  1 Nov 28 23:34 /dev/sda1
brw-rw----. 1 root disk 8,  2 Nov 28 23:34 /dev/sda2
brw-rw----. 1 root disk 8, 16 Nov 28 23:34 /dev/sdb

80ded2dfff7c40acae1e3d9924a46ab1.png

[root@rhel76 ~]# fdisk /dev/sdb
[root@rhel76 ~]# fdisk /dev/sdb
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.
Device does not contain a recognized partition table
Building a new DOS disklabel with disk identifier 0xa1773dc6.
Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): 
Using default response p
Partition number (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): 
Using default value 41943039
Partition 1 of type Linux and of size 20 GiB is set
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
[root@rhel76 ~]# ll /dev/sd*
brw-rw----. 1 root disk 8,  0 Nov 28 23:34 /dev/sda
brw-rw----. 1 root disk 8,  1 Nov 28 23:34 /dev/sda1
brw-rw----. 1 root disk 8,  2 Nov 28 23:34 /dev/sda2
brw-rw----. 1 root disk 8, 16 Nov 28 23:49 /dev/sdb
brw-rw----. 1 root disk 8, 17 Nov 28 23:49 /dev/sdb1
[root@rhel76 ~]# fdisk -l | grep dev
Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
/dev/sdb1            2048    41943039    20970496   83  Linux
Disk /dev/sda: 64.4 GB, 64424509440 bytes, 125829120 sectors
/dev/sda1   *        2048     1953791      975872   83  Linux
/dev/sda2         1953792   125829119    61937664   8e  Linux LVM
Disk /dev/mapper/rhel-root: 31.4 GB, 31415336960 bytes, 61358080 sectors
Disk /dev/mapper/rhel-swap: 2000 MB, 2000683008 bytes, 3907584 sectors
Disk /dev/mapper/rhel-u01: 30.0 GB, 30001856512 bytes, 58597376 sectors

f118f9e31b3a4ec1a91bedce92bc7041.png


3.创建 PV


[root@rhel76 ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree
  /dev/sda2  rhel lvm2 a--  <59.07g 4.00m
[root@rhel76 ~]# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.
[root@rhel76 ~]# pvs
  PV         VG   Fmt  Attr PSize   PFree  
  /dev/sda2  rhel lvm2 a--  <59.07g   4.00m
  /dev/sdb1       lvm2 ---  <20.00g <20.00g


4.扩展逻辑卷


[root@rhel76 ~]# vgs
  VG   #PV #LV #SN Attr   VSize   VFree
  rhel   1   3   0 wz--n- <59.07g 4.00m
[root@rhel76 ~]# vgextend rhel /dev/sdb1
[root@rhel76 ~]# vgextend rhel /dev/sdb1
  Volume group "rhel" successfully extended
[root@rhel76 ~]# vgs
  VG   #PV #LV #SN Attr   VSize  VFree 
  rhel   2   3   0 wz--n- 79.06g 20.00g
[root@rhel76 ~]# vgs
  VG     #PV #LV #SN Attr   VSize   VFree  
  jem_vg   1   0   0 wz--n- <20.00g <20.00g
  rhel     1   3   0 wz--n- <59.07g   4.00m
[root@rhel76 ~]# lvdisplay
 --- Logical volume ---
  LV Path                /dev/rhel/root
  LV Name                root
  VG Name                rhel
  LV UUID                fB06rl-92CE-trM6-e2tM-pP4o-6SKt-p03lGC
  LV Write Access        read/write
  LV Creation host, time rhel76, 2021-06-26 22:04:57 +0000
  LV Status              available
  # open                 1
  LV Size                <29.26 GiB
  Current LE             7490
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     8192
  Block device           253:0
[root@rhel76 ~]# lvs
  LV   VG   Attr       LSize   Pool Origin Data%  Meta%  Move Log Cpy%Sync Convert
  root rhel -wi-ao---- <29.26g                                                    
  swap rhel -wi-ao----   1.86g                                                    
  u01  rhel -wi-ao----  27.94g     
[root@rhel76 ~]# lvextend -L +18G /dev/rhel/root
  Size of logical volume rhel/root changed from <29.26 GiB (7490 extents) to <47.26 GiB (12098 extents).
  Logical volume rhel/root successfully resized.
使用以下命令刷新lv
[root@rhel76 ~]# xfs_growfs /dev/rhel/root
meta-data=/dev/mapper/rhel-root  isize=512    agcount=4, agsize=1917440 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=7669760, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=3745, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 7669760 to 12388352


5.再次确认分区大小


[root@rhel76 ~]# df -TH
Filesystem            Type      Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root xfs        51G  4.4G   47G   9% /
devtmpfs              devtmpfs  2.1G     0  2.1G   0% /dev
tmpfs                 tmpfs     2.1G     0  2.1G   0% /dev/shm
tmpfs                 tmpfs     2.1G   14M  2.1G   1% /run
tmpfs                 tmpfs     2.1G     0  2.1G   0% /sys/fs/cgroup
/dev/sda1             xfs       996M  172M  825M  18% /boot
/dev/mapper/rhel-u01  xfs        30G   34M   30G   1% /u01
tmpfs                 tmpfs     413M  4.1k  413M   1% /run/user/42
tmpfs                 tmpfs     413M   54k  413M   1% /run/user/0

90e25792776d4f0692fb2d68ea2db433.png


很明显,/ 分区由原来的30G扩展到了51G


如果觉得文章对你有帮助,点赞、收藏、关注、评论,一键四连支持

您的批评指正是我写作的最大动力!

目录
相关文章
|
1月前
|
Ubuntu Linux Anolis
Linux系统禁用swap
本文介绍了在新版本Linux系统(如Ubuntu 20.04+、CentOS Stream、openEuler等)中禁用swap的两种方法。传统通过注释/etc/fstab中swap行的方式已失效,现需使用systemd管理swap.target服务或在/etc/fstab中添加noauto参数实现禁用。方法1通过屏蔽swap.target适用于新版系统,方法2通过修改fstab挂载选项更通用,兼容所有系统。
141 3
Linux系统禁用swap
|
1月前
|
Linux
Linux系统修改网卡名为eth0、eth1
在Linux系统中,可通过修改GRUB配置和创建Udev规则或使用systemd链接文件,将网卡名改为`eth0`、`eth1`等传统命名方式,适用于多种发行版并支持多网卡配置。
187 3
|
2月前
|
Ubuntu Linux
计算机基础知识:linux系统怎么安装?
在虚拟机软件中创建一个新的虚拟机,并选择相应操作系统类型和硬盘空间大小等参数。将下载的 ISO 镜像文件加载到虚拟机中。启动虚拟机,进入安装界面,并按照步骤进行安装。安装完成后,可以在虚拟机中使用 Linux 系统。
|
2月前
|
存储 Ubuntu Linux
「正点原子Linux连载」第二章Ubuntu系统入门
在图2.8.2.4中,我们使用命令umount卸载了U盘,卸载以后当我们再去访问文件夹/mnt/tmp的时候发现里面没有任何文件了,说明我们卸载成功了。
|
Ubuntu Linux 网络安全
Linux系统初始化脚本
一款支持Rocky、CentOS、Ubuntu、Debian、openEuler等主流Linux发行版的系统初始化Shell脚本,涵盖网络配置、主机名设置、镜像源更换、安全加固等多项功能,适配单/双网卡环境,支持UEFI引导,提供多版本下载与持续更新。
163 0
Linux系统初始化脚本
|
2月前
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
155 18
|
1月前
|
安全 Linux Shell
Linux系统提权方式全面总结:从基础到高级攻防技术
本文全面总结Linux系统提权技术,涵盖权限体系、配置错误、漏洞利用、密码攻击等方法,帮助安全研究人员掌握攻防技术,提升系统防护能力。
154 1
|
1月前
|
监控 安全 Linux
Linux系统提权之计划任务(Cron Jobs)提权
在Linux系统中,计划任务(Cron Jobs)常用于定时执行脚本或命令。若配置不当,攻击者可利用其提权至root权限。常见漏洞包括可写的Cron脚本、目录、通配符注入及PATH变量劫持。攻击者通过修改脚本、创建恶意任务或注入命令实现提权。系统管理员应遵循最小权限原则、使用绝对路径、避免通配符、设置安全PATH并定期审计,以防范此类攻击。
621 1
|
2月前
|
缓存 监控 Linux
Linux系统清理缓存(buff/cache)的有效方法。
总结而言,在大多数情形下你不必担心Linux中buffer与cache占用过多内存在影响到其他程序运行;因为当程序请求更多内存在没有足够可用资源时,Linux会自行调整其占有量。只有当你明确知道当前环境与需求并希望立即回收这部分资源给即将运行重负载任务之前才考虑上述方法去主动干预。
1011 10
|
2月前
|
安全 Linux 数据安全/隐私保护
为Linux系统的普通账户授予sudo访问权限的过程
完成上述步骤后,你提升的用户就能够使用 `sudo`命令来执行管理员级别的操作,而无需切换到root用户。这是一种更加安全和便捷的权限管理方式,因为它能够留下完整的权限使用记录,并以最小权限的方式工作。需要注意的是,随意授予sudo权限可能会使系统暴露在风险之中,尤其是在用户不了解其所执行命令可能带来的后果的情况下。所以在配置sudo权限时,必须谨慎行事。
405 0