ubuntu 永久 磁盘挂载

在Ubuntu中,如果你想要将一个磁盘分区(如sda1)永久挂载到一个特定的目录,并且在 /etc/fstab 文件中添加条目以确保开机自动挂载,你可以按照以下步骤操作:

  1. 创建磁盘分区:首先,你需要使用分区工具(如fdisk或parted)在磁盘sda上创建分区。例如,你可以使用fdisk:
sudo fdisk /dev/sda

在fdisk提示符下,你可以使用"n"命令创建一个新分区,然后按照提示进行操作创建分区。创建分区后,使用"w"命令保存并退出fdisk。

linaro@bm1684:~$ sudo fdisk /dev/sda

# 输出
Welcome 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 0xe2f18847.

Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): 

Using default response p.
Partition number (1-4, default 1): 
First sector (2048-937703087, default 2048): 
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-937703087, default 937703087): 

Created a new partition 1 of type 'Linux' and of size 447.1 GiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
  1. 格式化分区:创建分区后,你需要使用适当的文件系统格式化分区。例如,如果你希望使用ext4文件系统:
sudo mkfs.ext4 /dev/sda1

# 输出
linaro@bm1684:~$ sudo mkfs.ext4 /dev/sda1
mke2fs 1.45.5 (07-Jan-2020)
Creating filesystem with 117212630 4k blocks and 29310976 inodes
Filesystem UUID: 5af098aa-f849-486d-be4d-dcc03caedbf9
Superblock backups stored on blocks: 
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
        4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968, 
        102400000

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (262144 blocks): done
Writing superblocks and filesystem accounting information: done  
  1. 创建挂载点:你需要创建一个目录,用作挂载点。
sudo mkdir -p /home/linaro/disk0
  1. 编辑 /etc/fstab.emmc.ro 文件:你需要编辑这个文件来添加一个新的条目,这样Ubuntu就可以在启动时自动挂载 sda1 到指定的挂载点。打开终端并输入以下命令以编辑 fstab.emmc.ro 文件:
sudo vim /etc/fstab.emmc.ro 

在文件的末尾添加如下行(确保替换 <文件系统类型> 为你的磁盘分区的实际文件系统类型,如 ext4):

/dev/sda1 /home/linaro/disk0 <文件系统类型> defaults,nofail 0 2

# 添加一行
/dev/sda1 /home/linaro/disk0 ext4 defaults,nofail 0 2

这里的 nofail 选项确保即使此磁盘未连接,系统也可以正常启动而不会进入紧急模式。

  1. 挂载分区:你可以立即挂载分区而不需要重启,使用如下命令:
sudo mount -a
  1. 检查挂载是否成功:使用 df -h 或者 lsblk 命令来检查磁盘是否已经正确挂载。

这些步骤应该能帮助你将 sda1 挂载到 /home/linaro/disk0 并在 /etc/fstab 中正确设置,以确保每次启动时自动挂载

相关推荐

  1. ubuntu 永久 磁盘挂载

    2024-06-12 12:40:04       32 阅读
  2. Ubuntu——永久挂载/卸载硬盘

    2024-06-12 12:40:04       64 阅读
  3. ubuntu22.04挂载磁盘的步骤

    2024-06-12 12:40:04       52 阅读
  4. CentOS 磁盘挂载

    2024-06-12 12:40:04       33 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-12 12:40:04       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-12 12:40:04       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-12 12:40:04       82 阅读
  4. Python语言-面向对象

    2024-06-12 12:40:04       91 阅读

热门阅读

  1. nginx配置

    2024-06-12 12:40:04       29 阅读
  2. 在密钥泄露后,如何评估影响并采取下一步行动?

    2024-06-12 12:40:04       27 阅读
  3. Web前端开发群聊:深入探索、交流与实践

    2024-06-12 12:40:04       31 阅读
  4. 常见的数据寻址方式

    2024-06-12 12:40:04       30 阅读
  5. 【C语言】32个关键字

    2024-06-12 12:40:04       26 阅读
  6. net core json 转换帮助类 JsonHelper

    2024-06-12 12:40:04       30 阅读
  7. 扩展知识:RocketMQ 如何开启 ACL 验证

    2024-06-12 12:40:04       27 阅读
  8. [python]yfinance国内不能使用

    2024-06-12 12:40:04       33 阅读