Linux 为另一个分区/目录运行 apt-get?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3954584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Running apt-get for another partition/directory?
提问by Avall
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:
我已经从实时 Ubuntu CD 启动了我的系统,我需要修复一些软件包问题。我已经安装了我的硬盘,现在我想像正常启动一样运行 apt-get。即更改 apt-get 的工作目录,以便它可以在我的硬盘上工作。我以前这样做过,但我不记得语法。我认为这只是一些标志,如下所示:
apt-get --root-directory=/mnt/partition1 install....
But I only get "Command line option...is not understood". Any ideas?
但我只得到“命令行选项......不明白”。有任何想法吗?
采纳答案by Paulo Scardine
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).
如果您的系统使用多个磁盘分区,您可能必须安装其中的一些分区才能使软件包系统正常工作(10 年前,当硬盘开始变得太大而无法进行原始物理备份时,我停止了设置多个分区)。
This wouldn't work if you don't already have a usable debian system in that location. – akostadinov
如果您在该位置还没有可用的 debian 系统,这将不起作用。– 阿科斯塔迪诺夫
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.
如果您在 chroot 时无法使软件包系统正常工作,则可能它太混乱而无法再次信任 - 根据我的经验,将其恢复生机的努力很少有回报。如果发生这种情况,很高兴您仍然可以访问您的 HD,备份您的数据并执行干净的重新安装。
Some relevant comments from other answer:
来自其他答案的一些相关评论:
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
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 -o RootDir=/tmp/test_apt 设置(几乎)所有路径都在不同的根目录中。顺便说一句,在正在运行的系统上,如果您复制 /etc/apt、/usr/lib/apt 和 mkdir -p usr/lib etc 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 选项是必需的,因为我找不到在不同根目录中设置锁定文件的方法。– 阿科斯塔迪诺夫
工作是指使用搜索和下载包等操作。如果一些必要的软件包不存在,则实际上无法安装。如果目标实际上是出于任何原因在新根目录中安装软件包,则 debootstrap 可以提供帮助。– 阿科斯塔迪诺夫
回答by Jander
Running chroot /mnt/partition1
will start a new shell in which the root of the filesystem is /mnt/partition1
. Assuming the apt-get
on your hard drive still works correctly, you can proceed from there.
运行chroot /mnt/partition1
将启动一个新的 shell,其中文件系统的根目录是/mnt/partition1
. 假设apt-get
您的硬盘驱动器上的 仍然正常工作,您可以从那里继续。
dpkg --root=/mnt/partition1 -i mypackage.deb
is an option that doesn't require chroot
, but does require you to download the package yourself.
dpkg --root=/mnt/partition1 -i mypackage.deb
是一个不需要的选项chroot
,但需要您自己下载软件包。
回答by enzotib
Also this should work:
这也应该有效:
sudo apt-get -o Dir=/media/partitioni1 update