开机自动挂载ISO文件
Table of Contents
1 概述
开机自动挂载ISO 文件有两种途径 。一种是经过配置fstab文件,开机时Linux自动识别并 挂载。另一种是将挂载命令加入到开机后自动执行的脚本中, 通常为/etc/rc.d/rc.local.css
下面分别是两种方式的内容。html
好比个人ISO文件是 /root/CentOS-7-x86_64-DVD-1611.iso, 我想把它挂载到 /iso 路径下。前提要先建立/iso 路径。下面是实现自动挂载的两种途径。java
1.1 经过fstab
在/etc/fstab 文件中添加入下面一行内容:python
<ISO文件绝对路径> <挂载点> iso9660 loop,defaults 0 0
示例以下:sql
[root@report-test rc.d]# cat /etc/fstab ...... 省略 /root/CentOS-7-x86_64-DVD-1611.iso /iso iso9660 loop,defaults 0 0
编辑好文件fstab后,保存,并执行以下命令进行本次挂载(也就是手动挂载),不须要重启服务器。下次重 启服务器时会自动挂载:shell
# mount /iso
示例以下:sass
[root@report-test rc.d]# mount /iso mount: /dev/loop0 写保护,将以只读方式挂载
1.2 经过rc.local
在rc.local文件尾部加入如下格式的命令:ruby
cat >> /etc/rc.d/rc.local <<EOF mount -o loop -t iso9660 <ISO文件绝对路径> <挂载点> EOF
示例:bash
[root@report-test rc.d]# cat >> /etc/rc.d/rc.local <<EOF > mount -o loop -t iso9660 /root/CentOS-7-x86_64-DVD-1611.iso /iso > EOF [root@report-test rc.d]# tail /etc/rc.d/rc.local # to run scripts during boot instead of using this file. # # In contrast to previous versions due to parallel execution during boot # this script will NOT be run after all other services. # # Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure # that this script will be executed during boot. touch /var/lock/subsys/local mount -o loop -t iso9660 /root/CentOS-7-x86_64-DVD-1611.iso /iso # 此行为手动挂载iso文件的命令,路径存在的话,不须要作任何配置,便可进行挂载