Linux挂载本地ISO镜像源

本文介绍了如何在Linux系统中创建挂载目录,上传并挂载ISO镜像,以及编辑YUM仓库文件以添加本地镜像源。步骤包括创建目录、上传文件、使用`mount`命令挂载镜像,并配置`/etc/yum.repos.d/CentOS-Base.repo`以利用新挂载的镜像源。

1 创建挂载镜像的目录

mkdir /opt/rpm

2 上传iso镜像到root目录

3 挂载镜像

mount -t iso9660 /root/CentOS-7-x86_64-DVD-2207-02.iso /opt/rpm/

4 若是ftp文件夹挂载本地

mkdir /opt/iso
将ftp上software/caozuoxitong目录挂载到本地/opt/iso/ 目录
mount -t cifs //172.xxx.22.111/software/caozuoxitong /opt/iso/ -o username=root,password=password,iocharset=utf8

然后在执行mount -t iso9660 /opt/iso/CentOS-7-x86_64-DVD-2207-02.iso /opt/rpm/

5 编辑/etc/yum.repos.d/CentOS-Base.repo

# CentOS-Base.repo
#
# The mirror system uses the connecting IP address of the client and the
# update status of each mirror to pick mirrors that are updated to and
# geographically close to the client.  You should use this for CentOS updates
# unless you are manually picking other mirrors.
#
# If the mirrorlist= does not work for you, as a fall back you can try the 
# remarked out baseurl= line instead.
#
#

[base]
name=CentOS-$releasever - Base
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=os&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#released updates 
[updates]
name=CentOS-$releasever - Updates
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=updates&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=extras&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus
mirrorlist=http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=centosplus&infra=$infra
#baseurl=http://mirror.centos.org/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

#新增挂载
[local-rpms]
name=localrpms
baseurl=file:///opt/rpm
gpgcheck=0
enabled=1

6 最后执行yum makecache

在这里插入图片描述

Linux系统中挂载本地镜像作为yum源,可按以下步骤操作: ### 准备镜像文件 将镜像上传到服务器的自定义目录,例如上传到`/opt`目录 [^1]。 ### 挂载镜像 1. 建立挂载的目录,如创建`/media/CentOS7`目录: ```bash mkdir /media/CentOS7 ``` 2. 挂载镜像,使用以下命令将`/opt`目录下的镜像挂载到`/media/CentOS7`目录: ```bash mount -t iso9660 -o loop /opt/CentOS-7-x86_64-Everything-2009.iso /media/CentOS7 ``` 执行上述命令后,可能会提示“写保护,将以只读方式挂载”,这属于正常情况 [^1]。 ### 查看挂载情况 可使用`df -h`等命令查看镜像是否成功挂载。 ### 编辑repo文件 编辑`/etc/yum.repos.d/local.repo`文件,添加以下内容: ```plaintext [CentOS7-Localsource] name=CentOS7 baseurl=file:///media/CentOS7 enabled=1 gpgcheck=0 ``` 其中,`[CentOS7-Localsource]`为仓库的标识;`name`是仓库的描述;`baseurl`为镜像挂载的路径;`enabled=1`表示启用该仓库;`gpgcheck=0`表示不校验软件包的签名 [^1]。 ### 生成yum缓存 配置完成后,需要清理旧的yum缓存并生成新的缓存: ```bash yum clean all yum makecache ``` ### 不同操作示例 还有另一种挂载及配置方式: 1. 新建目录`/mnt/iso`用于放置原始镜像文件,`/mnt/cdrom`用于挂载镜像: ```bash mkdir -p /mnt/iso mkdir -p /mnt/cdrom ``` 2. 将镜像文件`CentOS-7-x86_64-Minimal-2009.iso`上传到`/mnt/iso`文件夹下。 3. 挂载镜像: ```bash mount -o loop /mnt/iso/CentOS-7-x86_64-Minimal-2009.iso /mnt/cdrom ``` 若要取消挂载,可使用`umount /mnt/cdrom`命令 [^2]。 4. 备份yum源: ```bash cd /etc/yum.repos.d mkdir bak mv *.repo bak ``` 5. 配置本地yum源,编辑`/etc/yum.repos.d/local.repo`文件 [^3]。 ### 另一种repo文件示例 编辑`/etc/yum.repos.d/cos7-local.repo`文件,内容如下: ```plaintext [cos7-local] name=cos7-local baseurl=file:///media/ enabled=1 gpgcheck=0 ``` 这里的`baseurl`要和镜像挂载的目录对应 [^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值