以红帽为例,创建好虚拟机后依次进行以下操作:
第一步:准备,检查光盘连接,切换到root用户以便进行后续操作
第二步:查看光盘名称 :
[root@localhost ~]# ls -l /dev | grep cdrom
lrwxrwxrwx. 1 root root 3 Sep 4 08:35 cdrom -> sr0
crw-rw----+ 1 root cdrom 21, 0 Sep 4 08:24 sg0
brw-rw----+ 1 root cdrom 11, 0 Sep 4 08:35 sr0
可得光盘名称为 sr0
第三步:创建一个新的目录
[root@localhost ~]# mkdir /mnt/cdrom
第四步:把光盘挂载到创建的空文件夹下
[root@localhost ~]# mount /dev/sr0 /mnt/cdrom
#查看挂载情况
[root@localhost ~]# ls /mnt/cdrom/
AppStream EULA images RPM-GPG-KEY-redhat-beta
BaseOS extra_files.json isolinux RPM-GPG-KEY-redhat-release
EFI GPL media.repo TRANS.TBL
由此可得到AppStream和BaseOS写入仓库中
第五步:编辑仓库配置文件
[root@localhost ~]# vi /etc/yum.repos.d/rpm.repo
[BaseOS]
name=BaseOS
baseurl=file:///mnt/cdrom/BaseOS
gpgcheck=0
enabled=1
[AppStream]
name=AppStream
baseurl=file:///mnt/cdrom/AppStream
gpgcheck=0
enabled=1
baseurl 后面的路径中mnt/cdrom/为我们自己创建的目录BaseOS和AppStream可从第四步中获得
验证
[root@localhost ~]# yum install vim -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
baseos 0.0 B/s | 0 B 00:00
Errors during downloading metadata for repository 'baseos':
- Curl error (37): Couldn't read a file:// file for file:///mnt/cdrom/repodata/repomd.xml [Couldn't open file /mnt/cdrom/repodata/repomd.xml]
Error: Failed to download metadata for repo 'baseos': Cannot download repomd.xml: Cannot download repodata/repomd.xml: All mirrors were tried
[root@localhost ~]# vi /etc/yum.repos.d/rpm.repo
[root@localhost ~]# yum install vim -y
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
BaseOS 75 MB/s | 2.3 MB 00:00
AppStream 88 MB/s | 5.8 MB 00:00
Package vim-enhanced-2:8.0.1763-13.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
成功。