扩容磁盘与恢复分区
839 字
4 分钟
扩容磁盘与恢复分区
1 直接挂载新磁盘
fdisk /dev/sdc
Command (m for help): n 创建新分区
Select (default p): p # 创建主分区
Partition number (2-4, default 2): 2 # 分区编号First sector (2048-62914558, default 2048): # 第一个扇区Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62914558, default 62914558): #最后一个扇区
Command (m for help): w # 保存
mkfs -t ext4 /dev/sdX1查看分区
lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 500G 0 disk......sdb 8:16 0 500G 0 disksdc 8:32 0 30G 0 disk├─sdc1 8:33 0 512B 0 part└─sdc2 8:34 0 30G 0 part2 分区恢复
2.1 删除分区
fdisk /dev/sdc
Command (m for help): d # 删除分区Partition number (1,2, default 2): 2 # 分区号
Command (m for help): w # 保存
[root@caiwc-tst-67 /]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsdc 8:32 0 30G 0 disk└─sdc1 8:33 0 512B 0 partsr0 11:0 1 2G 0 rom2.2 恢复数据
sudo yum install epel-releasesudo yum install testdisktestdisk
>[ Create ] Create a new log file
>Disk /dev/sdc - 32 GB / 30 GiB - Virtual disk
>[Intel ] Intel/PC partition
>[ Analyse ] Analyse current partition structure and search for lost partitions
[Quick Search] # 回车
>* Linux 1 0 1 30719 63 32 62912512 # 回车
1 * Linux 1 0 1 30719 63 32 62912512 # 回车
# 等扫描完,按pDisk /dev/sdc - 32 GB / 30 GiB - CHS 30720 64 32Analyse cylinder 10256/30719: 33% Linux 1 0 1 30719 63 24 62912504 Linux 1 0 1 30719 63 24 62912504 Linux 1 0 1 30719 63 24 62912504 Linux 1 0 1 30719 63 24 62912504 Linux 1 0 1 30719 63 24 62912504 Linux 1 0 1 30719 63 24 62912504
# 选择要恢复的文件,按c复制 * Linux 1 0 1 30719 63 32 62912512Directory />drwxr-xr-x 0 0 4096 22-May-2025 10:50 . drwxr-xr-x 0 0 4096 22-May-2025 10:50 .. drwx------ 0 0 16384 22-May-2025 10:45 lost+found drwxr-xr-x 0 0 4096 22-May-2025 10:50 nginx_logs drwxr-xr-x 0 0 4096 22-May-2025 10:50 redis drwxr-xr-x 0 0 4096 22-May-2025 10:50 rocketmq drwxr-xr-x 0 0 4096 22-May-2025 10:50 velero-minio drwxr-xr-x 0 0 4096 22-May-2025 10:50 victoria
# 选择要恢复的目录,按回车确定# 选择要恢复的目录,按回车确定Please select a destination where / and any files below will be copied.Keys: Arrow keys to select another directory C when the destination is correct Q to quitDirectory /data>drwxr-xr-x 0 0 49 3-Apr-2025 10:02 . dr-xr-xr-x 0 0 4096 22-May-2025 10:59 .. drwx--x--- 0 0 171 22-May-2025 11:09 docker3 在原有分区扩容
# 查看磁盘信息lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 2T 0 disk├─sda1 8:1 0 600M 0 part /boot/efi├─sda2 8:2 0 1G 0 part /boot└─sda3 8:3 0 2T 0 part ├─almalinux_registry--100-root 253:0 0 120G 0 lvm / ├─almalinux_registry--100-home 253:1 0 20G 0 lvm /home └─almalinux_registry--100-data 253:2 0 358.4G 0 lvm /data
# 扩容到sda3parted /dev/sdaGNU Parted 3.5Using /dev/sdaWelcome to GNU Parted! Type 'help' to view a list of commands.(parted) resizepart 3 100%(parted) quitInformation: You may need to update /etc/fstab.
# 刷新分区信息Physical volume "/dev/sda3" changed1 physical volume(s) resized or updated / 0 physical volume(s) not resized
# 等一段时间再次查看lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTSsda 8:0 0 2T 0 disk├─sda1 8:1 0 600M 0 part /boot/efi├─sda2 8:2 0 1G 0 part /boot└─sda3 8:3 0 2T 0 part ├─almalinux_registry--100-root 253:0 0 120G 0 lvm / ├─almalinux_registry--100-home 253:1 0 20G 0 lvm /home └─almalinux_registry--100-data 253:2 0 358.4G 0 lvm /data3.1 Lvm 扩容
# 查看vgs VG #PV #LV #SN Attr VSize VFree almalinux_registry-100 1 3 0 wz--n- <2.00t 1.51tpvs PV VG Fmt Attr PSize PFree /dev/sda3 almalinux_registry-100 lvm2 a-- <2.00t 1.51tlvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert data almalinux_registry-100 -wi-ao---- <358.41g home almalinux_registry-100 -wi-ao---- 20.00g root almalinux_registry-100 -wi-ao---- 120.00g
# 扩展物理卷pvresize /dev/sda3# 扩容逻辑卷# lvextend -L +50G /dev/almalinux_registry-100/data # 指定扩展量lvextend -l +100%FREE /dev/almalinux_registry-100/data # 使用全部剩余空间
# 扩展文件系统#resize2fs /dev/almalinux_registry--100/data # 适用于ext4文件系统xfs_growfs /data # 适用于xfs文件系统
# 查看lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert data almalinux_registry-100 -wi-ao---- 1.86t home almalinux_registry-100 -wi-ao---- 20.00g root almalinux_registry-100 -wi-ao---- 120.00g文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!
相关文章 智能推荐
1
OpenClaw安装
💻Linux 龙虾安装笔记
2
CrowdSec 安全预防
💻Linux CrowdSec 安全预防
3
atop 使用
💻Linux 运维工作中经常遇到节点 oom ,但是重启后找不到那个进程导致资源占用满了,可以使用 atop 查看
4
HAProxy+Keepalived使用
💻Linux HAProxy+Keepalived使用,里面包含了日志收集,监控与报警
5
Nginx 调优
💻Linux Nginx 配置与优化
随机文章 随机推荐