DVDに格納されたdebパッケージをインストールする方法について記載します。ネットワーク関係のパッケージを削除してしまった場合に復旧させるのに使うことができます。
Table of Contents
1 apt-cdromでcdromをリポジトリに追加
cdromをマウントします。
$ sudo mount -t iso9660 /dev/cdrom /media/cdrom mount: /dev/sr0 is write-protected, mounting read-only
apt-cdromでcdromをリポジトリに追加します。
$ sudo apt-cdrom -m -d /media/cdrom add Using CD-ROM mount point /media/cdrom/ Identifying... [1a235e539972579c22a0bec9a077f7c3-2] Scanning disc for index files... Found 4 package indexes, 0 source indexes, 0 translation indexes and 1 signatures This disc is called: 'Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)' Copying package lists...gpgv: Signature made Thu 21 Apr 2016 07:29:18 AM JST using DSA key ID FBB75451 gpgv: Good signature from "Ubuntu CD Image Automatic Signing Key <[email protected]>" Reading Package Indexes... Done Writing new source list Source list entries for this disc are: deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted Repeat this process for the rest of the CDs in your set.
apt-cdromによって/etc/apt/sources.listは以下のように変更されます。cdromのリポジトリを削除するには"deb cdrom:"の行を削除します。
$ diff -uprN /etc/apt/sources.list{.org,}
--- /etc/apt/sources.list.org 2016-08-12 10:50:26.281895047 +0900
+++ /etc/apt/sources.list 2016-08-12 10:50:42.603934453 +0900
@@ -2,6 +2,7 @@
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
+deb cdrom:[Ubuntu 16.04 LTS _Xenial Xerus_ - Release amd64 (20160420.1)]/ xenial main restricted
deb http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
deb-src http://jp.archive.ubuntu.com/ubuntu/ xenial main restricted
@@ -51,3 +52,4 @@ deb http://security.ubuntu.com/ubuntu xe
deb-src http://security.ubuntu.com/ubuntu xenial-security universe
deb http://security.ubuntu.com/ubuntu xenial-security multiverse
deb-src http://security.ubuntu.com/ubuntu xenial-security multiverse
+
2 Ubuntu 16.04デスクトップのdebパッケージは少ない
ubuntu-16.04-desktop-amd64.isoは24パッケージしか持ってません。ubuntu-16.04-desktop-amd64.isoはLiveDVDである為、LiveDVDのルートファイルシステムをコピーしてから、grub等の環境依存のdebパッケージをインストールしており、debパッケージをほとんど使わない為です。
$ grep ^Package: /var/lib/apt/lists/Ubuntu*Packages | awk '{ print $2 }'
b43-fwcutter
dkms
libc6-i386
grub-efi
grub-efi-amd64
grub-efi-amd64-bin
grub-efi-amd64-signed
grub
lupin-support
mouseemu
setserial
shim
shim-signed
oem-config
oem-config-gtk
oem-config-slideshow-ubuntu
user-setup
wvdial
libuniconf4.6
libwvstreams4.6-base
libwvstreams4.6-extras
bcmwl-kernel-source
intel-microcode
iucode-tool
ubuntu-16.04-server-amd64.isoは1244パッケージあります。しかしgnome等のデスクトップ環境のパッケージを持ちません。
$ grep ^Package: /var/lib/apt/lists/Ubuntu*Packages | awk '{ print $2}'
accountsservice
libaccountsservice0
acct
acl
libacl1
acpid
adduser
aide
aide-common
python3-alabaster
libasound2
libasound2-data
alsa-utils
amavisd-new
anacron
libjs-angularjs
apache2
apache2-bin
apache2-data
apache2-doc
<snip>
3 debパッケージをDVDを作成する
この記事ではデスクトップ環境のdebパッケージをDVDに格納して、リポジトリとして利用できるようにします。
3.1 debパッケージを用意する
こちらのスクリプトを利用して、ubuntu-desktopのdebパッケージと依存パッケージをダウンロードします。
$ sudo apt install -y apt-rdepends $ mkdir deb $ cd deb $ ../download-deb-package.sh ubuntu-desktop $ cd ..
3.2 GPGキーを用意する
gpgを作成する場合に以下のメッセージが出る場合があります。マウス操作等でランダム値へのノイズを発生させてやることで解消されますが、SSH経由の場合はマウス操作できません。
Not enough random bytes available. Please do some other work to give
そこでrng-toolsでランダム値を更新します。
$ sudo apt install -y rng-tools $ sudo rngd -r /dev/urandom
gpgをbatch処理で作成する為の設定ファイルを作成します。
$ cat <<EOF > gpg.txt Key-Type: RSA Subkey-Type: RSA Name-Real: hiroom2 Expire-Date: 0 %pubring public.key %secring signing.key %commit EOF
GPGキーをbatch処理で作成してインポートします。
$ gpg --batch --gen-key gpg.txt $ gpg --import public.key signing.key
3.3 リポジトリを作成する
リポジトリを作成するrepreproをインストールします。
$ sudo apt install -y reprepro
リポジトリ作成で利用するsubkeyの値を取得します。
$ dir=`pwd`
$ subkey=`gpg --list-keys --keyring ${dir}/public.key --no-default-keyring | \
grep sub | awk '{ print $2 }' | awk -F'/' '{ print $2 }'`
isoというディレクトリを作成し、repreproの設定ファイルを作成します。
$ mkdir iso
$ cd iso
$ mkdir conf
$ cat <<EOF > conf/distributions
Codename: xenial
Architectures: amd64
Components: main
SignWith: ${subkey}
EOF
repreproでリポジトリを追加します。
$ reprepro includedeb xenial ~/deb/*.deb
GPGキーの公開鍵をisoディレクトリに格納します。
$ cp ../public.key .
3.4 DVDの作成
genisoimageでisoイメージを作成します。作成したisoイメージをdvdrecord等でメディアに書き込みます。
$ genisoimage -J -R -V "Ubuntu 16.04 repo" -o ubuntu-16.04-repo.iso iso
3.5 リポジトリの追加
メディアをDVDドライブに入れてマウントします。
$ sudo mount /dev/cdrom /media/cdrom
apt-keyでGPGキーを追加します。
$ sudo apt-key add /media/cdrom/public.key
apt-cdromで追加します。ディスク名がデータベースにないので"Ubuntu 16.04 repo"を入力します。
$ echo "Ubuntu 16.04 repo" | sudo apt-cdrom -m -d /media/cdrom add Using CD-ROM mount point /media/cdrom/ Identifying... [24043ba8f9dff07baf00246e9de86642-2] Scanning disc for index files... Found 1 package indexes, 0 source indexes, 0 translation indexes and 0 signatures Please provide a name for this Disc, such as 'Debian 5.0.3 Disk 1': Name: 'Ubuntu 16.04 repo' This disc is called: 'Ubuntu 16.04 repo' Reading Package Indexes... Done Writing new source list Source list entries for this disc are: deb cdrom:[Ubuntu 16.04 repo]/ xenial main Repeat this process for the rest of the CDs in your set.
これ以降はネットワークが動作しない状態でもDVDからパッケージをインストールできます。
$ sudo apt update -y $ sudo apt install -y ubuntu-desktop