1.首先讓鏡像被系統識別
[root@localhost Desktop]# df //首先查看已存在的掛載項 Filesystem 1K-blocks Used Available Use% Mounted on /dev/vda1 10473900 6971760 3502140 67% / devtmpfs 469332 0 469332 0% /dev tmpfs 484920 140 484780 1% /dev/shm tmpfs 484920 12784 472136 3% /run tmpfs 484920 0 484920 0% /sys/fs/cgroup /dev/mapper/vg0-vo 483670 2339 451840 1% /home
現在我把鏡像掛載到/mnt目錄上
[root@localhost Desktop]# mount -t iso9660 -o loop /dev/cdrom /mnt/cdrom //鏡像掛載到/mnt目錄上 mount: /dev/loop0 is write-protected, mounting read-only [root@localhost Desktop]# df Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/loop0 3654720 3654720 0 100% /mnt //掛載鏡像成功
2.查看/mnt下的鏡像文件
[root@localhost Desktop]# cd /mnt [root@localhost mnt]# ls addons images Packages RPM-GPG-KEY-redhat-release EFI isolinux release-notes TRANS.TBL EULA LiveOS repodata GPL media.repo RPM-GPG-KEY-redhat-beta
有這些文件說明掛載成功了。
3.配置本地yum源
[root@localhost etc]# cd /etc/yum.repos.d/ [root@localhost etc]#rm -rf * [root@localhost yum.repos.d]# vim yum.repo //文件名稱一定以.repo為后綴 [rhel7.0] //倉庫描述 name=rhel7.0 server //對軟件源的描述 baseurl=file:///mnt //鏡像的掛載入地址 file:// --格式 /mnt--指定目錄 gpgcheck=0 //不檢查gpgkey enabled=1 //此yum源語句塊立即生效
4.測試
[root@localhost yum.repos.d]# yum clear all //清空之前的yum源信息 Loaded plugins: langpacks No such command: clear. Please use /usr/bin/yum --help [root@localhost yum.repos.d]# yum repolist //列出yum的信息 Loaded plugins: langpacks repo id repo name status rhel7.0 rhel7.0 server 4,305 repolist: 4,305 [root@localhost yum.repos.d]# yum install gcc -y //下載gcc
5.設置開機自動掛載
系統reboot后,鏡像不會自動掛載到/mnt目錄上,我們需要修改系統啟動文件。
[root@localhost Desktop]# vim /etc/rc.d/rc.local 最后一行添加 mount /root/Desktop/rhel-server-7.0-x86_64-dvd.iso /mnt //mount 鏡像的絕對路徑 要掛載的目錄 [root@localhost Desktop]# chmod 755 /etc/rc.d/rc.local //系統開機時自動執行此腳本
測試
[root@localhost Desktop]# reboot
[root@foundation36 kiosk]# ssh 172.25.254.136
root@172.25.254.136's password: Last login: Thu Jan 17 22:50:16 2019 from 172.25.254.36 [root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on ... /dev/loop0 3654720 3654720 0 100% /mnt //開機被自動掛載上