• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Adjusting APT Sources for Multiarch
2
3The Cuttlefish host Debian packages can also be built and used on an `arm64`
4based system. However, because certain parts of it are still `amd64`, the
5APT sources of the system need to be adjusted for multiarch so that package
6dependencies can be correctly looked up and installed.
7
8For detailed context, see [Multiarch HOWTO](https://wiki.debian.org/Multiarch/HOWTO), and this document will use Ubuntu 21.04 (Hirsute) as an example for
9making such adjustments.
10
11The basic idea is to first limit the existing APT sources to `arm64` only,
12so that when a new architecture like `amd64` is added, APT won't try to
13fetch packages for the new architecture from the existing repository, as
14`arm64` packages are in "ports", while `amd64` ones are in the main
15repository. So a line in `/etc/apt/sources.list` such as:
16
17```
18deb http://ports.ubuntu.com/ubuntu-ports hirsute main restricted
19```
20
21would be changed to:
22
23```
24deb [arch=arm64] http://ports.ubuntu.com/ubuntu-ports hirsute main restricted
25```
26
27Next, each line of config like the above will be duplicated and modified into
28an entry that corresponds to what's in the main repository, with its
29architecture limited to `amd64`. For example, for the same line as shown above,
30a new entry will be added like this:
31
32```
33deb [arch=amd64] http://archive.ubuntu.com/ubuntu hirsute main restricted
34```
35
36The script below might be handy for this task:
37```bash
38#!/bin/bash
39cp /etc/apt/sources.list ~/sources.list.bak
40(
41  (grep ^deb /etc/apt/sources.list | sed 's/deb /deb [arch=arm64] /') && \
42  (grep ^deb /etc/apt/sources.list | sed 's/deb /deb [arch=amd64] /g; s/ports\.ubuntu/archive.ubuntu/g; s/ubuntu-ports/ubuntu/g') \
43) | tee /tmp/sources.list
44mv /tmp/sources.list /etc/apt/sources.list
45```
46**Note:** please run the above script as `root`, and adjust for differences in
47Ubuntu releases or location prefixed repositories for faster download (e.g.
48`us.archive.ubuntu.com` instead of `archive.ubuntu.com`).
49
50Finally, add the new architecture and do an APT update with:
51```bash
52sudo dpkg --add-architecture amd64
53sudo apt update
54```
55Make sure there's no errors or warnings in the output of `apt update`. To
56restore the previous APT sources list, use the backup file `sources.list.bak`
57saved by the script in your home directory.
58