Ubuntu自制liveCD学习

如何定制 Ubuntu Live CD

Live CD 是伟大的,它使你能够不用安装就能够体验。它允许你在此之上运行你喜爱的程序,它还让手动恢复系统变得非常简单。

Ubuntu Live CD 已经与一些优秀的软件一起打包,你可以在 Live CD 上使用它,但是也有一些你不需要的软件也在其中,而你需要的软件可能没有。

有一个专业的解决办法就是自己去定制 Live CD 的映像文件

这个教程将逐步去定制一个 Ubuntu Live CD,删除其中的的一些组件和增加一些新的东西。

通过这个教程,我们将完成下面的细则重新制作一个我们自己的 Ubuntu 8.04 Live CD:

  • 删除非英语的语言包
  • 更新所有的软件包
  • 启用 universe 和 multiverse 软件包类
  • 安装 mp3 支持,RealPlayer
  • 安装 Firefox flash-nonfree 插件

定制后的映像文件可能会大于800M,所以我们不能再用CD了,而将用DVD。

1. 预备主机

首先,我们需要下载当前版本的 Ubuntu 8.04 Live CD 映像文件并把它保存到 ~/Desktop,还需要安装一些扩展的工具软件用于重新建造 Live CD 映像文件:

$ sudo apt-get install squashfs-tools chroot

现在我们开始设置工作环境,首先,我们挂载ISO映像到 /tmp/livecd :

$ mkdir /tmp/livecd
$ sudo mount -o loop ~/Desktop/ubuntu-7.10-desktop-i386.iso /tmp/livecd

接着我们创建一个工作目录和定制的 CD 目录,再把挂载后的 Live CD 中除了 filesystem.squashfs 以外的所有文件都复制到 ~/livecd/cd 目录中。:

$ mkdir ~/livecd
$ mkdir ~/livecd/cd
$ rsync --exclude=/casper/filesystem.squashfs -a /tmp/livecd/ ~/livecd/cd

这是复制 filesystem.squashfs 以外的所有文件,filesystem.squashfs 是 Live CD 中的压缩根文件系统。

现在我们挂载 caspter/filesystem.squashfs 到 ~/livecd/squashfs 目录,从而复制里面的所有文件到 ~/livecd/custom 目录中,这个目录将是我们定制的根文件系统,最后压缩打包成新的 filesystem.squashfs

