Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

arch-chroot: bind mount over a /etc/resolv.conf symlink #57

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tasks when installing [Arch Linux](https://www.archlinux.org).
## Requirements

* GNU coreutils (>= v8.15)
* util-linux (>= 2.23)
* util-linux (>= 2.39)
* POSIX awk
* bash (>= 4.1)
* asciidoc (for generating man pages)
Expand Down
26 changes: 6 additions & 20 deletions arch-chroot.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,20 @@ resolve_link() {
chroot_add_resolv_conf() {
local chrootdir=$1
local src
local dest
local dest="$chrootdir/etc/resolv.conf"

src=$(resolve_link /etc/resolv.conf)
dest=$(resolve_link "$chrootdir/etc/resolv.conf" "$chrootdir")

# If we don't have a source resolv.conf file, there's nothing useful we can do.
[[ -e $src ]] || return 0

if [[ ! -e $dest ]]; then
# There are two reasons the destination might not exist:
#
# 1. There may be no resolv.conf in the chroot. In this case, $dest won't exist,
# and it will be equal to $1/etc/resolv.conf. In this case, we'll just exit.
# The chroot environment must not be concerned with DNS resolution.
#
# 2. $1/etc/resolv.conf is (or resolves to) a broken link. The environment
# clearly intends to handle DNS resolution, but something's wrong. Maybe it
# normally creates the target at boot time. We'll (try to) take care of it by
# creating a dummy file at the target, so that we have something to bind to.

# Case 1.
[[ $dest = $chrootdir/etc/resolv.conf ]] && return 0

# Case 2.
install -Dm644 /dev/null "$dest" || return 1
if [[ ! -e "$dest" && ! -h "$dest" ]]; then
# There may be no resolv.conf in the chroot. In this case, we'll just exit.
# The chroot environment must not be concerned with DNS resolution.
return 0
fi

chroot_add_mount "$src" "$dest" --bind
chroot_add_mount "$src" "$dest" -c --bind
}

arch-chroot() {
Expand Down