免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1225 | 回复: 0
打印 上一主题 下一主题

debootstrap 备忘 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2006-02-25 12:06 |只看该作者 |倒序浏览

               
               
               
               
               
                原文地址:https://wiki.ubuntu.com/DebootstrapChroot
目的:建立一个 ubuntu 的chroot环境。
1 安装所需的包
debootstrap 是一个用来建立 chroot 环境的工具,可在此 chroot 环境中测试软件,建立包,运行特定服务等等任务。
下边的地址可下载到 debootstrap 的安装包:
http://archive.ubuntu.com/ubuntu/pool/main/d/debootstrap/debootstrap_0.3.1.4ubuntu4_all.deb
然后安装:
sudo dpkg --install debootstrap_0.3.3.0ubuntu4_all.deb
dchroot 是一个方便的管理 chroot 环境的工具。
   sudo apt-get install dchroot
   
2 设置基本 chroot
  
  这里假定使用 /home/chuangxin/chroot 目录作为欲建立的 chroot 位置。
  $ mkdir /home/chuangxin/chroot
  $ sudo vi /etc/dchroot.conf  # 编辑此文件并加入一行  mychroot  /home/chuangxin/chroot
  注意:将 /home/chuangxin/chroot 替换为你自己的 chroot目录
  使用 debootstrap 配置环境,如果想在一个64位机建立一个32位环境,添加 --arch i386, 如果想在
chroot 中创建 .deb 包,添加 --variant=buildd。可以改变 brezzy 为 warty , hoary ,
dapper (它们都是ubuntu 特定发行版的代号)。
  debootstrap breezy /home/chuangxin/chroot/ http://debian.cn99.com/ubuntu/

  运行上边的命令后,debootstrap 将从 http://debian.cn99.com/ubuntu
获取最基本的软件包,并在 /home/chuangxin/chroot 中建立一个基于 ubuntu brezzy 的 chroot 环境。
  为了能够更新 chroot 环境,拷贝两个主机文件:
  $ sudo cp /etc/resolv.conf /home/chuangxin/chroot/etc/
   $ sudo cp /etc/apt/sources.list /home/chuangxin/chroot/etc/apt/sources.list
  切换到临时环境:
   $ sudo chroot /home/chuangxin/chroot  /bin/bash
  更新环境并安装创建 .deb 包必须的软件包(注意:下面的操作是在 chroot 环境中)。
   # apt-get update
   # apt-get install wget debconf devscripts gnupg
   # apt-get update
   # apt-get install locales dialog
   # dpkg-reconfigure locales # reconfigure locale
   # tzconfig # reconfigure time zone
   # exit   
   
  附加:如果想在 ubuntu 主系统中建立一个 debian 的 chroot 环境,可以指定一个debian仓库:
   # sudo  debootstrap  --arch i386 sid sid/  http://ftp.uk.debian.org/debian/
  如果只是想设置一个简单的 chroot 环境,那么到此结束。
  但是如果想让非 root 用户也可以使用此 chroot 环境,并且能访问真实环境的 /home 目录,那进行得进行更多的设置。
3 更多设置
首先复制及修改一些必要的东西:
sudo cp /etc/passwd /home/chuangxin/chroot/etc/
sudo sed 's/\([^:]*\):[^:]*:/\1:*:/' /etc/shadow | sudo tee /home/chuangxin/chroot/etc/shadow
sudo cp /etc/group /home/chuangxin/chroot/etc/
sudo cp /etc/hosts /home/chuangxin/chroot/etc/ # avoid sudo warnings when it tries to resolve the chroot's hostname
  接着设置 sudo 环境,及 root 和 第一个可以sudo 的用户密码:
sudo cp /etc/sudoers /home/chuangxin/chroot/etc/
sudo chroot /home/chuangxin/chroot/
dpkg-reconfigure passwd
passwd
  安装 sudo 包:
apt-get install sudo
exit
接下来,编辑主机系统的 /etc/fstab 文件并加入如下内容:
/home           /home/chuangxin/chroot/home        none    bind            0       0
/tmp            /home/chuangxin/chroot/tmp         none    bind            0       0
/media/cdrom    /home/chuangxin/chroot/media/cdrom none    bind            0       0
/dev            /home/chuangxin/chroot/dev         none    bind            0       0
proc-chroot     /home/chuangxin/chroot/proc        proc    defaults        0       0
devpts-chroot   /home/chuangxin/chroot/dev/pts     devpts  defaults        0       0
挂载试试:
  sudo mount -a
为 chroot 环境的 命令行 增加一个提示:
  sudo chroot /var/chroot/
  echo mychroot > etc/debian_chroot
  exit
使用 dchroot 切换进入 mychroot 所指代的 chroot (/etc/dchroot.conf 中指定):   
  dchroot -c mychroot -d
   ( -c DIR :指定要进入的 chroot 位置。 -d 指定在进入 chroot 后保留宿主的环境变量 )
               
               
               
               
               
               
               
               
               
               
               
               

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/11826/showart_78383.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP