为 Virtual Box 中的 CentOS 6.6 配置本地DVD光盘做yum软件源,centosyum


因为virtual box 中的centos配置host-only共享win7上网,配置失败,所以只能使用Centos的 DVD 光盘来配置yum软件源。不然就没得完了。

1. 首先要在virtual box 中的插入DVD的iso光盘,相信这一步,大家都会,不然如何在virtual box 安装centos呢?

2. 挂载 iso 光盘
第一步之后,我们发现执行 df 命令,尽然没有看到我们上面挂载的 iso 光盘,这是怎么回事呢?

[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 。

相关内容