LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 595|回复: 1

[zt]Apt-Pinning for Beginners

[复制链接]
发表于 2005-8-24 20:38:47 | 显示全部楼层 |阅读模式
google上找到的,感觉不错,转来让兄弟们看看

http://jaqque.sbih.org/kplug/apt-pinning.html


  1. Apt-Pinning for Beginners
  2. Why apt-pinning?

  3. Do you run Debian? Have you ever gotten annoyed at how Debian Stable always seems to be out of date?

  4. I will show you a way that you can have apt mix-and-match between Stable, Testing, and Unstable sources. This will allow you to run a mostly-Stable system, but also track the latest and greatest of those packages that you are most keenly interested in.

  5. Why do this? Stable is covered by the Security Team. Testing and Unstable are not. For non-critical services, like perhaps your mailer, or your window manager, this is not so important, and the newest versions may have additional features that are desired. It is these packages that are perfect for pinning to a version, other than Stable.
  6. sources.list

  7. The first step is to set up your /etc/apt/sources.list to include your typical Stable, plus the Testing/Unstable sources that you want.

  8. A simple sources.list may look like this:

  9. #Stable
  10. deb http://ftp.us.debian.org/debian stable main non-free contrib
  11. deb http://non-us.debian.org/debian-non-US stable/non-US main contrib non-free

  12. #Testing
  13. deb http://ftp.us.debian.org/debian testing main non-free contrib
  14. deb http://non-us.debian.org/debian-non-US testing/non-US main contrib non-free

  15. #Unstable
  16. deb http://ftp.us.debian.org/debian unstable main non-free contrib
  17. deb http://non-us.debian.org/debian-non-US unstable/non-US main contrib non-free

  18. You would probably want to add your mirrors, security.debian.org, and perhaps the appropriate deb-src lines. Here is a copy of my actual sources.list.
  19. preferences

  20. The next step is to create/edit your /etc/apt/preferences file. preferences is where the apt-pinning takes place. Normally, the highest version of an available package wins, but we will override that.

  21. A simple preferences file may look like this:

  22. Package: *
  23. Pin: release a=stable
  24. Pin-Priority: 700

  25. Package: *
  26. Pin: release a=testing
  27. Pin-Priority: 650

  28. Package: *
  29. Pin: release a=unstable
  30. Pin-Priority: 600

  31. Note the decending values. Since Stable has the highest pin-priority, it will be installed preferentially over Testing or Unstable.

  32. My actual preferences file is what you see above.
  33. apt-get update

  34. Now we are ready to apt-get update. This will add the new repositories to apt's list.
  35. E: Dynamic MMap ran out of room

  36. You may find that you receive an error like the following:

  37. E: Dynamic MMap ran out of room
  38. E: Error occured while processing sqlrelay-sqlite (NewPackage)
  39. E: Problem with MergeList /var/lib/apt/lists/ftp.us.debian.org_debian_dists_woody_contrib_binary-i386_Packages
  40. E: The package lists or status file could not be parsed or opened.

  41. This is caused because apt's cache is too small to handle all of the packages that are included with stable, testing, and unstable. This is also very easy to fix. Add the following line to /etc/apt/apt.conf

  42. APT::Cache-Limit "8388608";

  43. Thanks to R (Chandra) Chandras for pointing out this problem
  44. Installing new packages

  45. To install a new package, it is just as it ever was, apt-get install <package>. If the package exists in Stable, then that is what it will grab. If the package exists only in Unstable, then from Unstable it will be gotten.

  46. What if the package exists in both Stable and Unstable, but we want the Unstable version? There are two ways we can do that, each with a slightly different syntax, and each with a slightly different effect.

  47.     * apt-get install <package>/unstable

  48.       This will install the unstable version of the package, and try to meet any dependencies from Stable. This may not work, but it will tell you why:

  49. # apt-get install zsh/unstable
  50. Reading Package Lists... Done
  51. Building Dependency Tree... Done
  52. Selected version 4.0.6-7 (Debian:unstable) for zsh
  53. Some packages could not be installed. This may mean that you have
  54. requested an impossible situation or if you are using the unstable
  55. distribution that some required packages have not yet been created
  56. or been moved out of Incoming.

  57. Since you only requested a single operation it is extremely likely that
  58. the package is simply not installable and a bug report against
  59. that package should be filed.
  60. The following information may help to resolve the situation:

  61. Sorry, but the following packages have unmet dependencies:
  62.   zsh: Depends: libc6 (>= 2.2.5-13) but 2.2.5-11.1 is to be installed
  63. E: Sorry, broken packages

  64.     * apt-get -t unstable install <package>

  65.       This will install the Unstable version of the package, and try to meet any dependencies from Unstable. This may produce better results.

  66. # apt-get -t unstable install zsh   
  67. Reading Package Lists... Done
  68. Building Dependency Tree... Done
  69. The following extra packages will be installed:
  70.   libc6 libc6-dev libc6-pic libdb1-compat locales
  71. The following NEW packages will be installed:
  72.   libdb1-compat
  73. 5 packages upgraded, 1 newly installed, 0 to remove and 394  not upgraded.
  74. Need to get 11.6MB of archives. After unpacking 606kB will be used.
  75. Do you want to continue? [Y/n]

  76. That's it!

  77. Armed with a complete sources.list and a minimal preferences, you can go ahead and mix-and-match between the various Debian releases.

  78. Have fun!

复制代码



