一键优雅为Ubuntu20.04服务器挂载新磁盘

itopen组织
1、提供OpenHarmony优雅实用的小工具
2、手把手适配riscv + qemu + linux的三方库移植
3、未来计划riscv + qemu + ohos的三方库移植 + 小程序开发
4、一切拥抱开源,拥抱国产化

一、小于2T磁盘挂载方式

1.1 安装磁盘到电脑后启动系统

1.2 查找未分区的磁盘

  • 打开终端输入sudo fdisk -l查找到没有分区的磁盘
  • 已经分区的磁盘会有对应的Device Start End Sectors Size Type信息,而未分区的磁盘没有对应的信息,通过查看当前/dev/nvme0n1是新增加的未分区磁盘
$ sudo fdisk -l
[sudo] password for wen_fei:
Disk /dev/nvme0n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors # 未分区的磁盘
Disk model: Samsung SSD 980 PRO 2TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/nvme1n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors # 已分区的磁盘
Disk model: Samsung SSD 980 PRO 2TB
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: 6F0C9477-25AA-45D6-A027-C7186A2C5918Device             Start        End    Sectors  Size Type
/dev/nvme1n1p1      2048    5859327    5857280  2.8G EFI System
/dev/nvme1n1p2   5859328  162109439  156250112 74.5G Linux filesystem
/dev/nvme1n1p3 162109440  220702719   58593280   28G Linux filesystem
/dev/nvme1n1p4 220702720  298827775   78125056 37.3G Linux filesystem
/dev/nvme1n1p5 298827776  376952831   78125056 37.3G Linux filesystem
/dev/nvme1n1p6 376952832  416014335   39061504 18.6G Linux filesystem
/dev/nvme1n1p7 416014336 3907028991 3491014656  1.6T Linux filesystemDisk /dev/nvme2n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors # 已分区的磁盘
Disk model: Samsung SSD 980 PRO 2TB
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: B6155B74-845D-4234-B637-4308B3F0C56DDevice         Start        End    Sectors  Size Type
/dev/nvme2n1p1  2048 3907028991 3907026944  1.8T Linux filesystem

1.3 磁盘分区

  • 对未分区的磁盘执行命令sudo fdisk /dev/xxx
  • 根据提示输入m查看指令信息
  • 根据提示输入n开始创建分区
  • 根据提示输入p表示创建主分区,或者输入区e表示创建逻辑分区:一块硬盘最多只能创建4个主分区,逻辑分区可以创建若干个
  • 根据提示输入x表示创建x个分区说明: 我们挂载磁盘一般只创建一个分区即可,直接输入1即可
  • 根据提示直接回车设置分区开始位置是从第2048个扇区开始: 由于EFI的兴起,要给EFI代码留磁盘最开始的1M空间,即2048521/(10241024)=1M,因此分区默认第2048个扇区开始
  • 根据提示直接回车设置分区结束位置为磁盘末尾
  • 根据提示输入w保存分区设置
$ sudo fdisk /dev/nvme0n1Welcome to fdisk (util-linux 2.34).
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.
Created a new DOS disklabel with disk identifier 0x20e2fdf1.Command (m for help): mHelp:DOS (MBR)a   toggle a bootable flagb   edit nested BSD disklabelc   toggle the dos compatibility flagGenericd   delete a partitionF   list free unpartitioned spacel   list known partition typesn   add a new partitionp   print the partition tablet   change a partition typev   verify the partition tablei   print information about a partitionMiscm   print this menuu   change display/entry unitsx   extra functionality (experts only)ScriptI   load disk layout from sfdisk script fileO   dump disk layout to sfdisk script fileSave & Exitw   write table to disk and exitq   quit without saving changesCreate a new labelg   create a new empty GPT partition tableG   create a new empty SGI (IRIX) partition tableo   create a new empty DOS partition tables   create a new empty Sun partition tableCommand (m for help): n
Partition typep   primary (0 primary, 0 extended, 4 free)e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-3907029167, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-3907029167, default 3907029167):Created a new partition 1 of type 'Linux' and of size 1.8 TiB.Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

1.4 格式化分区

  • 输入命令sudo mkfs -t ext4 /dev/xxx进行格式化磁盘
  • 记住生成磁盘的UUID为挂载磁盘使用
