在实际环境中,我们的硬盘会有不够用的情况,此时我们会给主机添加硬盘然后把硬盘或者分区挂载在需要的位置。但是主机重启后以前所做的挂载将会消失,而我们还要重新挂载显得非常繁琐。为了解决此类问题,Linux有自动挂载功能,我们只要把需要做的挂载写入到/etc/fstab中就可以实现开机自动挂载功能了。下面我就给大家介绍一下如何实现开机自动挂载功能。
1,为了解决数据存储区容量不够用的问题,将决定为主机添加两块硬盘并将第一块硬盘分区,分别挂载在/data/document/、/data/software/、/data/media/
[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
DeviceBoot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 85.8 GB, 85899345920 bytes……新加硬盘85G
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn’t contain a valid partition table……未分区
Disk /dev/sdc: 21.4 GB, 21474836480 bytes……新加硬盘21G
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn’t contain a valid partition table……未分区
2,把sdb做分区分别为:sdb140G、sd2 45G;sdc分给逻辑卷sdc5
[root@localhost ~]# fdisk -l
Disk /dev/sda: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
DeviceBoot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 2563 20482875 83 Linux
/dev/sda3 2564 2824 2096482+ 82 Linux swap / Solaris
Disk /dev/sdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
DeviceBoot Start End Blocks Id System
/dev/sdb1 1 4864 39070048+ 83 Linux……sdb1 40G
/dev/sdb2 4865 10443 44813317+ 83 Linux……sdb2 45G
Disk /dev/sdc: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
DeviceBoot Start End Blocks Id System
/dev/sdc1 1 2610 20964793+ 5 Extended
/dev/sdc5 1 2610 20964762 83 Linux……sdc5 21G
3,用vim打开/etc/fstab并编辑
[root@localhost ~]# vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
LABEL=/boot /boot ext3 defaults 1 2
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
LABEL=SWAP-sda3 swap swap defaults 0 0
UUID=”dfa9ce92-aea6-442c-b840-7118cac3df5a”/data/document ext3 defaults 0 0……新加
UUID=”ce11e3fd-c817-457e-9b7b-3d09c6b6b7e6″/data/software ext3 defaults 0 0 挂载
UUID=”e685f293-0d3c-442c-9feb-f89c4225e157″/data/media ext3 defaults 0 0
~
~
~
10,76 全部
4,验证新加自动挂载是否成功
[root@localhost ~]# df -h
文件系统容量已用可用已用%挂载点
/dev/sda2 19G 2.8G 16G 16% /
/dev/sda1 99M 12M 82M 13%/boot
tmpfs 500M 0 500M 0% /dev/shm
/dev/hdc 4.1G 4.1G 0 100% /media/RHEL_5.9 x86_64 DVD
[root@localhost ~]# mount –a……重新加载fstab配置信息
[root@localhost ~]# df -h
文件系统容量已用可用已用%挂载点
/dev/sda2 19G 2.8G 16G 16% /
/dev/sda1 99M 12M 82M 13% /boot
tmpfs 500M 0 500M 0% /dev/shm
/dev/sdb1 37G 177M 35G 1% /data/document……挂载成功
/dev/sdb2 43G 177M 40G 1% /data/software……挂载成功
/dev/sdc5 20G 173M 19G 1% /data/media……挂载成功
5,重新启动主机验证是否能跟随主机自动挂载
[root@localhost ~]# reboot
……………………………………….
……………………….
……..
[root@localhost ~]# df -lT
文件系统类型 1K-块已用可用已用% 挂载点
/dev/sda2 ext3 19840924 2920144 15896640 16% /
/dev/sda1 ext3 101086 12184 83683 13% /boot
tmpfs tmpfs 511924 0 511924 0% /dev/shm
/dev/sdb1 ext3 38456308 180240 36322568 1% /data/document……已挂载
/dev/sdb2 ext3 44109972 180240 41689068 1% /data/software 成功
/dev/sdc5 ext3 20635668 176200 19411232 1% /data/media