Add cdrom to repository list with apt-cdrom

Ubuntu 16.04: Install package from DVD

This article will describe installing deb packages which are in DVD. This will help to recovery when the network packages are removed by mistake.

Table of Contents

  • 1. Add cdrom to repository list with apt-cdrom
  • 2. Few packages in ubuntu-16.04-desktop-amd64.iso
  • 3. Create DVD which has custom deb packages
    • 3.1. Download deb packages
    • 3.2. Create GPG key
    • 3.3. Create repository
    • 3.4. Create DVD
    • 3.5. Add cdrom to repository list

1 Add cdrom to repository list with apt-cdrom

Mount cdrom to /media/cdrom.

$ sudo mount -t iso9660 /dev/cdrom /media/cdrom
mount: /dev/sr0 is write-protected, mounting read-only

Add cdrom to repository list with apt-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 "
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.

The apt-cdrom changes /etc/apt/sources.list. For removing cdrom from repository list, remove "deb cdrom:" statement in /etc/apt/sources.list.

$ 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 Few packages in ubuntu-16.04-desktop-amd64.iso

ubuntu-16.04-desktop-amd64.iso has only 24 packages. ubuntu-16.04-desktop-amd64.iso is LiveDVD. For installing, copy root filesystem of LiveDVD to storage and install 24 packages to storage.

$ 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 has 1244 packages. But it has no desktop environment packages.

$ 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

3 Create DVD which has custom deb packages

This article will create DVD which has desktop environment packages. And this will add DVD to repository list.

3.1 Download deb packages

Download deb packages of ubuntu-desktop and dependencies with this script.

$ sudo apt install -y apt-rdepends
$ mkdir deb
$ cd deb
$ ../download-deb-package.sh ubuntu-desktop
$ cd ..

3.2 Create GPG key

When creating GPG key, the following message will be output and console will be hung.

Not enough random bytes available. Please do some other work to give

For avoid this hung, update /dev/urandom with rng-tools.

$ sudo apt install -y rng-tools
$ sudo rngd -r /dev/urandom

Create gpg config file.

$ cat < gpg.txt
Key-Type: RSA
Subkey-Type: RSA
Name-Real: hiroom2
Expire-Date: 0
%pubring public.key
%secring signing.key
%commit
EOF

Create GPG key with gpg batch mode, and import GPG key.

$ gpg --batch --gen-key gpg.txt
$ gpg --import public.key signing.key

3.3 Create repository

Install reprepro which creates repository with apt.

$ sudo apt install -y reprepro

Get subkey value for GPG key of repository.

$ dir=`pwd`
$ subkey=`gpg --list-keys --keyring ${dir}/public.key --no-default-keyring | \
grep sub | awk '{ print $2 }' | awk -F'/' '{ print $2 }'`

Create iso directory and store reprepro config file to there.

$ mkdir iso
$ cd iso
$ mkdir conf
$ cat < conf/distributions
Codename: xenial
Architectures: amd64
Components: main
SignWith: ${subkey}
EOF

Create repository with reprepro.

$ reprepro includedeb xenial ~/deb/*.deb

Copy GPG public key to iso directory.

$ cp ../public.key .

3.4 Create DVD

Create iso image with genisoimage. Please burn iso image to DVD media.

$ genisoimage -J -R -V "Ubuntu 16.04 repo" -o ubuntu-16.04-repo.iso iso

3.5 Add cdrom to repository list

Insert DVD media and mount cdrom to /media/cdrom.

$ sudo mount /dev/cdrom /media/cdrom

Add GPG key with apt-key.

$ sudo apt-key add /media/cdrom/public.key

Add cdrom to repository list with apt-cdrom. Because the database has no entry of this DVD, input repository name "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.

Now you can install deb packages from DVD.

$ sudo apt update -y
$ sudo apt install -y ubuntu-desktop

你可能感兴趣的:(Add cdrom to repository list with apt-cdrom)