更新套件時發生錯誤 [論壇 - Ubuntu 與 GNOME]


正在瀏覽:   1 名遊客


 到底部   前一個主題   下一個主題  [無發表權] 請登錄或者註冊



更新套件時發生錯誤
會員一級
註冊日期:
2014/1/25 11:45
所屬群組:
已註冊使用者
等級: 4
HP : 0 / 75
MP : 9 / 2145
EXP: 3
離線
小弟我sudo apt-get update

更新套件清單時發生錯誤如附圖

可以幫忙看一下 如何解決這個問題

感激不盡

附件:



png  2017-05-20 15-40-26 的螢幕擷圖.png (340.98 KB)
37626_591ff4f8e6056.png 1440X795 px

png  2017-05-20 16-42-46 的螢幕擷圖.png (303.90 KB)
37626_5920021916e7f.png 1440X795 px

2017/5/20 15:48
應用擴展 工具箱
回覆: 更新套件時發生錯誤
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 905
MP : 679 / 30304
EXP: 23
離線
================================================================================

以下測試環境「Xubuntu 16.04 amd64 英文界面」。

================================================================================

一些套件操作技巧的討論案例,紀錄在「[索引] 套件操作實務」。

================================================================================

先從您給的圖片,找到圖片裡面的頁面網址

* 「圖一」畫面的「網頁連結」。
* 「圖二」畫面的「網頁連結」。


## 「圖一」相關的指令

執行


$ ls /var/backups/dpkg.status* -l



顯示


-rw-r--r-- 1 root root 4264015 May 21 13:54 /var/backups/dpkg.status.0
-rw-r--r-- 1 root root 1154322 May 18 13:38 /var/backups/dpkg.status.1.gz
-rw-r--r-- 1 root root 1153023 May 16 17:17 /var/backups/dpkg.status.2.gz
...略...


執行


$ ls /var/lib/dpkg/status -l



顯示


-rw-r--r-- 1 root root 4263150 May 21 15:05 /var/lib/dpkg/status



執行


$ ls /var/lib/dpkg/status-old -l



顯示


-rw-r--r-- 1 root root 4264015 May 21 13:54 /var/lib/dpkg/status-old



執行


$ sudo cp /var/backups/dpkg.status.0 /var/lib/dpkg/status
$ sudo apt-get update



## 「圖二」相關的指令

執行


$ sudo apt-get install unattended-upgrades apticron



執行


$ sudo dpkg-reconfigure unattended-upgrades




================================================================================

關於「圖一」,

也不曉得在您的環境,發生狀況的關鍵因素會是什麼?
在我的環境「/var/lib/dpkg/status」和「/var/backups/dpkg.status.0」是存在的,請見上面的指令。

我沒有遇過這樣的情形,所以我也沒實際去處理的經驗,只有討論過相關的情形,

之前有一篇相關的討論「#12 回覆: 軟體中心無法安裝程式 (如何重建「/var/lib/dpkg/info」)」,可以參考。

還有可以參考「Debian 參考手冊 / 6.3.4 回復套件的選取狀態的資料」。


================================================================================


關於「圖二」,

從提示訊息可以了解到,在安裝「unattended-upgrades」,「apticron」,「apt-listchanges」這三個「Package」時,

在執行「MaintainerScripts」這個階段,會發生錯誤,


* /var/lib/dpkg/info/unattended-upgrades.postinst
* /var/lib/dpkg/info/apticron.postinst
* /var/lib/dpkg/info/apt-listchanges.postinst


================================================================================

關於「圖二」,目前建議的解法

您可以嘗試執行下面的指令,將「unattended-upgrades」,「apticron」,「apt-listchanges」這三個「Package」移除


執行


$ sudo apt-get remove unattended-upgrades apticron apt-listchanges



您的安裝系統,應該就可以回復到可以正常運作的狀態。


或是「dpkg」也有移除的指令,


$ suod dpkg -r unattended-upgrades apticron apt-listchanges




================================================================================

執行

$ man apt-get


可以找到下面這一段說明


remove
remove is identical to install except that packages are removed
instead of installed. Note that removing a package leaves its
configuration files on the system. If a plus sign is appended to
the package name (with no intervening space), the identified
package will be installed instead of removed.




執行

$ man dpkg


可以找到下面這一段說明


-r, --remove package...|-a|--pending
Remove an installed package. This removes everything except
conffiles, which may avoid having to reconfigure the package if
it is reinstalled later (conffiles are configuration files that
are listed in the DEBIAN/conffiles control file). If -a or
--pending is given instead of a package name, then all packages
unpacked, but marked to be removed in file /var/lib/dpkg/status,
are removed.

Removing of a package consists of the following steps:

1. Run prerm script

2. Remove the installed files

3. Run postrm script




================================================================================

關於下面這三個檔案(當已經有安裝「unattended-upgrades」,「apticron」,「apt-listchanges」這三個「Package」時)

* /var/lib/dpkg/info/unattended-upgrades.postinst
* /var/lib/dpkg/info/apticron.postinst
* /var/lib/dpkg/info/apt-listchanges.postinst


也可以透過下載「Package」或「Source Package」找到。