$ mkdir ~/livecd/squashfs
$ mkdir ~/livecd/custom
$ sudo modprobe squashfs
$ sudo mount -t squashfs -o loop /tmp/livecd/casper/filesystem.squashfs ~/livecd/squashfs/
$ sudo cp -a ~/livecd/squashfs/* ~/livecd/custom

最后,让我们复制 /etc/resolv.conf 和 /etc/hosts 到 ~/livecd/custom/etc 以致于我们能够访问网络:

$ sudo cp /etc/resolv.conf /etc/hosts ~/livecd/custom/etc/

另外,我还复制了整个dpkg文件夹,然后在chroot之后,执行了apt-get install dpkg

2. 开始定制前准备

准备完成后,我们将 chroot 到 ~/livecd/custom 目录,挂载必要的虚拟文件系统 (/proc 和 /sys)。到这里,我们将开始定制我们的 Live CD。

$ sudo chroot ~/livecd/custom
# mount -t proc none /proc/
# mount -t sysfs none /sys/
# export HOME=/root

3. 开始定制

3.1. 删除不需要的软件包

先,我们将删除非英语的语言包和 gnome-games,以释放更多的空间。

# apt-get remove --purge gnome-games*
# apt-get remove --purge `dpkg-query -W --showformat='${Package}\n' | grep language-pack | egrep -v '\-en'`

或许你需要删除其它的软件包,你可以通过运行下面的命令查看安装了哪些软件包:

# dpkg-query -W --showformat='${Package}\n' | less

3.2. 更新所有的软件包

现在我们修改源配置文件和更新所有已安装的软件包:
打开并编辑 /etc/apt/sources.list

# vim /etc/apt/sources.list

如下:

deb http://old-releases.ubuntu.com/ubuntu/ maverick main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-security main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-updates main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu/ maverick-proposed main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-proposed main restricted universe multiverse

deb http://old-releases.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse
deb-src http://old-releases.ubuntu.com/ubuntu/ maverick-backports main restricted universe multiverse

保存以后,运行下面的命令更新软件包:

# apt-get update
# apt-get dist-upgrade

3.3. 安装新的软件包

我们安装所有的多媒体软件包:

# apt-get install gstreamer0.10-ffmpeg gstreamer0.10-plugins-ugly \
gstreamer0.10-plugins-ugly-multiverse gstreamer0.10-plugins-bad gstreamer0.10-plugins-bad-multiverse

接着下载(http://ftp.ubuntu.org.cn/home/aariz/realplayer_11.0.0-0.3_i386.deb 用户名:ubuntu 密码:ubuntuftp)并安装 RealPlayer:

# dpkg -i /tmp/realplay.deb

现在,我们安装一些压缩工具软件和Firefox的Flash插件:

# apt-get install rar unrar unace-nonfree flashplugin-nonfree

你还可安装一些自己需要的软件包,如中文语言支持包,中文软件法等, 这里就不一一讲解了。

4. 清除临时文件并退出 chroot

在我们安装软件包时,会使用一些临时文件,这里我们将他们清除来节省更多的空间:

# apt-get clean

同时也清除系统的临时目录中的文件:

# rm -rf /tmp/*

在 chroot 前,我们复制过两个文件(/etc/hosts 和 /etc/resolv.conf),这里也将其删除:

# rm -f /etc/hosts /etc/resolv.conf

最后,卸载两个虚拟文件系统 /proc 和 /sys,退出 chroot:

# umount /proc/
# umount /sys/
# exit

因为我们修改了一些软件包,所以我们需要重新创建 manifest 文件,重新创建 squashfs 和 ISO。

5. 重新创建映像文件

首先,重新创建 maniifest 文件。

$ chmod +w ~/livecd/cd/casper/filesystem.manifest
$ sudo chroot ~/livecd/custom dpkg-query -W --showformat='${Package} ${Version}\n' > ~/livecd/cd/casper/filesystem.manifest
$ sudo cp ~/livecd/cd/casper/filesystem.manifest ~/livecd/cd/casper/filesystem.manifest-desktop

接着重新创建 squashfs 根文件系统映像文件。

$ sudo mksquashfs ~/livecd/custom ~/livecd/cd/casper/filesystem.squashfs

现在,你还要自己定制 ~/livecd/cd/README.diskdefines 文件。 更新MD5校验文件 ~/livecd/cd/md5sum.txt

$ sudo rm ~/livecd/cd/md5sum.txt
$ sudo -s
# (cd ~/livecd/cd && find . -type f -print0 | xargs -0 md5sum > /tmp/md5sum.txt && mv /tmp/md5sum.txt .)

到这里,定制工作已经完成,下面就重新创建 ISO 映像文件:

$ cd ~/livecd/cd
$ sudo mkisofs -r -V "Ubuntu-Live-Custom" -b isolinux/isolinux.bin -c isolinux/boot.cat -cache-inodes -J -l -no-emul-boot \
-boot-load-size 4 -boot-info-table -o ~/Desktop/Ubuntu-Live-8.04-custom.iso .

打包完成后,不要急于刻录,而是到虚拟机(VMware 或 qemu)调试没有问题后,再刻录。

6. 结论

通过一系列的工作,我们定制出一个符合我们自己需要的 Ubuntu Live CD,这里只是简单的叙述一下大概的定制过程,还有很多的有意思的东西等你们自己去研究,如桌面风格的修改、在引导菜单里可以选择GUI与CLI模式、支持 presistent等等,这算就抛砖引玉吧。:)

This entry was posted in 默认分类 and tagged 原创 on 2008年09月25日.
  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值