新增数据盘

第一步:在阿里云创建云盘(必须和挂载的服务器是一个区域一个分区)

            购买完之后在阿里云上面先挂载

第二步:创建磁盘分区

[root@iZj6c45wku1lv9c4w5dlpqZ ~]# fdisk -l 查看现有磁盘分区

Disk /dev/vda: 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: 0x00020f03

Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41940992 83 Linux

Disk /dev/vdb: 128.8 GB, 128849018880 bytes
16 heads, 63 sectors/track, 249660 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00000000

对未分区磁盘进行分区

[root@iZj6c45wku1lv9c4w5dlpqZ ~]# fdisk /dev/vdb 
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0x78851959.
Changes will remain in 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 (m for help): m 查看帮助
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
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)

Command (m for help): n 新增加分区
Command action
e extended
p primary partition (1-4)
p 基本分区
Partition number (1-4): 1 分区编号
First cylinder (1-249660, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-249660, default 249660):
Using default value 249660

Command (m for help): w 写入修改
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@iZj6c45wku1lv9c4w5dlpqZ ~]#
[root@iZj6c45wku1lv9c4w5dlpqZ ~]# fdisk -l 查看新建分区

Disk /dev/vda: 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: 0x00020f03

Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41940992 83 Linux

Disk /dev/vdb: 128.8 GB, 128849018880 bytes
16 heads, 63 sectors/track, 249660 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x78851959

Device Boot Start End Blocks Id System
/dev/vdb1 1 249660 125828608+ 83 Linux

 将新建分区格式为ext4格式


[root@iZj6c45wku1lv9c4w5dlpqZ ~]# mkfs -t ext4 /dev/vdb1 将新建分区格式为ext4格式
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
7864320 inodes, 31457152 blocks
1572857 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
960 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@iZj6c45wku1lv9c4w5dlpqZ ~]# fdisk -l 查看分区列表

Disk /dev/vda: 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: 0x00020f03

Device Boot Start End Blocks Id System
/dev/vda1 * 1 5222 41940992 83 Linux

Disk /dev/vdb: 128.8 GB, 128849018880 bytes
16 heads, 63 sectors/track, 249660 cylinders
Units = cylinders of 1008 * 512 = 516096 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x78851959

Device Boot Start End Blocks Id System
/dev/vdb1 1 249660 125828608+ 83 Linux


第三步:挂载上要指定的目录(当挂载的目录下面有数据的时候把数据移出再挂载,否则挂载上目录下面会没有数据)


[root@iZj6c45wku1lv9c4w5dlpqZ ~]# mount /dev/vdb1 /mnt 将分区挂载到/mnt下
[root@iZj6c45wku1lv9c4w5dlpqZ ~]#

第四步:可以设置开机自动挂载


[root@iZj6c45wku1lv9c4w5dlpqZ ~]#
[root@iZj6c45wku1lv9c4w5dlpqZ ~]# blkid 查看磁盘UUID
/dev/vda1: UUID="a3b07a51-3009-4ddf-9240-81333f13880e" TYPE="ext4"
/dev/vdb1: UUID="883cb023-0e52-45d0-bc4f-a40b0247bd99" TYPE="ext4"
[root@iZj6c45wku1lv9c4w5dlpqZ ~]#
[root@iZj6c45wku1lv9c4w5dlpqZ ~]#

[root@iZm5e9eb5azhksxowz185wZ ~]# cat /etc/fstab

#
# /etc/fstab
# Created by anaconda on Fri Feb 24 02:58:22 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=07151862-c2b9-45dc-bfndfasdssddfcadd   / ext3 defaults 1 1
UUID="a3b07a51-3009-4ddf-9240-81333f13880e  /mnt ext4 defaults 0 0

[root@iZm5e9eb5azhksxowz185wZ ~]#

 umount命令

  解挂文件系统。umount [-ahnrvV][-t 《文件系统类型》][文件系统]

  umount可卸除目前挂在Linux目录中的文件系统。

  线上在用的nfs访问时出了问题,导致/data1目录ls都无法进行输出,需要进行卸载掉 。而直接卸载时由于目录正被其他进程占用 ,无法直接umount,这里就结合fuser进行umount卸载。

  1、直接卸载

  [root@localhost /]# umount /data1/img

  umount: /data1/img: device is busy

  umount: /data1/img: device is busy

  2、提示被占用,使用强制卸载

  [root@localhost /]# umount -f /data1/img

  umount2: Device or resource busy

  umount: /data1/img: device is busy

  umount2: Device or resource busy

  umount: /data1/img: device is busy

  注:使用-f 参数进行强制卸载时一般建议等一会儿再进行下面的操作,一些情况下处理需要1-2分钟的时间。

  3、使用umount -f,问题依旧。使用fuser命令,先确认有那些进程在占用该目录

  [root@localhost /]# fuser -cu /data1/img

  /data1/img: 1757c(mysql)

  上面查看发现是pid为1757的mysql用户起的进程在占用该目录。

  4、确认mysql所起的进程可以kill 后,可以直接使用fuser 的k参数进行kill (也可以手动停掉1757进程再卸载)

  [root@localhost /]# fuser -ck /data1/img

  /data1/img: 1757c

  注:这里k 就是kill的意思,注意没进行确认前要谨慎使用该参数。

  另外,umount异常时,也经常会用到 lsof 指定确认文件被什么进程占用

  上面就是Linux使用umount命令强制卸载文件系统的方法,即使提示被占用也照样能够通过命令来卸载。

原文地址:https://www.cnblogs.com/xy51/p/9603543.html