扩容磁盘与恢复分区

839 字
4 分钟
扩容磁盘与恢复分区

1 直接挂载新磁盘#

Terminal window
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

查看分区

Terminal window
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 8:0 0 500G 0 disk
......
sdb 8:16 0 500G 0 disk
sdc 8:32 0 30G 0 disk
├─sdc1 8:33 0 512B 0 part
└─sdc2 8:34 0 30G 0 part

2 分区恢复#

2.1 删除分区#

Terminal window
fdisk /dev/sdc
Command (m for help): d # 删除分区
Partition number (1,2, default 2): 2 # 分区号
Command (m for help): w # 保存
[root@caiwc-tst-67 /]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sdc 8:32 0 30G 0 disk
└─sdc1 8:33 0 512B 0 part
sr0 11:0 1 2G 0 rom

2.2 恢复数据#

sudo yum install epel-release
sudo yum install testdisk
testdisk
>[ 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 # 回车
# 等扫描完,按p
Disk /dev/sdc - 32 GB / 30 GiB - CHS 30720 64 32
Analyse 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 62912512
Directory /
>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 quit
Directory /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 docker

3 在原有分区扩容#

Terminal window
# 查看磁盘信息
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 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
# 扩容到sda3
parted /dev/sda
GNU Parted 3.5
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) resizepart 3 100%
(parted) quit
Information: You may need to update /etc/fstab.
# 刷新分区信息
Physical volume "/dev/sda3" changed
1 physical volume(s) resized or updated / 0 physical volume(s) not resized
# 等一段时间再次查看
lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
sda 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

3.1 Lvm 扩容#

Terminal window
# 查看
vgs
VG #PV #LV #SN Attr VSize VFree
almalinux_registry-100 1 3 0 wz--n- <2.00t 1.51t
pvs
PV VG Fmt Attr PSize PFree
/dev/sda3 almalinux_registry-100 lvm2 a-- <2.00t 1.51t
lvs
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

文章分享

如果这篇文章对你有帮助,欢迎分享给更多人!

扩容磁盘与恢复分区
https://ccops.cc/posts/4f7d127a/
作者
蹦蹦站长
发布于
2023-03-10
许可协议
CC BY-NC-SA 4.0

评论区

Profile Image of the Author
蹦蹦站长
一个养兔子的运维
公告
感谢你的来访!希望在这里能找到对你有用的内容!
音乐
封面

音乐

暂未播放

0:00 0:00
暂无歌词
分类
标签
站点统计
文章
81
分类
6
标签
45
总字数
88,456
运行时长
0
最后活动
0 天前
站点信息
构建平台
Local
博客版本
Firefly v6.12.1
文章许可
CC BY-NC-SA 4.0

文章目录