linux 挂载新硬盘

linux 挂载新硬盘

linux 挂载新硬盘

查看硬盘设备

新硬盘设备在/dev目录下, 命名规则一般是sda, sdb, sdc...

每个硬盘的分区会形成一个分区文件, 同样在/dev目录下, 命名规则一般是(以sda为例) sda1, sda2......

用fdisk对这块硬盘分区

fdisk /dev/sdb
# 按 m 可显示菜单
Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table
# 按 g 创建新的GPT分区表
# 按 n 在分区表内创建新的分区
# 按 w 写入分区表, 保存并推出

经过以上步骤后分区的建立已经完成,但是此时系统还无法识别分区表

内核重新读取分区表

partprobe /dev/sdb
  • 注意:这里是整个磁盘sdb,不是磁盘分区sdb1

创建文件系统(格式化分区)

Linux 中的主流的文件系统有:ext4和xfsd等, 通常建立ext4文件系统

mkfs.ext4 /dev/sdb1
  • 注意:这里是磁盘分区sdb1,不是整个磁盘sdb

挂载

手动挂载

mount /dev/sdb1 /home/upload/file/

使用df查看挂载情况

Filesystem      Size  Used Avail Use% Mounted on
udev             16G     0   16G   0% /dev
tmpfs           3.2G   11M  3.2G   1% /run
/dev/sda1        92G   60G   28G  69% /
tmpfs            16G  192K   16G   1% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs            16G     0   16G   0% /sys/fs/cgroup
/dev/sda6       945M  137M  744M  16% /boot
/dev/sda7       1.7T  1.6T   55G  97% /home
tmpfs           3.2G   36K  3.2G   1% /run/user/1000
/dev/sdb1       917G   72M  871G   1% /home/upload/file         ----------      此行为新挂载硬盘

这里已经挂载成功,但是这只是一次性的,重启后就会消失

永久挂载

要对/etc/fstab文件编辑

vi /etc/fstab

​ 命令运行结果(文件内容) :

# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
#                
# / was on /dev/sda1 during installation
UUID=172fbcba-9aad-4c84-88b5-8f271b1c8d69 /               ext4    errors=remount-ro 0       1
# /boot was on /dev/sda6 during installation
UUID=bdfe743b-3350-4d4e-a94f-dc734210c6c0 /boot           ext4    defaults        0       2
# /home was on /dev/sda7 during installation
UUID=2a0fc22c-6f11-446d-bf99-2bd0913c5635 /home           ext4    defaults        0       2
# swap was on /dev/sda5 during installation
UUID=7403ecf6-b49b-4612-9036-afc85debed9e none            swap    sw              0       0

# disk size 1TB sdb to /home/upload/file
/dev/sdb1        /home/upload/file       ext4           defaults       0        0

扩展:

#UUID的查询:
blkid

检查配置

以上步骤完成后,还需要判断是否正确

mount -a
posted on 2019-09-23 18:27  斑駁儿 阅读( ...) 评论( ...) 编辑 收藏

转载于:https://www.cnblogs.com/bevon/p/11573924.html

你可能感兴趣的:(linux 挂载新硬盘)