Ubuntu18.04 挂载磁盘

前提

当前操作普通用户无权限,所以需要切换到root账户,执行操作如下:

sudo -i

1.查看磁盘情况

root@datacenter:~# fdisk -l
Disk /dev/vda: 100 GiB, 107374182400 bytes, 209715200 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
Disklabel type: gpt
Disk identifier: AB42D5D6-48EF-4252-B60C-B7C781E8FFAC

Device     Start       End   Sectors  Size Type
/dev/vda1   2048      4095      2048    1M BIOS boot
/dev/vda2   4096 209713151 209709056  100G Linux filesystem

Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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

从如上执行结果可以看出,要挂载的硬盘500G ,位置在 /dev/vdb

2.查看指定分区情况

root@datacenter:~# fdisk -l /dev/vdb 
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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

3.查看分区块大小

root@datacenter:~# fdisk -s /dev/vdb 
524288000

此处的显示的524288000512*1024*1000获得,单位是字节。

将磁盘的文件系统更改为 xfs

mkfs.xfs /dev/vdb

4.正式分区

root@datacenter:~# fdisk /dev/vdb

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

The old ext4 signature will be removed by a write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x0faba5aa.

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

Command (m for help): n
Partition type
   p   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-1048575999, default 2048): 2048
Last sector, +sectors or +size{K,M,G,T,P} (2048-1048575999, default 1048575999): 

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

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@datacenter:~# fdisk -lu /dev/vdb
Disk /dev/vdb: 500 GiB, 536870912000 bytes, 1048576000 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
Disklabel type: dos
Disk identifier: 0x0faba5aa

Device     Boot Start        End    Sectors  Size Id Type
/dev/vdb1        2048 1048575999 1048573952  500G 83 Linux

如上分区完成。

5.查看当前分区表

root@datacenter:~# cat /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).
#
# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/vda2 during curtin installation
/dev/disk/by-uuid/xxx-xxx-xxx-xxx / ext4 defaults 0 1
/swap.img   none    swap    sw  0   0

6.查看当前磁盘分区UUID

root@datacenter:~# blkid 
/dev/vda2: UUID="xxx-xxx-xxx-xxx" TYPE="ext4" PARTUUID="xxx-xxx-xxx-xxx"
/dev/vda1: PARTUUID="xxx-xxx-xxx-xxx"
/dev/vdb1: PARTUUID="xxx-xxx-xxx-xxx"

7.修改分区表

vi /etc/fstab 在最下方加入如下内容

UUID="39fxxxxxx-b8ed-xxxx-a430-e5xxxxx62887" /data ext4 defaults 0 1

G /g 快速到文章最后一行 ,$ 到行尾部 o 快速在下一行插入

8.检查文件是否正确

mount -a

9.重启看效果

reboot now

注意:一定注意要在重启之前检查fstab文件是否正确,我在做的时候,直接干岔劈了两台服务器,非常尴尬。

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注