[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 28767356 4690696 22608708 18% / tmpfs 515272 228 515044 1% /dev/shm /dev/sda2 999320 1436 945456 1% /tmp
我們執行:lsblk 才能看到我們第一步中掛載的iso光盤:
[root@localhost ~]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT sr0 11:0 1 3.8G 0 rom sda 8:0 0 30G 0 disk ├─sda1 8:1 0 28G 0 part / ├─sda2 8:2 0 1G 0 part /tmp └─sda3 8:3 0 1G 0 part [SWAP]
上面那個 sr0 大小3.8G的就是 我們上面掛載的iso光盤。我們看到他沒有掛載點,其MOUNTPOINT欄目下面的值為空,這才是我們上面用df命令查看不到iso光盤的原因。所以我們需要將 sr0 掛載到一個掛載點上: 3. 掛載iso: [root@localhost ~]# ll /dev/cdrom lrwxrwxrwx. 1 root root 3 Sep 9 09:27 /dev/cdrom -> sr0 [root@localhost ~]# mkdir /mnt/cdrom [root@localhost ~]# mount /dev/cdrom /mnt/cdrom ll /dev/cdrom 的結果看到,其是到 sr0 的一個連接; mkdir /mnt/cdrom 建立一個掛載點; mount /dev/cdrom /mnt/cdrom 將光盤掛載到 /mnt/cdrom; mount執行如果不成功,則需要加參數:mount -t iso9660 /dev/cdrom /mnt/cdrom/
[root@localhost ~]# df Filesystem 1K-blocks Used Available Use% Mounted on /dev/sda1 28767356 4690684 22608720 18% / tmpfs 515272 228 515044 1% /dev/shm /dev/sda2 999320 1436 945456 1% /tmp /dev/sr0 3934618 3934618 0 100% /mnt/cdrom 在查看 df 的結果,就看到 /dev/sr0 被掛載到了 /mnt/cdrom
我們去查看一下光盤的內容:
[root@localhost ~]# cd /mnt/cdrom [root@localhost cdrom]# ll total 562 -r--r--r--. 2 root root 14 Oct 24 2014 CentOS_BuildTag -r--r--r--. 2 root root 212 Nov 27 2013 EULA -r--r--r--. 2 root root 18009 Nov 27 2013 GPL dr-xr-xr-x. 3 root root 2048 Oct 24 2014 images dr-xr-xr-x. 2 root root 2048 Oct 24 2014 isolinux dr-xr-xr-x. 2 root root 534528 Oct 24 2014 Packages -r--r--r--. 2 root root 1354 Oct 19 2014 RELEASE-NOTES-en-US.html dr-xr-xr-x. 2 root root 4096 Oct 24 2014 repodata -r--r--r--. 2 root root 1706 Nov 27 2013 RPM-GPG-KEY-CentOS-6 -r--r--r--. 2 root root 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Debug-6 -r--r--r--. 2 root root 1730 Nov 27 2013 RPM-GPG-KEY-CentOS-Security-6 -r--r--r--. 2 root root 1734 Nov 27 2013 RPM-GPG-KEY-CentOS-Testing-6 -r--r--r--. 1 root root 3165 Oct 24 2014 TRANS.TBL
為了避免每次只需掛載的操作,我們修改一下 /etc/fstab ,讓系統自動幫我們掛載:
[root@localhost cdrom]# cat /etc/fstab # # /etc/fstab # Created by anaconda on Wed Aug 12 10:17:54 2015 # # 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=050bfcba-55c7-4618-9159-497232acca9d / ext4 defaults 1 1 UUID=35cc903b-a973-4fe8-84b5-69c1aaa9d7f2 /tmp ext4 defaults 1 2 UUID=7900da09-a872-4be0-95b7-7668eea54179 swap swap defaults 0 0 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 /dev/cdrom /mnt/cdrom iso9660 defaults 0 2
最後一行,是我們加的內容。這樣系統啟動時,就會執行 /etc/fstab 中的文件掛載。 4. 配置掛載的DVD光盤做yum軟件源
[root@localhost cdrom]# cd /etc/yum.repos.d/ [root@localhost yum.repos.d]# ll total 28 -rw-r--r--. 1 root root 1991 Oct 23 2014 CentOS-Base.repo -rw-r--r--. 1 root root 647 Oct 23 2014 CentOS-Debuginfo.repo -rw-r--r--. 1 root root 289 Oct 23 2014 CentOS-fasttrack.repo -rw-r--r--. 1 root root 628 Sep 9 09:55 CentOS-Media.repo -rw-r--r--. 1 root root 5394 Oct 23 2014 CentOS-Vault.repo
軟件源所以的配置都在目錄 /etc/yum/repso.d/ 下面 先做個備份: [root@localhost yum.repos.d]# mv CentOS-Base.repo CentOS-Base.repo.backup [root@localhost yum.repos.d]# cp CentOS-Media.repo CentOS-Media.repo.backup mv 掉 CentOS-Base.repo 的原因時,其中包括的都是網絡上的 yum 軟件源,如果不 mv 掉的話,以後每次都會先去網絡上的 yum 軟件源尋找,浪費時間。 備份 CentOS-Media.repo 之後,然後我們修改它,編輯 CentOS-Media.repo : 1> 將 gpgcheck 和 enabled 分別改為:gpgcheck=0 enabled=1 2> 將 baseurl 參數中的第二行原來的 "file:///media/cdrom" 值 改為:file:///mnt/cdrom/ 修改之後的結果如下:
[root@localhost yum.repos.d]# cat CentOS-Media.repo # CentOS-Media.repo # # This repo can be used with mounted DVD media, verify the mount point for # CentOS-6. You can use this repo and yum to install items directly off the # DVD ISO that we release. # # To use this repo, put in your DVD and use it with the other repos too: # yum --enablerepo=c6-media [command] # # or for ONLY the media repo, do this: # # yum --disablerepo=\* --enablerepo=c6-media [command] [c6-media] name=CentOS-$releasever - Media baseurl=file:///media/CentOS/ file:///mnt/cdrom/ file:///media/cdrecorder/ gpgcheck=0 enabled=1 gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
3> 清理 yum cache ,更新 yum:
[root@localhost yum.repos.d]# yum clean all Loaded plugins: fastestmirror, refresh-packagekit, security Cleaning repos: c6-media Cleaning up Everything Cleaning up list of fastest mirrors [root@localhost yum.repos.d]# [root@localhost yum.repos.d]# yum update Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Update Process Determining fastest mirrors * c6-media: file:///media/CentOS/repodata/repomd.xml: [Errno 14] Could not open/read file:///media/CentOS/repodata/repomd.xml Trying other mirror. file:///media/cdrecorder/repodata/repomd.xml: [Errno 14] Could not open/read file:///media/cdrecorder/repodata/repomd.xml Trying other mirror. c6-media | 4.0 kB 00:00 ... c6-media/primary_db | 3.5 MB 00:00 ... No Packages marked for Update [root@localhost yum.repos.d]#
然後就可以使用 本地 iso 光盤的軟件源來安裝軟件了。
[root@localhost yum.repos.d]# yum install pcre-devel Loaded plugins: fastestmirror, refresh-packagekit, security Setting up Install Process Loading mirror speeds from cached hostfile * c6-media: Package pcre-devel-7.8-6.el6.i686 already installed and latest version Nothing to do [root@localhost yum.repos.d]#
顯示我已經安裝了 pcre-devel 。