$ sudo mkfs -t ext4 /dev/nvme0n1
mke2fs 1.45.5 (07-Jan-2020)
Found a dos partition table in /dev/nvme0n1
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 488378646 4k blocks and 122101760 inodes
Filesystem UUID: 330fdef4-df72-47ab-afa0-0ff08ae4999f
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

1.5 设置开机自动挂载

  • 打开文件/etc/fstab添加新分区挂载到/data目录
$ sudo vim /etc/fstab
# /datb was on /dev/nvme3n1p1 during installation
UUID=330fdef4-df72-47ab-afa0-0ff08ae4999f /data           ext4    defaults        0       2

1.6 重启系统

  • 系统重启后查看已经有目录/data表示挂载新磁盘成功

    1.7 删除分区

  • 卸载分区:使用sudo umount xxx

  • 对已分区的磁盘执行命令sudo fdisk /dev/xxx

  • 根据提示输入m查看指令信息

  • 根据提示输入d开始删除最后一个分区,如果想删除更多的分区,则不停的输入d即可

  • 根据提示输入p表示打印分区表

  • 根据提示输入w表示保存分区设置

  • 删除/etc/fstab中原UUID挂载的磁盘

$ sudo fdisk /dev/nvme0n1Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.Command (m for help): mHelp:DOS (MBR)a   toggle a bootable flagb   edit nested BSD disklabelc   toggle the dos compatibility flagGenericd   delete a partitionF   list free unpartitioned spacel   list known partition typesn   add a new partitionp   print the partition tablet   change a partition typev   verify the partition tablei   print information about a partitionMiscm   print this menuu   change display/entry unitsx   extra functionality (experts only)ScriptI   load disk layout from sfdisk script fileO   dump disk layout to sfdisk script fileSave & Exitw   write table to disk and exitq   quit without saving changesCreate a new labelg   create a new empty GPT partition tableG   create a new empty SGI (IRIX) partition tableo   create a new empty DOS partition tables   create a new empty Sun partition tableCommand (m for help): d
Selected partition 1
Partition 1 has been deleted.Command (m for help): p
Disk /dev/nvme0n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors
Disk model: Samsung SSD 980 PRO 2TB
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: dos
Disk identifier: 0xcd706ecbCommand (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

二、大于2T磁盘挂载方式

2.1 安装磁盘到电脑后启动系统

2.2 查找未分区的磁盘

  • 打开终端输入sudo fdisk -l查找到没有分区的磁盘
  • 已经分区的磁盘会有对应的Device Start End Sectors Size Type信息,而未分区的磁盘没有对应的信息,通过查看当前/dev/nvme0n1是新增加的未分区磁盘
$ sudo fdisk -l
[sudo] password for wen_fei:
Disk /dev/nvme0n1: 3.74 TiB, 4096805658624 bytes, 8001573552 sectors
Disk model: Lexar SSD ARES 4TB
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytesDisk /dev/nvme1n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors # 已分区的磁盘
Disk model: Samsung SSD 980 PRO 2TB
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: 6F0C9477-25AA-45D6-A027-C7186A2C5918Device             Start        End    Sectors  Size Type
/dev/nvme1n1p1      2048    5859327    5857280  2.8G EFI System
/dev/nvme1n1p2   5859328  162109439  156250112 74.5G Linux filesystem
/dev/nvme1n1p3 162109440  220702719   58593280   28G Linux filesystem
/dev/nvme1n1p4 220702720  298827775   78125056 37.3G Linux filesystem
/dev/nvme1n1p5 298827776  376952831   78125056 37.3G Linux filesystem
/dev/nvme1n1p6 376952832  416014335   39061504 18.6G Linux filesystem
/dev/nvme1n1p7 416014336 3907028991 3491014656  1.6T Linux filesystemDisk /dev/nvme2n1: 1.84 TiB, 2000398934016 bytes, 3907029168 sectors # 已分区的磁盘
Disk model: Samsung SSD 980 PRO 2TB
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: B6155B74-845D-4234-B637-4308B3F0C56DDevice         Start        End    Sectors  Size Type
/dev/nvme2n1p1  2048 3907028991 3907026944  1.8T Linux filesystem

2.3 磁盘分区

  • 对未分区的磁盘执行命令sudo parted /dev/xxx
  • 根据提示输入mklabel gpt建立GPT分区
  • 根据提示输入Yes开始创建分区
  • 根据提示输入mkpart primary ext4 0% 100%创建主分区
  • 根据提示输入print查看详细信息
  • 根据提示输入quit退出
$ sudo parted /dev/nvme0n1
GNU Parted 3.3
Using /dev/nvme0n1
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) mklabel gpt
Warning: The existing disk label on /dev/nvme0n1 will be destroyed and all data on this disk will be lost. Do you want to
continue?
Yes/No? Yes
(parted) mkpart primary ext4 0% 100%
(parted) print
Model: Lexar SSD ARES 4TB (nvme)
Disk /dev/nvme0n1: 4097GB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:Number  Start   End     Size    File system  Name     Flags1      1049kB  4097GB  4097GB  ext4         primary(parted) quit
Information: You may need to update /etc/fstab.

