Linux分区管理 永久挂载(推荐)&临时挂载

Linux分区管理 永久挂载(推荐)&临时挂载

本文采用Linux版本为CentOS 7.4,下文涉及的命令均采用root用户执行,数据无价,请谨慎操作!

介绍

前段时间受限电影响,公司的测试服务器在周末停电,部分测试服务器重启后找不到项目文件,排查发现是因为采用的临时挂载的方式挂载的新硬盘,重新挂载后恢复正常。

分区情况

使用fdisk查看当前分区情况

读取到/dev/sda和/dev/sdb两块硬盘,/dev/mapper/vgdisk-root及/dev/mapper/vgdisk-swap为逻辑卷,对应/dev/sda下的/dev/sda2及/dev/sda3

[root@kfb1 ~]# fdisk -l

Disk /dev/sda: 107.4 GB, 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
Disk label type: dos
Disk identifier: 0x000515f8

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048     1026047      512000   83  Linux
/dev/sda2         1026048   125829119    62401536   8e  Linux LVM
/dev/sda3       125829120   209715199    41943040   8e  Linux LVM

Disk /dev/sdb: 214.7 GB, 214748364800 bytes, 419430400 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


Disk /dev/mapper/vgdisk-root: 102.6 GB, 102550732800 bytes, 200294400 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


Disk /dev/mapper/vgdisk-swap: 4290 MB, 4290772992 bytes, 8380416 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

使用df命令获取当前磁盘使用情况

/dev/sdb未进行挂载

[root@kfb1 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vgdisk-root   96G  7.7G   88G   9% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  198M  1.7G  11% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  171M  327M  35% /boot
tmpfs                    378M   12K  378M   1% /run/user/42

永久挂载(推荐)

新建挂载目录,必须为空目录

[root@kfb1 ~]# cd /
[root@kfb1 /]# mkdir apps

编辑/etc/fstab文件

[root@kfb1 /]# vim /etc/fstab

#
# /etc/fstab
# Created by anaconda on Tue Dec 19 13:49:44 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
#
/dev/mapper/vgdisk-root /                       xfs     defaults        0 0
UUID=b00f5375-e726-45e0-8d4e-a439bd2c4805 /boot                   xfs     defaults        0 0
/dev/mapper/vgdisk-swap swap                    swap    defaults        0 0

新增一条记录

其中:/dev/sdb为未进行挂载的硬盘,/apps为新建的挂载目录,其他参数可根据已有的root记录填写

/dev/sdb /apps                    xfs    defaults        0 0

使用mount命令刷新/etc/fstab文件

[root@kfb1 ~]# mount -a

重新执行df命令,可发现挂载成功

[root@kfb1 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vgdisk-root   96G  7.7G   88G   9% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  198M  1.7G  11% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  171M  327M  35% /boot
tmpfs                    378M   12K  378M   1% /run/user/42
/dev/sdb                 400G  346G   55G  87% /apps

临时挂载(不推荐)

临时挂载方式重启后即取消挂载(数据不会丢失,重新挂载即可),不推荐,仅供参考

新建挂载目录,必须为空目录(同上)

[root@kfb1 ~]# cd /
[root@kfb1 /]# mkdir apps

直接使用mount命令进行挂载

其中:/dev/sdb为未进行挂载的硬盘,/apps为新建的挂载目录

[root@kfb1 /]# mount /dev/sdb /apps

重新执行df命令,可发现挂载成功

[root@kfb1 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vgdisk-root   96G  7.7G   88G   9% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  198M  1.7G  11% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  171M  327M  35% /boot
tmpfs                    378M   12K  378M   1% /run/user/42
/dev/sdb                 400G  346G   55G  87% /apps

使用umount命令手动卸载

[root@kfb1 /]# umount /apps

重新执行df命令,已成功卸载

[root@kfb1 ~]# df -h

Filesystem               Size  Used Avail Use% Mounted on
/dev/mapper/vgdisk-root   96G  7.7G   88G   9% /
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  198M  1.7G  11% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/sda1                497M  171M  327M  35% /boot
tmpfs                    378M   12K  378M   1% /run/user/42

你可能感兴趣的:(Linux分区管理 永久挂载(推荐)&临时挂载)