也可看看 http://www.argon.org/~roderick/apt-pinning.html


  1. Using APT with more than 2 sources

  2. APT's Default-Release setting (aka apt-get --target-release) is useful if your /etc/apt/sources.list file contains exactly 2 releases (such as stable and testing, or testing and unstable). If you want to track more than 2 releases (stable, testing, and unstable, or two of those plus a non-Debian source), it has problems. This document explains how to do better. Updates can be found at http://www.argon.org/~roderick/apt-pinning.html.
  3. Improved /etc/apt/preferences File

  4. First, here are some reasonable /etc/apt/preferences files for the common cases. The rest of this document describes what these are doing.

  5.     * Track stable:

  6. Explanation: see http://www.argon.org/~roderick/apt-pinning.html
  7. Package: *
  8. Pin: release o=Debian,a=stable
  9. Pin-Priority: 900

  10. Package: *
  11. Pin: release o=Debian,a=testing
  12. Pin-Priority: 400

  13. Package: *
  14. Pin: release o=Debian,a=unstable
  15. Pin-Priority: 300

  16. Package: *
  17. Pin: release o=Debian
  18. Pin-Priority: -1

  19.     * Track testing:

  20. Explanation: see http://www.argon.org/~roderick/apt-pinning.html
  21. Package: *
  22. Pin: release o=Debian,a=testing
  23. Pin-Priority: 900

  24. Package: *
  25. Pin: release o=Debian,a=unstable
  26. Pin-Priority: 300

  27. Package: *
  28. Pin: release o=Debian
  29. Pin-Priority: -1

  30. "apt-get --default-release" Has No Memory

  31. When you run "apt-get -t unstable install foo", this sets APT::Default-Release for this invocation of apt-get, but it doesn't affect future runs. This is useful in some circumstances, but problematic in others.
  32. The Good

  33. Say you've got testing and unstable in your sources.list, an APT::Default-Release of "testing" in apt.conf, no /etc/apt/preferences, and a package foo which is available from the releases like this:

  34. release         version         priority
  35. no -t switch         -t unstable
  36. testing         1.1         990         500
  37. unstable         1.2         500         990

  38. If foo isn't installed and you run "apt-get install foo" you get version 1.1 from testing, since that version has the highest priority.

  39. If you run "apt-get -t unstable install foo" instead you get version 1.2 from unstable, since the -t switch temporarily causes that version to have the highest priority.

  40. foo will temporarily track unstable. If version 1.3 is uploaded to unstable while 1.1 is still in testing, we have:

  41. release         version         priority
  42. installed         1.2         100
  43. testing         1.1         990
  44. unstable         1.3         500

  45. The highest priority version is 1.1, but this is lower than the installed 1.2. Since the priority of 1.1 is 990 (which is lower than 1000), apt-get will not downgrade to it. The next highest priority is 1.3 at 500. Since this is greater than the installed 1.2, it is selected.

  46. foo will stop tracking unstable as soon as testing gets a version which is as new as the version which is currently installed. Say that version 1.3 migrates from unstable to testing, and then 1.4 is uploaded to unstable:

  47. release         version         priority
  48. installed         1.3         100
  49. testing         1.3         990
  50. unstable         1.4         500

  51. Since the unstable 1.4 version now has a lower priority than the installed version, foo is not upgraded to it. Often this is what you want.
  52. The Bad

  53. APT::Default-Release's behavior works well when you're only tracking two different releases, but with 3 or more it starts to go wrong. When you install a package from 1 of the non-default releases, it can be immediately replaced with a newer version from another of them.

  54. Consider:

  55. release         version         priority
  56. APT::Default-Release         above /etc/apt/preferences
  57. stable         1.0         990         900
  58. testing         1.1         500         400
  59. unstable         1.2         500         300

  60. With an APT::Default-Release of "stable" and no /etc/apt/preferences, if you install the package with "apt-get -t testing install foo" you'll get version 1.1 from testing.

  61. The big problem happens when you run "apt-get upgrade": Version 1.2 from unstable has the same priority as the 1.1 just installed, so 1.1 (testing) is replaced with 1.2 (unstable)!

  62. I fix this problem by giving testing and unstable different priorities. With the explicit PINs from the above /etc/apt/preferences, version 1.2 from unstable has priority 300 compared to testing's 400, so the version from testing remains installed.

  63. The pin of other Debian releases at priority -1 is only a bit of defensiveness. This doesn't affect any Debian sources that I know of (since they're all stable, testing, or unstable), so if a new Debian source is added I'll have to decide what priority to give it. Without this pin it'd come in at the default priority of 500.
  64. Using Non-Debian Sources

  65. If you're using non-Debian sources, you've got the same problem, only more so because there's no natural ordering as there is with Debian's stable -> testing -> unstable. Without explicitly listing them in /etc/apt/preferences, they're all at priority 500, so a package installed from one source can be replaced by a higher version supplied by a different source.

  66. A partial fix for this is to pin each source at a different priority. Eg,

  67. Package: *
  68. Pin: origin marillat.free.fr
  69. Pin-Priority: 600

  70. Package: *
  71. Pin: origin www.ibiblio.org
  72. Pin-Priority: 610

  73. Package: *
  74. Pin: origin www.argon.org
  75. Pin-Priority: 620

  76. These settings would mean that a package installed from www.argon.org wouldn't automatically be replaced with one from the other two, and one from www.ibiblio.org wouldn't be replaced with one from marillat.free.fr.

  77. Working in the other direction the packages would still be replaced, however: If you've installed a package from www.ibiblio.org and a newer version becomes available from www.argon.org, apt-get will upgrade to it. The only way I know of to prevent that is to explicitly pin the package to the source via /etc/apt/preferences.

  78. Roderick Schertler <roderick@argon.org>
  79. http://www.argon.org/~roderick/
复制代码
发表于 2006-6-13 12:11:11 | 显示全部楼层
非常不错,正需要这个。
谢谢拉哈。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表