## 透過 Package

執行下面指令,下載「unattended-upgrades」這個「Package


$ apt-get download unattended-upgrades



執行


$ dpkg -e unattended-upgrades_0.90ubuntu0.6_all.deb



會產生一個資料夾「DEBIAN」


$ tree DEBIAN



顯示


DEBIAN/
├── conffiles
├── config
├── control
├── md5sums
├── postinst
├── postrm
├── prerm
└── templates

0 directories, 8 files



可以對照「DEBIAN/postinst」和「/var/lib/dpkg/info/unattended-upgrades.postinst」


## 透過「Source Package」

執行下面指令,下載「unattended-upgrades」的「Source Package


$ apt-get source unattended-upgrades




可以對照「unattended-upgrades-0.90ubuntu0.6/debian/postinst」和「/var/lib/dpkg/info/unattended-upgrades.postinst」


相關概念的討論案例

* #5 回覆: 軟體中心無法安裝程式
* Debian Wiki / MaintainerScripts


================================================================================

關於「sudo apt-get autoremove」或「sudo apt autoremove」的使用時機

執行

$ man apt-get

可以找到下面一段說明,


autoremove (and the auto-remove alias since 1.1)
autoremove is used to remove packages that were automatically
installed to satisfy dependencies for other packages and are now no
longer needed.



$ man apt

可以找到下面一段說明,


autoremove (apt-get(8))
autoremove is used to remove packages that were automatically
installed to satisfy dependencies for other packages and are now no
longer needed as dependencies changed or the package(s) needing
them were removed in the meantime.

You should check that the list does not include applications you
have grown to like even though they were once installed just as a
dependency of another package. You can mark such a package as
manually installed by using apt-mark(8). Packages which you have
installed explicitly via install are also never proposed for
automatic removal.




通常您再執行「apt-get」完後,就會有相關的提示訊息,請您使用「apt-get autoremove」或「apt autoremove」

例如,您可以參考這個「討論案例」,有紀錄在「[索引] 套件操作實務」。
還有後來您自己遇到的「討論案例」。


我的理解,

通常安裝「A」套件,而「A」相依「B」這個套件,
所以安裝「A」套件時,也會跟著安裝「B」套件,

然後若單獨移除了「A」套件,而「B」套件是不會跟著移除,
這時候系統若沒有其他的套件是相依「B」套件的,

當每次執行「apt-get」完後,這時候就會提醒您使用「apt-get autoremove」來移除「B」套件。

================================================================================

以上提供參考

報告完畢


2017/5/21 16:19
應用擴展 工具箱
回覆: 更新套件時發生錯誤
會員三級
註冊日期:
2016/4/18 12:29
所屬群組:
已註冊使用者
等級: 9
HP : 0 / 221
MP : 39 / 4821
EXP: 84
離線
借串問一下,發生最後的那行error code(1),的原因
前幾個禮拜也有裝 xubuntu ENG 32bit ,有發生那個Error code
暫時還沒空處理

2017/5/22 11:13
應用擴展 工具箱
回覆: 更新套件時發生錯誤
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 905
MP : 679 / 30304
EXP: 23
離線
ubuntu_net2016 寫到:
借串問一下,發生最後的那行error code(1),的原因
前幾個禮拜也有裝 xubuntu ENG 32bit ,有發生那個Error code
暫時還沒空處理



我上面的「回覆#2」有提到


samwhelp 寫到:

關於「圖二」,

從提示訊息可以了解到,在安裝「unattended-upgrades」,「apticron」,「apt-listchanges」這三個「Package」時,

在執行「MaintainerScripts」這個階段,會發生錯誤,


* /var/lib/dpkg/info/unattended-upgrades.postinst
* /var/lib/dpkg/info/apticron.postinst
* /var/lib/dpkg/info/apt-listchanges.postinst




所以您要觀察您執行「apt-get」的時候,

是執行那個套件的「Maintainer Scripts (相關文章)」這個階段發生錯誤,
然後「trace」該「script」裡面執行到那段code發生錯誤。

以上面為例,「unattended-upgrades」這個「package」,
從「圖二」的提示訊息,「... post-installation script ...」
可以看到是在執行「/var/lib/dpkg/info/unattended-upgrades.postinst」這個「script」時出錯,
所以就要trace「/var/lib/dpkg/info/unattended-upgrades.postinst」這個「script」是執行到什麼發生錯誤。


小弟不才,目前還沒去學會怎麼「debug」這一段,Orz...
只有粗略瞭解上面的概念,有些概念還沒研究透澈,還沒花時間再去深究這一段。

另外還有一個相關的指令「dpkg-reconfigure」。

$ man dpkg-reconfigure
$ man debconf


$ man dpkg

可以看到下面其中一段說明


--configure package...|-a|--pending
Configure a package which has been unpacked but not yet config‐
ured. If -a or --pending is given instead of package, all
unpacked but unconfigured packages are configured.

To reconfigure a package which has already been configured, try
the dpkg-reconfigure(8) command instead.

Configuring consists of the following steps:

1. Unpack the conffiles, and at the same time back up the old
conffiles, so that they can be restored if something goes wrong.

