先介绍一下环境:
虚拟机:debian7.2.0
主机: Win7
方法一:
由于有时候无法联网就需要离线安装软件包,可以把debian官网上列出的几个DVD镜像都下下来,其实主要是DVD1,这样就不需要每次安装软件都得联网。
下面是我从Debian官网上下下来的DVD镜像:
debian-7.2.0-i386-DVD-1
debian-7.2.0-i386-DVD-2
debian-7.2.0-i386-DVD-3
在每张DVD中都有一个README.txt,其中有如下说明:
About This Disc
===============
This disc is labeled
Debian GNU/Linux 7.2.0 "Wheezy" - Official i386 DVD Binary-1
20131012-12:56
which means that this disc is number 1 of a set of 10 discs It
contains programs ("binaries") for `i386' computers.
The programs on the Binary discs are ordered by popularity. The
Binary-1 disc contains the most popular programs and the installation
tools; it is possible to install and run Debian with only the Binary-1
disc. The other discs, up to Binary-10, contain mostly
special-interest programs.
The Release Notes for "wheezy" are available on the Debian web site.
在DVD1中有关于Debian的安装手册,中文的手册路径是doc/manual/zh_CN/,其中也有关于DVD安装的介绍
CD(和 DVD) 里面包含的软件包按照流行程度排列次序。也就是说,第一张光盘里面是最常用的软件,而最后一张光盘里面包含的是很少有人用到的软件。
这也意味着购买或者下载刻录所有 CD 是一种浪费,因为大部分光盘您根本不会用到。多数情况下,只需要使用前 3 到 8 张 CD,然后从网络镜像安装其他要用的软件包。DVD 的情况类似:只要一张,或者前两张 DVD 就能满足您大部分要求。
根据经验,常见的桌面安装(使用 GNOME 桌面环境)只需要前三张 CD。其他的桌面环境(KDE 或 Xfce),就需要额外的 CD。而第一张 DVD 就可以轻松地满足所有的三种桌面环境。
下面开始安装:
先给虚拟机添加三个虚拟光驱,将刚下载的三个DVD镜像装入
如下图所示:(注意:由于已经安装了Debian7.2,所以我把DVD1放在了第二个,即第一IDE控制器从通道,将DVD2放在了第一IDE控制器主通道上,目的是防止每次启动时都自动进入Debian安装界面,DVD1中也有很多软件包)
由于添加了三个虚拟光驱,需要修改/etc/fstab,
修改为:
同时在/media目录下新建一个目录cdrom2,重启后系统就自动把DVD2挂载到/media/cdrom0,将DVD1挂载到/media/cdrom1,将DVD3挂载到/media/cdrom2下面,如下图:
挂载好之后,就可以修改/etc/apt/sources.list了,添加如下内容:
如果不知道路径后面写什么可以执行 apt-cdrom add,系统会自动搜索cdrom,并自动填写/etc/apt/sources.list文件,可以看他是怎么写的,使用apt-cdrom add这种方法,有事会出现无法找到软件包的问题。
最后就可以执行 apt-get update了。
方法二:
与方法一的不同点是,不用给虚拟机添加虚拟光驱,只要Linux能够识别放有光盘镜像的存储器就可以,比如我们把要用的几块光盘镜像放到Samba共享目录或者移动硬盘中,(对于使用移动硬盘的方案,Linux识别后系统会自动挂载如果没有,需要手动挂载)。
比如将移动硬盘挂载到了/media/work/下,光盘镜像的路径是:
/media/work/software/虚拟机/debian/debian6/dvd
其中的镜像如下:
pengdl@debian:/media/work/software/虚拟机/debian/debian6/dvd$ ls
debian-6.0.8-i386-DVD-1.iso debian-6.0.8-i386-DVD-5.iso debian-update-6.0.8-i386-DVD-1.iso
debian-6.0.8-i386-DVD-2.iso debian-6.0.8-i386-DVD-6.iso debian-update-6.0.8-i386-DVD-2.iso
debian-6.0.8-i386-DVD-3.iso debian-6.0.8-i386-DVD-7.iso
debian-6.0.8-i386-DVD-4.iso debian-6.0.8-i386-DVD-8.iso
在/media下创建几个用于挂载的目录,cdrom1 cdrom2 cdrom3 cdrom4 cdrom5 cdrom6 ....,为了说明问题,我们这里只创建cdrom1 cdrom2 cdrom3
pengdl@debian:/media$ ls
cdrom cdrom0 cdrom1 cdrom2 cdrom3 entertainment sf_share work
分别将DVD1~DVD4挂载到cdrom0~cdrom3下:
pengdl@debian:/media$ sudo mount -o loop /media/work/software/虚拟机/debian/debian6/dvd/debian-6.0.8-i386-DVD-1.iso ./cdrom0
pengdl@debian:/media$ sudo mount -o loop /media/work/software/虚拟机/debian/debian6/dvd/debian-6.0.8-i386-DVD-2.iso ./cdrom1 pengdl@debian:/media$ sudo mount -o loop /media/work/software/虚拟机/debian/debian6/dvd/debian-6.0.8-i386-DVD-3.iso ./cdrom2 pengdl@debian:/media$ sudo mount -o loop /media/work/software/虚拟机/debian/debian6/dvd/debian-6.0.8-i386-DVD-4.iso ./cdrom3 pengdl@debian:/media$ mount /dev/sda1 on / type ext3 (rw,errors=remount-ro) tmpfs on /lib/init/rw type tmpfs (rw,nosuid,mode=0755) proc on /proc type proc (rw,noexec,nosuid,nodev) sysfs on /sys type sysfs (rw,noexec,nosuid,nodev) udev on /dev type tmpfs (rw,mode=0755) tmpfs on /dev/shm type tmpfs (rw,nosuid,nodev) devpts on /dev/pts type devpts (rw,noexec,nosuid,gid=5,mode=620) /dev/sdc5 on /home type ext3 (rw) /dev/sdd1 on /home/pengdl/ext_disk type ext3 (rw) /dev/sdb5 on /usr type ext3 (rw) rpc_pipefs on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw) binfmt_misc on /proc/sys/fs/binfmt_misc type binfmt_misc (rw,noexec,nosuid,nodev) nfsd on /proc/fs/nfsd type nfsd (rw) share on /media/sf_share type vboxsf (gid=1001,rw) /dev/sde5 on /media/work type fuseblk (rw,allow_other,blksize=4096) /dev/sde1 on /media/entertainment type fuseblk (rw,allow_other,blksize=4096) /dev/loop0 on /media/cdrom0 type iso9660 (rw) /dev/loop1 on /media/cdrom1 type iso9660 (rw) /dev/loop2 on /media/cdrom2 type iso9660 (rw) /dev/loop3 on /media/cdrom3 type iso9660 (rw) pengdl@debian:/media$
修改sources.list
#deb http://192.168.8.64/debian6/debian squeeze main contrib non-free
#deb file:/home/pengdl/ext_disk/debian6_source/mirror/192.168.8.64/debian6/debian squeeze main contrib non-free
#deb http://192.168.253.130/debian squeeze main contrib non-free
#deb http://127.0.0.1 squeeze main contrib non-
#deb http://ftp.debian.org/debian/ squeeze main non-free contrib
#deb http://ftp.debian.org/debian/ squeeze-proposed-updates main non-free contrib
#deb http://mirrors.163.com/debian/ squeeze main non-free contrib
#deb http://mirrors.163.com/debian/ squeeze-proposed-updates main non-free contrib
#deb-src http://mirrors.163.com/debian/ squeeze main non-free contrib
#deb-src http://mirrors.163.com/debian/ squeeze-proposed-updates main non-free contrib
deb file:///media/cdrom0 squeeze main contrib
deb file:///media/cdrom1 squeeze main contrib
deb file:///media/cdrom2 squeeze main contrib
deb file:///media/cdrom3 squeeze main contrib
注意 :
为什么要填写 squeeze main contrib,而没有non-free,因为
pengdl@debian:/media/cdrom1$ ls
css debian dists firmware md5sum.txt pics pool README.html README.mirrors.html README.mirrors.txt README.txt
pengdl@debian:/media/cdrom1$ cd dists/
pengdl@debian:/media/cdrom1/dists$ ls
oldstable squeeze
pengdl@debian:/media/cdrom1/dists$ ls -l
total 2
lr-xr-xr-x 1 root root 7 Oct 19 23:23 oldstable -> squeeze
dr-xr-xr-x 1 root root 2048 Oct 19 23:23 squeeze
pengdl@debian:/media/cdrom1/dists$ cd squeeze/
pengdl@debian:/media/cdrom1/dists/squeeze$ ls
contrib main Release
在squeeze下没有non-free目录。
最后执行sudo apt-get update 即可。
可以参考: