news 2026/4/15 10:56:41

Ubuntu挂在新云盘(Disk磁盘)

作者头像

张小明

前端开发工程师

1.2k 24
文章封面图
Ubuntu挂在新云盘(Disk磁盘)

挂在新云盘

首先lsblk 查看磁盘是否已经存在,比如以下120G的新盘,不存在请重启后在尝试查看。

root@h-1587531148664508295:~# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTS
loop0 7:0 0 63.9M 1 loop /snap/core20/2318
loop1 7:1 0 63.8M 1 loop /snap/core20/2686
loop2 7:2 0 87M 1 loop /snap/lxd/28373
loop3 7:3 0 91.4M 1 loop /snap/lxd/36918
loop4 7:4 0 38.8M 1 loop /snap/snapd/21759
loop5 7:5 0 50.9M 1 loop /snap/snapd/25577
vda 252:0 0 20G 0 disk
├─vda1 252:1 0 19.9G 0 part /
├─vda14 252:14 0 4M 0 part
└─vda15 252:15 0 106M 0 part /boot/efi
vdb 252:16 0 120G 0 disk

然后使用 fdisk -l 命令查看磁盘文件信息
root@h-1587531148664508295:~# fdisk -l
Disk /dev/loop0: 63.95 MiB, 67051520 bytes, 130960 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 /dev/loop1: 63.77 MiB, 66871296 bytes, 130608 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 /dev/loop2: 87.03 MiB, 91258880 bytes, 178240 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 /dev/loop3: 91.4 MiB, 95842304 bytes, 187192 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 /dev/loop4: 38.83 MiB, 40714240 bytes, 79520 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 /dev/loop5: 50.93 MiB, 53399552 bytes, 104296 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 /dev/vda: 20 GiB, 21474836480 bytes, 41943040 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
Disklabel type: gpt
Disk identifier: 251CA31D-FA80-41E2-A9F9-4F45B5FAE58D

Device Start End Sectors Size Type
/dev/vda1 227328 41943006 41715679 19.9G Linux filesystem
/dev/vda14 2048 10239 8192 4M BIOS boot
/dev/vda15 10240 227327 217088 106M EFI System

Partition table entries are not in disk order.


Disk /dev/vdb: 120 GiB, 128849018880 bytes, 251658240 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


确定新盘(肯定是无分区,并且大容量的,这里就一个120Gib 满足条件,跟上面 lsblk 列出的没区别)
/dev/vdb


然后创建分区并格式化文件系统,Linux一般都是EXT4文件系统

# 创建分区(以 GPT 分区表为例)
sudo parted /dev/vdb mklabel gpt
sudo parted /dev/vdb mkpart primary ext4 0% 100%

# 格式化为 ext4 文件系统
sudo mkfs.ext4 /dev/vdb1

# 创建挂载目录并挂载
sudo mkdir -p /mnt/vdb1
sudo mount /dev/vdb1 /mnt/vdb1

查看新盘分区信息:
sudo parted /dev/vdb print

然后设置开机自动挂载:(获取分区的 UUID)
root@h-1587531148664508295:/mnt/vdb1# sudo blkid /dev/vdb1
、sudo: unable to resolve host h-1587531148664508295: Name or service not known
、/dev/vdb1: UUID="4cd0bccb-f6ab-4860-bc3e-2c6e4b8f2563" BLOCK_SIZE="4096" TYPE="ext4" PARTLABEL="primary" PARTUUID="8c921b12-0621-4027-b892-fb7599fe4dd4"

编辑 /etc/fstab
sudo nano /etc/fstab

添加以下行(使用 UUID 替代设备名):
UUID=4cd0bccb-f6ab-4860-bc3e-2c6e4b8f2563 /mnt/vdb1 ext4 defaults 0 2

测试配置
sudo mount -a # 无报错表示配置正确

设置目录权限
若需普通用户访问挂载点:
sudo chown -R ubuntu:ubuntu /mnt/vdb1 # 假设用户为 ubuntu
sudo chmod -R 755 /mnt/vdb1

可以通过以下命令查看是否已经挂载。
df -h

修复问题:
sudo: unable to resolve host h-1587531148664508295: Name or service not known

编辑 /etc/hosts文件
sudo nano /etc/hosts

添加以下行(将 h-1587531148664508295替换为实际主机名):
127.0.0.1 h-1587531148664508295

验证修复
ping $(hostname) # 应返回本地回环地址(127.0.0.1)

版权声明: 本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若内容造成侵权/违法违规/事实不符,请联系邮箱:809451989@qq.com进行投诉反馈,一经查实,立即删除!
网站建设 2026/4/8 12:15:34

从 ABP 到 CleanDDD:关于软件长期演进的一些思考

从 ABP 到 CleanDDD:关于软件长期演进的一些思考 最近在项目中接触到了 CleanDDD,也重新审视了我们长期使用的 ABP 技术栈。 这并不是一篇“反 ABP”的文章,而是一次站在时间维度上的技术反思。 如果你也在维护一个已经运行多年、并且还会继续…

作者头像 李华
网站建设 2026/4/8 11:53:03

为什么选择TensorFlow 2.9镜像进行大模型训练?

为什么选择TensorFlow 2.9镜像进行大模型训练? 在当前AI研发加速迈向工业化和规模化的背景下,一个稳定、高效且可复现的开发环境,往往比模型结构本身更能决定项目的成败。尤其是在大模型训练场景中,动辄数百GB显存占用、跨多卡甚至…

作者头像 李华
网站建设 2026/4/11 2:05:32

监控TensorFlow训练任务状态:Prometheus集成方案

监控TensorFlow训练任务状态:Prometheus集成方案 在现代深度学习项目中,一次模型训练可能持续数小时甚至数天。你有没有遇到过这样的场景:提交任务后只能干等结果,偶尔查看日志发现损失值早已不再下降,却无法第一时间察…

作者头像 李华
网站建设 2026/4/11 11:03:01

JAVA助力:同城羽毛球馆自助预约新方案

JAVA助力:同城羽毛球馆自助预约新方案一、方案背景与目标在全民健身热潮下,羽毛球作为一项广受欢迎的体育运动,其场馆预约需求日益增长。传统的人工预约方式存在效率低、信息不透明、管理成本高等问题。本方案旨在利用JAVA技术,打…

作者头像 李华
网站建设 2026/4/8 3:12:05

远程访问TensorFlow开发环境:SSH配置图文教程

远程访问TensorFlow开发环境:SSH配置实战指南 在深度学习项目中,你是否曾遇到这样的场景?本地笔记本跑不动模型,训练一次要十几个小时;团队成员之间因为环境版本不一致导致代码“在我机器上能跑”;或者你想…

作者头像 李华