2.4 格式化分区

  • 输入命令sudo mkfs -t ext4 /dev/xxx进行格式化磁盘
  • 记住生成磁盘的UUID为挂载磁盘使用
$ sudo mkfs -t ext4 /dev/nvme0n1
mke2fs 1.45.5 (07-Jan-2020)
/dev/nvme0n1 contains a ext4 file systemcreated on Wed Jul  3 17:44:09 2024
Proceed anyway? (y,N) y
Discarding device blocks: done
Creating filesystem with 1000196694 4k blocks and 250052608 inodes
Filesystem UUID: 7918bc9f-458c-442f-b586-53fa657b4ad2
Superblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,102400000, 214990848, 512000000, 550731776, 644972544Allocating group tables: done
Writing inode tables: done
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done

2.5 设置开机自动挂载

  • 打开文件/etc/fstab添加新分区挂载到/data目录
$ sudo vim /etc/fstab
# /datb was on /dev/nvme3n1p1 during installation
UUID=7918bc9f-458c-442f-b586-53fa657b4ad2 /data           ext4    defaults        0       2

2.6 重启系统

  • 系统重启后查看已经有目录/data表示挂载新磁盘成功

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/web/44001.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

ios swift5 蓝牙广播出数据

WARNING: The advertisement key ‘Manufacturer Data’ is not allowed WARNING: The advertisement key ‘Service Data’ is not allowed manager?.startAdvertising([CBAdvertisementDataServiceUUIDsKey : [myService?.uuid], CBAdvertisementDataLocalNameKey : "…

鸿蒙Navigation的页面跳转官方代码

星河版本 文章部分代码来源于官方 文章部分代码来源于官方只是自己改了容易理解 与API4不同的Navigation 新版本使用的思路是 1、创建页面栈 pageInfos: NavPathStack new NavPathStack();2、resources/base/profile创建 router_map.json 文件 {"routerMap":…

数电设计提问求帮助,出租车计费器。

🏆本文收录于《CSDN问答解惑-》专栏,主要记录项目实战过程中的Bug之前因后果及提供真实有效的解决方案,希望能够助你一臂之力,帮你早日登顶实现财富自由🚀;同时,欢迎大家关注&&收藏&…

Autosar诊断实战系列28-2E写DID Pending期间偶发回NRC0x13问题排查

本文框架 前言1.问题描述2.问题复现3.问题分析问题1:为何在2E Pending期间会发送功能寻址的10 01回NRC13?问题2:在ECU Pending期间收到功能寻址10 01,MCU需要如何处理?问题3:DcmDslConnection是如何定义的?问题4:功能寻址于物理寻址是否对应不同的DcmDslConnection?问…

Pandas数据可视化宝典:解锁图形绘制与样式自定义的奥秘

Pandas数据可视化宝典:解锁图形绘制与样式自定义的奥秘 引言 数据可视化是将数据以图形或图像的形式展示出来,使复杂的数据更容易被人类理解和分析。在数据分析、商业智能、科学研究等领域,数据可视化都扮演着至关重要的角色。Pandas作为一…

如何通过 Java 来完成 zip 文件与 rar 文件的解压缩?

目录 一、用到的知识点 二、代码展示(分解版) 三、代码展示(整体版) 一、用到的知识点 1.IO流: Input:输入,通过“输入流”进行文件的读取操作 Output:输出,通过“输出流”进行文件的写入操作 2.文件操作相关: File类&#xff…

Point Cloud Library (PCL) for Python - pclpy 安装指南 (2)

Point Cloud Library (PCL) for Python - pclpy 安装指南 (1) 导入库 from pclpy import pcl import numpy as np导入pclpy库中的pcl模块,用于处理点云数据。numpy库用于处理数值数据。 读取点云 cloud pcl.PointCloud.PointXYZRGB() pcl.io.loadPCDFile(F:\\bunn…

2024年西安铁一中集训DAY1---- 杂题选讲

文章目录 牛客练习赛125 E 联谊活动(枚举,分讨)牛客练习赛125 F 玻璃弹珠(类莫队,离线询问,数据结构)2024ccpc长春邀请赛 D Parallel Lines(随机化)2024ccpc长春邀请赛 E…

STM32智能健康监测系统教程

目录 引言环境准备智能健康监测系统基础代码实现:实现智能健康监测系统 4.1 数据采集模块 4.2 数据处理与分析模块 4.3 通信与网络系统实现 4.4 用户界面与数据可视化应用场景:健康监测与优化问题解决方案与优化收尾与总结 1. 引言 智能健康监测系统通…

k8s 容器环境下的镜像如何转换为docker 使用

在无法连接registry 的环境中,想要把 crictl 中的镜像给docker 使用,应该怎么处理? 其实容器镜像是通用的,crictl 和ctr 以及docker 镜像是可以互相使用的,因为docker 在1.10版本之后遵从了OCI。所以crictl 环境下的镜…

Android Studio 的Gradle下载慢,Gradle切换下载源

看图 下面的文字地址因为转义符号的问题,https后面少了一个斜杠看图片进行补充,直接复制不知道能不能用 distributionUrlhttps://mirrors.cloud.tencent.com/gradle/gradle-8.7-bin.zip

浪潮服务器内存物理插槽位置

浪潮服务器内存物理插槽位置 如下图所示

Doze和AppStandby白名单配置方法和说明

机制 配置路径 配置案例 说明 影响机制 调试命令 Doze /platform/frameworks/base /data/etc/platform.xml allow-in-power-save 【系统应用Doze白名单配置】 Doze\Job\AppStandby\Alarm\WakeLock\Sync 查看Doze白名单:adb shell dumpsys deviceidle 添加Doze白名单…

漏洞挖掘之信息搜集(一)

本篇文章只从信息搜集的步骤整理 一、选好你要挖掘的src 这一点一定要明确,定好一个,然后下定决心一定要挖到一个高危 常见src总结: 360众测(需要考核) 漏洞盒子(还可以,审核很慢)----基本无要求 补天:有钱,但要求高,百度收录占比权重大于等于1或者或者谷歌权…

前端进阶全栈计划:Java基础语法

前言 本教程旨在帮助初学者系统地掌握Java的基础知识。我们将从Java的基本语法开始,逐步深入到面向对象编程、异常处理、多线程编程等核心概念。无论你是编程新手,还是希望夯实基础的开发者,这份指南都将带你走进Java的世界,打下坚…

昇思MindSpore学习笔记6-06计算机视觉--Vision Transormer图像分类

摘要: 记录MindSpore AI框架使用ViT模型在ImageNet图像数据分类上进行训练、验证、推理的过程和方法。包括环境准备、下载数据集、数据集加载、模型解析与构建、模型训练与推理等。 一、概念 1. ViT模型 Vision Transformer 自注意结构模型 Self-Attention Tran…

MySQL(基础篇)

DDL (Data Definition Language) 数据定义语言,用来定义数据库对象(数据库,表, 字段) DML (Data Manipulation Languag) 数据操作语言,用来对数据库表中的数据进行增删改 DQL (Data Query Language) 数据查询语言,用…

前缀,中缀,后缀表达式

前缀表达式 前缀表达式(也称为波兰式)是一种将运算符放在操作数之前的表示数学表达式的方法。在前缀表达式中,操作符出现在它们所操作的操作数之前。 例如,将中缀表达式5 3转换为前缀表达式,可以写成 5 3。在这个例…

9 个让 Python 性能更高的小技巧,你掌握了吗?

我们经常听到 “Python 太慢了”,“Python 性能不行”这样的观点。但是,只要掌握一些编程技巧,就能大幅提升 Python 的运行速度。 今天就让我们一起来看下让 Python 性能更高的 9 个小技巧 python学习资料分享(无偿)…

数据(图像)增广

一、数据增强 1、增加一个已有数据集,使得有更多的多样性,比如加入不同的背景噪音、改变图片的颜色和形状。 2、增强数据是在线生成的 3、增强类型: (1)翻转 (2)切割 (3&#xf…