挂载磁盘

参考:https://blog.csdn.net/web_snail/article/details/98507738

一、查看磁盘列表

1.1:lsblk 列出系统上的所有磁盘列表
# lsblk
NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   1.8T  0 disk 
└─sda1            8:1    0   1.8T  0 part 
sdb               8:16   0 447.1G  0 disk 
├─sdb1            8:17   0   200M  0 part /boot/efi
├─sdb2            8:18   0     1G  0 part /boot
└─sdb3            8:19   0   446G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0  31.4G  0 lvm  [SWAP]
  └─centos-home 253:2    0 364.5G  0 lvm  /home
1.2:blkid 列出装置的 UUID 等参数
# blkid
/dev/sdb1: SEC_TYPE="msdos" UUID="08F5-2442" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="4a1e3b5a-4a15-4fe5-84c1-47b1dc4fd1dc" 
/dev/sdb2: UUID="c0e00e91-3098-4aa9-b126-289598be66e2" TYPE="xfs" PARTUUID="2c36a200-75ee-4343-8281-db7994a7dbc0" 
/dev/sdb3: UUID="BjBZjl-Se5F-bsDt-SNOE-cTAA-uIet-6N7OKc" TYPE="LVM2_member" PARTUUID="18edcb81-200e-4966-89e3-2664fdc45256" 
/dev/sda1: UUID="cab629d9-3a15-48a3-9b58-55f068c6cf7b" TYPE="xfs" 
/dev/mapper/centos-root: UUID="1dcffb5c-cd6c-4107-91e2-70dd6ebdd250" TYPE="xfs" 
/dev/mapper/centos-swap: UUID="afcd2091-7723-4d5d-ab10-c331ad3f1a6f" TYPE="swap" 
/dev/mapper/centos-home: UUID="e5bc9c34-2f47-4eed-9e2d-c38e4965bdf4" TYPE="xfs"
1.3:parted /dev/sda print (parted 列出磁盘的分区表类型与分区信息)
Model: 未知 (unknown)
Disk /dev/sda1: 2000GB
Sector size (logical/physical): 512B/4096B
Partition Table: loop
Disk Flags: 

Number  Start  End     Size    File system  标志
 1      0.00B  2000GB  2000GB  xfs

二:磁盘分区

2.1:用 gdisk 或 fdisk 新增分区槽

这里用fdisk: # fdisk /dev/sda

[root@localhost ~]# fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.
欢迎使用 fdisk (util-linux 2.23.2)。

更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。


命令(输入 m 获取帮助):m
命令操作
   a   toggle a bootable flag
   b   edit bsd disklabel
   c   toggle the dos compatibility flag
   d   delete a partition
   g   create a new empty GPT partition table
   G   create an IRIX (SGI) partition table
   l   list known partition types
   m   print this menu
   n   add a new partition
   o   create a new empty DOS partition table
   p   print the partition table
   q   quit without saving changes
   s   create a new empty Sun disklabel
   t   change a partition's system id
   u   change display/entry units
   v   verify the partition table
   w   write table to disk and exit
   x   extra functionality (experts only)
2.2:用 参数 'n' 创建一个分区,再用 'w' 写入碰盘 ,可以用'p'参数查看碰盘情况
命令(输入 m 获取帮助):n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
分区号 (1-4,默认 1):2
起始 扇区 (2048-3907029167,默认为 2048):2048
Last 扇区, +扇区 or +size{K,M,G} (2048-3907029167,默认为 3907029167):3907029167
分区 2 已设置为 Linux 类型,大小设为 1.8 TiB

命令(输入 m 获取帮助):p
磁盘 /dev/sda:2000.4 GB, 2000398934016 字节,3907029168 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 4096 字节
I/O 大小(最小/最佳):4096 字节 / 4096 字节
磁盘标签类型:dos
磁盘标识符:0x87106dc1

   设备 Boot      Start         End      Blocks   Id  System
/dev/sda1            2048  3907029167  1953513560   83  Linux

三、格式化磁盘

3.1用 mkfs.xfs -f 格式成xfs
mkfs.xfs -f  /dev/sda1
meta-data=/dev/sda1              isize=512    agcount=4, agsize=122094598 blks
         =                       sectsz=4096  attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=488378390, imaxpct=5
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=238466, version=2
         =                       sectsz=4096  sunit=1 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

3.2 更新分区信息partprobe -s
[root@localhost ~]# partprobe -s
/dev/sda: msdos partitions 1
/dev/sdb: gpt partitions 1 2 3

四、文件系统挂载与卸除

4.1通过UUID进行挂载
4.1.1 查看UUID : blkid
[root@localhost ~]# blkid /dev/sda1
/dev/sda1: UUID="cab629d9-3a15-48a3-9b58-55f068c6cf7b" TYPE="xfs" 
4.1.2 通过查到的UUID进行挂载 和通过 目录挂载
# mount UUID="cab629d9-3a15-48a3-9b58-55f068c6cf7b" /data/sda/
# mount /dev/sda1 /data/sda
4.1.3 查看挂载情况 df /data/sda
# df /data/sda
文件系统            1K-块  已用       可用 已用% 挂载点
/dev/sda1      1952559696 32996 1952526700    1% /data/sda
4.1.4 可以使用umount (将装置文件卸除)
如: umount /data/sda

五:设定开机挂载

# vi /etc/fstab

5.1找出磁盘的UUID sda1的UUID为 adb768f0-e48c-4b72-927d-4ab4127ef1f0
# blkid
/dev/nvme0n1p1: SEC_TYPE="msdos" UUID="4881-D9C8" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="8149de76-55f2-4ff4-a6ef-5c6f188cc478"
/dev/nvme0n1p2: UUID="fda6b4be-20b3-458f-81ff-82f95dab4560" TYPE="xfs" PARTUUID="75cb65aa-2785-485b-995d-565c1bed82ac"
/dev/nvme0n1p3: UUID="yAfYsl-i5rz-pxbR-nTtZ-zpcP-D4Ik-TNSIpX" TYPE="LVM2_member" PARTUUID="5b3ae21a-4ac7-4802-97d6-5e04557a2112"
/dev/sda1: UUID="adb768f0-e48c-4b72-927d-4ab4127ef1f0" TYPE="xfs" PARTUUID="236781fe-7508-41f8-ad7e-4e15d0338924"
/dev/mapper/centos-root: UUID="3ab26947-9ada-4d3a-b29b-0466d43c3b3a" TYPE="xfs"
/dev/mapper/centos-swap: UUID="a08df468-5072-482f-ad5c-3909bdbf0660" TYPE="swap"
/dev/mapper/centos-home: UUID="de751e3b-a820-4950-afb2-00ca6d9734ce" TYPE="xfs"
/dev/nvme0n1: PTTYPE="gpt"
5.2写入自动挂载配制文件 vi /etc/fstab

后台加上

UUID=adb768f0-e48c-4b72-927d-4ab4127ef1f0 /usr/local/sddata xfs defaults 0 0

如下图


新加

推荐阅读更多精彩内容