对于Linux系统来说,挂载磁盘的方法其实都大同小异,所以本文以CentOS系统为例,介绍下Linux系统磁盘挂载方法,前面大部分内容源于天翼云的论坛。
1.查看磁盘情况
使用命令fdisk -l # 列出全部磁盘信息
[root@ linuxidc.com ~]# fdisk -l
Disk/dev/xvda: 42.9 GB, 42949672960 bytes
255 heads, 63 sectors/track, 5221 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:0x0008a9a5
Device Boot Start End Blocks Id System
/dev/xvda1 1 523 4194304 82 Linux swap / Solaris
Partition1 does not end on cylinder boundary.
/dev/xvda2 * 523 5222 37747712 83 Linux
Disk/dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:0x00000000
2.创建分区
fdisk /dev/xvde # 对xvde硬盘进行分区
n # 创建一个新分区
p # 创建一个主分区(e为扩展分区)
1 # 1表示第一个主分区
回车 # 从第1柱面开始分区
回车 # 表示整个xvde全写入第1分区(若需要将sdb分为多个分区,此时输入+分区大小)
P # 查看下已创建好的分区
w # 保存并退出
[root@ linuxidc.com ~]# fdisk /dev/xvde
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building anew DOS disklabel with disk identifier 0x590ca8b1.
Changes will remainin memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command'u').
Command (mfor help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-39162, default 1):
Usingdefault value 1
Last cylinder,+cylinders or +size{K,M,G} (1-39162, default 39162):
Usingdefault value 39162
Command (mfor help): p
Disk/dev/xvde: 322.1 GB, 322122547200 bytes
255 heads, 63 sectors/track, 39162 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier:0x590ca8b1
Device Boot Start End Blocks Id System
/dev/xvde1 1 39162 314568733+ 83 Linux
Command (mfor help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
3.创建分区文件系统并格式化磁盘
# mkfs.ext4 /dev/xvde1 # 将xvde1以ext4格式进行格式化
对于Linux系统来说,磁盘xvda和xvde的分区是根据系统启动时识别的先后顺序来排列,这样就会出现一个当主机重启后,出现跳盘的情况,为了避免此情况的发生,就需要我们将磁盘的UUID信息写入fstab文件,将分区与磁盘绑定。
1)通过blkid获得磁盘分区的UUID
#
# /etc/fstab
# Created by anaconda on Thu Jan 12 02:47:21 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=77fc0962-b3cf-400a-8903-0632e077fa09 / ext3 defaults 1 1
UUID=5546dd0c-ef40-451b-b266-df8ef3a49967 swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
UUID=d17945b-c369-42de-85a8-47217d24d3e5 /home/mysql ext4 defaults 0 0
6.将/var/lib/mysql/下的内容转移至/home/mysql/,并且在/var/lib/下创建mysql的链接,实际目录其实为/home/mysql