为另一个分区/目录运行apt-get? [英] Running apt-get for another partition/directory?

查看:102
本文介绍了为另一个分区/目录运行apt-get?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经从实时Ubuntu CD引导了系统,并且需要修复一些软件包问题.我已经安装了硬盘驱动器,现在我想像正常启动一样运行apt-get.即更改apt-get的工作目录,以便它将在我的硬盘上工作.我之前已经做过,但是我不记得语法了.我认为这只是一些标志,例如:

I have booted my system from a live Ubuntu CD, and I need to fix some package problems. I have mounted my hard drive, and now I want to run apt-get as if I booted normally. ie change the working directory for apt-get so it will work on my hard drive. I have done this before, but I can't remember the syntax. I think it was only some flag, like this:

apt-get --root-directory=/mnt/partition1 install....

但是我只得到命令行选项...不被理解".有什么想法吗?

But I only get "Command line option...is not understood". Any ideas?

推荐答案

chroot/mnt/partition1

chroot /mnt/partition1

如果您的系统使用多个磁盘分区,则可能必须安装其中的一些分区才能使软件包系统正常工作(十年前,当硬盘开始变得太大而无法进行原始物理备份时,我停止设置多个分区).

If your system uses several disk partitions you may have to mount some of them in order to get the package system working (I stopped setting up multiple partitions 10 years ago when hard disks started to get too large for raw physical backup).

如果您在该位置还没有可用的Debian系统,则此方法将无效.– akostadinov

This wouldn't work if you don't already have a usable debian system in that location. – akostadinov

如果您在chroot时无法使软件包系统正常工作,则可能是因为太混乱而无法再次信任它-以我的经验,将其重新投入使用的工作很少会付出任何代价.如果发生这种情况,很高兴您仍然可以访问HD,备份数据并执行干净的重新安装.

If you can't get the package system working when chrooting, perhaps it is too messed up to ever be trusted again - in my experience the effort to bring it back to life rarely pays. If that happens, be happy you can still access your HD, backup your data and perform a clean reinstall.

其他答案的一些相关评论:

Some relevant comments from other answer:

apt-get -o RootDir =/tmp/test_apt将(几乎)所有路径设置为不同的根目录.顺便说一句,如果您正在复制/etc/apt,/usr/lib/apt和mkdir -p usr/lib等var/cache var/lib/dpkg var/lib/apt/lists/partial var/cache/apt/archives/partial,最后触摸var/lib/dpkg/status,然后apt将在该根目录下工作.如果添加选项-o Debug :: NoLocking = 1,它甚至可以以非root用户身份工作.nolock选项是必需的,因为我找不到在不同的根目录中设置锁定文件的方法.– akostadinov

apt-get -o RootDir=/tmp/test_apt sets (almost) all paths to be in the different root. btw on a running system, if you copy /etc/apt, /usr/lib/apt, and mkdir -p usr/lib etc var/cache var/lib/dpkg var/lib/apt/lists/partial var/cache/apt/archives/partial and finally touch var/lib/dpkg/status, then apt is going to work in that root. It can even work as a non-root user if you add the option -o Debug::NoLocking=1. The nolock option is necessary because I couldn't find a way to set the lock file inside the different root directory. – akostadinov

工作是指使用搜索和下载包以及此类操作.如果某些基本软件包尚不存在,则实际上无法安装.如果目标实际上是出于任何原因将软件包安装在新的根目录中,则debootstrap可以提供帮助.– akostadinov

Work means using search and downloading packages and such operations. Actually installing is not possible if some essential packages are not already there. debootstrap can help if the goal is actually installing packages in a new root for whatever reason. – akostadinov

这篇关于为另一个分区/目录运行apt-get?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