Ubuntu16.04 中如何挂载第二块磁盘,挂载成功,但是用reboot和shutdown重启或关机后挂载就没有了的解决办法

时间:2023-03-10 02:19:31
Ubuntu16.04 中如何挂载第二块磁盘,挂载成功,但是用reboot和shutdown重启或关机后挂载就没有了的解决办法

本测试机有4块硬盘,初始意图想做一个磁盘阵列,但是在安装系统的时候不知道引导文件如何选择安装,所以暂时不使用磁盘阵列(后期研究)

检测硬盘能否被识别

root@ranxf:/# fdisk -l

Disk /dev/sda: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: gpt
Disk identifier: 59353137-DD3B-40FF-9656-314427DE1ADB 设备 Start 末尾 扇区 Size 类型
/dev/sda1 2048 1050623 1048576 512M EFI System
/dev/sda2 1050624 960419839 959369216 457.5G Linux filesystem
/dev/sda3 960419840 976771071 16351232 7.8G Linux swap Disk /dev/sdb: 465.8 GiB, 500107862016 bytes, 976773168 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disklabel type: dos
Disk identifier: 0xc48b3f11 设备 启动 Start 末尾 扇区 Size Id 类型
/dev/sdb1 2048 976773119 976771072 465.8G 83 Linux Disk /dev/sdc: 465.8 GiB, 500107862016 bytes, 976773168 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/sdd: 465.8 GiB, 500107862016 bytes, 976773168 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

上图中

dev/sda是系统安装时自动分区;

dev/sdb为手动格式化后的情况

dev/sdc和dev/sdd暂时未分区情况。

格式化磁盘

root@ranxf:/# mkfs.ext4 /dev/sdb

挂载磁盘

在本地硬盘中临时创建一个目录/wwwroot

并挂载第二块硬盘中的一个分区/dev/sdb1到/wwwroot

查看挂载是否成功。

root@ranxf:/# mkdir /wwwroot
root@ranxf:/# mount /dev/sdb1 /wwwroot/
root@ranxf:/# df -h
文件系统 容量 已用 可用 已用% 挂载点
udev 3.8G 0 3.8G 0% /dev
tmpfs 778M 9.4M 769M 2% /run
/dev/sda2 451G 20G 408G 5% /
tmpfs 3.8G 56M 3.8G 2% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 3.8G 0 3.8G 0% /sys/fs/cgroup
/dev/sda1 511M 3.6M 508M 1% /boot/efi
tmpfs 778M 0 778M 0% /run/user/121
tmpfs 778M 92K 778M 1% /run/user/1000
/dev/sdb1 459G 70M 435G 1% /wwwroot
root@ranxf:/#

挂载是成功了,但是用reboot和shutdown重启或关机后挂载就没有了,怎么解决

要修改/etc/fstab文件。
加一行字:
/dev/sdb1 /wwwroot ext4 defaults 0 0

也可以把你的挂载命令写入/etc/rc.local,这样开机自动挂载

卸载硬盘

#umount /dev/sdb1