自己定制OpenVZ的操作系统模版

简介: Creating a CentOS 5.0 Template Install a system (virtual or physical) with the default CentOS installation that you wish to package.

Creating a CentOS 5.0 Template

  1. Install a system (virtual or physical) with the default CentOS installation that you wish to package. This could be a minimal distro or the default distro or even something custom.
    1. It's generally quicker to bootstrap a CentOS system on another yum/rpm-based, or Debian based system by following the instructions in [1]
  2. Once the OS has been installed, you need to tar the contents of the OS.
    1. First, create a file called /tmp/exclude and add the following lines to it:
    .bash_history
    lost+found
    /dev/*
    /mnt/*
    /tmp/*
    /proc/*
    /sys/*
    /usr/src/*
    1. Now, tar the OS file up by typing: tar --numeric-owner –czvf /tmp/centos-5.0---image.tar.gz –X /tmp/exclude / where ARCH> represents the system architecture (i386 or
    x86_64) and DISTRO> represents the distribution (default, minimal, etc.).
    1. Now transfer the file over to the OpenVZ server into /vz/template/cache folder.
  3. On the OpenVZ server create a “dummy” container by creating a folder called /vz/private/50
    and copying the /etc/vz/conf/ve-vps.basic.conf-sample to /etc/vz/conf/50.conf.
    NOTE: 50 is the CTID for the container. You can choose any unused CTID on the OpenVZ server.
  4. Now create a new folder called /vz/template/centos/5//config again where
    ARCH> represents the system architecture.
  5. Create a file in the folder called rpm and add the following line:
    43
  6. Create a file called yum.conf in the folder and add the following lines:
    [main]

    cachedir=/vz/template/centos/5//yum-cache/

    reposdir=/dev/null

    installonlypkgs=

    [centos5-base]
    name=CentOS 5 - - Base

    baseurl= http://mirror.centos.org/centos/5/os//

    enabled=1

    gpgcheck=1

    [centos5-updates-released]

    name=CentOS 5 - - Released Updates

    baseurl= http://mirror.centos.org/centos/5/updates//

    enabled=1

    gpgcheck=1
  7. Copy /etc/vz/dists/centos-4.conf to /etc/vz/dists/centos-5.conf.
  8. Copy /vz/template/centos/4/i386/config/minimal.list to /vz/template/centos/5/i386/config/minimal.list.
  9. Change to the /vz/private/50 folder and then run the command gunzip –dc /vz/template/cache/centos-5---image.tar.gz | tar –xvf – to unpack the base image to the folder.
  10. Make sure you are in the /vz/private/50 folder.
  11. Edit etc/shadow and remove the replace the root password with !! instead of the hashed value.
  12. Edit the etc/inittab file and comment out the lines that respawn /sbin/mingetty on tty1 through tty6. Just put a # at the beginning of the line.
  13. Remove the etc/mtab file and then create a symbolic link by typing ln -s /proc/mounts etc/mtab.
  14. Remove all of the lines from etc/fstab except for the line that mounts /dev/pts.
  15. Edit etc/rc.d/rc.sysinit and comment out the line that starts /sbin/start_udev by placing a # at the beginning of the line.
  16. Now create device nodes by typing:
    mknod dev/ptmx c 5 2
    mkdir dev/pts
    /sbin/MAKEDEV –d /vz/private/50/dev ttyp ptyp
    mknod dev/null c 1 3
    mknod -m 644 dev/random c 1 8
    mknod dev/urandom c 1 9
  17. Create the var/lock/rpm folder.
  18. If you wish to disable IPv6, do the following:
    1. Edit etc/sysconfig/network and set NETWORKING_IPV6 to no.
    2. Add the following lines to etc/modprobe.d/blacklist:
    blacklist ipv6
    blacklist net-pf-10
  19. Disable any physical NICs by modifying the etc/sysconfig/network-scripts/ifcfg-ethX files (where X is the interface number starting from 0) and setting ONBOOT to no.
  20. Now you’re ready to start the template. Type vzctl start 50 and wait for it to start.
  21. You can install additional packages into the container by typing vzyum 50 install at the prompt where package> represents the name of the software package you wish to install.
  22. Finally, you should turn off unnecessary services.
    1. Enter the container by typing vzctl enter 50.
    2. View the services that are set to run at startup by typing chkconfig --list | grep 5:on.
    3. Disable any unwanted service by typing chkconfig --levels 2345 off where service> represents the service to disable.
    Services that you can (and should) turn off without harm are acpid, apmd, kudzu, and microcode_ctl.
  23. Exit the container by typing exit at the prompt.
  24. Stop the container by typing vzctl stop 50.
  25. Make sure you are in the /vz/private/50 folder.
  26. Finally, package up the new template by typing tar –czvf /vz/template/cache/centos-5--.tar.gz ./.
  27. The template is ready for use.
文章来自于这篇文档,http://wiki.openvz.org/Creating_a_CentOS_5.0_Template
下一步就是亲自试一下,然后加入注释和自己的注解,请大家稍等。。。。。。 005.gif
相关文章
|
2月前
|
Linux 数据安全/隐私保护 虚拟化
如何在 VM 虚拟机中安装 Kail Linux 2023.4 操作系统保姆级教程(附链接)
如何在 VM 虚拟机中安装 Kail Linux 2023.4 操作系统保姆级教程(附链接)
|
2月前
|
存储 编译器 Linux
操作系统相关问题——应用程序和操作系统怎么配合
应用程序和操作系统都是软件, CPU会将它们一视同仁,甚至CPU不知道自己在执行的程序是操作系统还是一般应用软件。CPU只知道去cs:ip寄存器中指向的内存取出指令并执行,它不知道什么是操作系统。
|
缓存 前端开发 Linux
Linux中应用程序的安装和管理程序
Linux中应用程序的安装和管理程序
Linux中应用程序的安装和管理程序
|
Linux Apache 数据安全/隐私保护
14.3 Linux独立服务管理
我们知道,RPM 包默认安装的服务分为独立的服务和基于 xinetd 的服务,本节来学习独立服务的管理。
119 0
14.3 Linux独立服务管理
|
分布式计算 Oracle 关系型数据库
硬核!!教你如何通过脚本自动部署虚拟机并安装操作系统
硬核!!教你如何通过脚本自动部署虚拟机并安装操作系统
475 0
硬核!!教你如何通过脚本自动部署虚拟机并安装操作系统
|
安全 Linux 程序员
除了LINUX,我们真的有可选的第二开源操作系统吗?
当你面临需要重新选择一门新操作系统的问题时,可能你是个不常使用PC常用手机的业外人士,即使正有一种力量正在劝导你弃用现在的windows或linux时,你也会对此不屑一顾,
659 0
除了LINUX,我们真的有可选的第二开源操作系统吗?
|
Java 中间件 Unix
一个设想:基于colinux,去厚重虚拟化,共盘直接文件系统安装运行的windows,linux
关键字:uniform windows,linux diskbios,虚拟机作为装机系统,元操作系统host,共用盘windows,linux设计。。diskbios,带iaas的云装机。。
391 0
一个设想:基于colinux,去厚重虚拟化,共盘直接文件系统安装运行的windows,linux