VMware虚拟机Centos7配置本地Yum源并开机自动挂载

1.首先要确认,iso镜像已经挂载,进入虚拟机设置里确认一下

在这里插入图片描述

2.创建一个挂载目录

[root@rac1 ~]# mkdir /mnt/cdrom

3.完成挂载

[root@rac1 ~]# mount -t iso9660 /dev/cdrom /mnt/cdrom

4.备份repo文件

mkdir /etc/yum.repos.d/bak -p
mv /etc/yum.repos.d/* /etc/yum.repos.d/bak

5.创建/etc/yum.repos.d/local.repo本地文件

[root@rac1 ~]# touch /etc/yum.repos.d/local.repo 
##文件内容
[local]
name=CentOS7-local
baseurl=file:///mnt/cdrom/
enabled=1
gpgcheck=0

6.查看yun源列表,看看是否创建成功

[root@rac1 ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                              repo name                                   status
local                                CentOS7-local                               10,019
repolist: 10,019

7.清除以前的yum源留下的缓存

[root@rac1 ~]# yum clean all
Loaded plugins: fastestmirror
Cleaning repos: local
Cleaning up list of fastest mirrors
Other repos take up 112 M of disk space (use --verbose for details)

8.创建新yum源缓存

[root@rac1 ~]# yum makecache
Loaded plugins: fastestmirror
Determining fastest mirrors
local                                                           | 3.6 kB  00:00:00     
(1/4): local/group_gz                                           | 166 kB  00:00:00     
(2/4): local/primary_db                                         | 6.0 MB  00:00:00     
(3/4): local/other_db                                           | 2.6 MB  00:00:00     
(4/4): local/filelists_db                                       | 7.1 MB  00:00:00     
Metadata Cache Created

9.开机自动挂载

为了一劳永逸,我们再配置一下开机自动挂载。编辑etc下的fstab,添加:

/dev/cdrom      /mnt/cdrom                      iso9660 defaults        0 0
Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