2. Run postinst script, if provided by the package.




還有「Files」那一段


FILES

...略...

/var/log/dpkg.log
Default log file (see /etc/dpkg/dpkg.cfg(5) and option --log).

...略...


The following files are components of a binary package. See deb(5) for
more information about them:
control
conffiles
preinst
postinst
prerm
postrm
triggers






以上提供參考

報告完畢


2017/5/25 15:09
應用擴展 工具箱
回覆: 更新套件時發生錯誤
會員五級
註冊日期:
2012/4/22 10:50
所屬群組:
已註冊使用者
等級: 37
HP : 0 / 905
MP : 679 / 30304
EXP: 23
離線
做個簡單的打包範例,來補充闡釋上面回覆提到的概念。

簡易打包範例可以參考之前寫的「文章」,連結有紀錄在這個「索引」。

此篇也有紀錄在「[索引] 套件操作實務」,使用「dpkg -b」當關鍵字查詢頁面,就可以找到。

此篇範例也放到「GitHub」上。

================================================================================

以下測試環境「Xubuntu 16.04 amd64 英文界面」。

================================================================================

執行


#!/usr/bin/env bash

# 建立專案資料夾
mkdir -p demo/DEBIAN

## 產生「demo/DEBIAN/control」
cat > demo/DEBIAN/control << EOF
Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>

EOF

## 產生「demo/DEBIAN/postinst」
cat > demo/DEBIAN/postinst << EOF
#!/bin/sh

xxxxx

EOF

## 設定「demo/DEBIAN/postinst」權限
chmod 775 demo/DEBIAN/postinst




會產生一個資料夾「demo」。

執行下面指令,觀看「demo」這個資料夾的結構。


$ tree demo



顯示


demo
└── DEBIAN
    ├── control
    └── postinst

1 directory, 2 files



執行下面指令,觀看「demo/DEBIAN/control」的內容


$ cat demo/DEBIAN/control



顯示


Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>



欄位,可以參考

$ man deb-control


執行下面指令,觀看「demo/DEBIAN/postinst」的內容


$ cat demo/DEBIAN/postinst



顯示


#!/bin/sh

xxxxx




* Debian Wiki / MaintainerScripts

$ man deb

================================================================================

$ man dpkg-deb

執行下面指令,打包成「deb檔」。


$ dpkg -b demo



顯示


dpkg-deb: building package 'demo' in 'demo.deb'.



會產生一個檔案「demo.deb」


執行下面指令,觀看「demo.deb」這個檔的資訊。


$ dpkg -I demo.deb



顯示


new debian package, version 2.0.
size 626 bytes: control archive=273 bytes.
130 bytes, 6 lines control
18 bytes, 4 lines * postinst #!/bin/sh

Package: demo
Version: 0.1
Architecture: all
Description: This is a test package.
Maintainer: developer <developer@home.heaven>




================================================================================

執行下面指令,安裝「demo.deb」


$ sudo dpkg -i demo.deb



顯示


...略...
Preparing to unpack demo.deb ...
Unpacking demo (0.1) ...
Setting up demo (0.1) ...
/var/lib/dpkg/info/demo.postinst: 3: /var/lib/dpkg/info/demo.postinst: xxxxx: not found
dpkg: error processing package demo (--install):
subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
demo



執行下面指令,觀看「/var/lib/dpkg/info/demo.postinst」這個檔案的內容。


$ cat /var/lib/dpkg/info/demo.postinst



顯示


#!/bin/sh

xxxxx



執行


$ sudo apt-get install



顯示


...略...
1 not fully installed or removed.
After this operation, 0 B of additional disk space will be used.
Setting up demo (0.1) ...
/var/lib/dpkg/info/demo.postinst: 3: /var/lib/dpkg/info/demo.postinst: xxxxx: not found
dpkg: error processing package demo (--configure):
subprocess installed post-installation script returned error exit status 127
Errors were encountered while processing:
demo
E: Sub-process /usr/bin/dpkg returned an error code (1)



上面的提示訊息,是不是跟「圖二」類似?


================================================================================


執行下面指令,確認是否安裝成功



$ dpkg -l demo



顯示


Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-=============================-===================-===================-=========
iF demo 0.1 all This is a test package.



注意上面開頭是「iF」,

* 「i」指的是「Desired=Install
* 「F」指的是「Status=halF-conf


執行


$ dpkg -s demo



顯示


Package: demo
Status: install ok half-configured
Maintainer: developer <developer@home.heaven>
Architecture: all
Version: 0.1
Description: This is a test package.



注意上面的「Status:」是「install ok half-configured

================================================================================

執行下面指令,移除「demo」這個「packeage」。


$ sudo apt-get remove demo



或是執行


$ sudo dpkg -r demo



================================================================================

以上補充說明

報告完畢


2017/5/25 16:57
應用擴展 工具箱


 [無發表權] 請登錄或者註冊


可以查看帖子.
不可發帖.
不可回覆.
不可編輯自己的帖子.
不可刪除自己的帖子.
不可發起投票調查.
不可在投票調查中投票.
不可上傳附件.
不可不經審核直接發帖.