Commit Graph

38 Commits

Author SHA1 Message Date
Emil Velikov
6c68163d4b pacstrap: move include_m4 after the globals
After the m4 substitution, the globals end up mixed misc functions.
Just keep them at the top for legibility.

Signed-off-by: Emil Velikov <emil.l.velikov@gmail.com>
2023-03-26 19:03:33 +01:00
Mike Yuan
ef83a837fd
pacstrap: add option '-D' to skip pacman dependency checks
Closes #19
2022-10-28 18:28:30 +08:00
Morten Linderud
ebf492335e
Merge branch 'pr-31' 2022-10-28 00:13:26 +02:00
Mike Yuan
91562aa99c
pacstrap: remove obsolete option '-d' completely
This has been obsolete for 4 years and I can hardly imagine people still using it (only to find that it doesn't actually work).
2022-10-22 21:07:27 +08:00
Mike Yuan
ddf3134077
pacstrap: add option '-P' to copy the host's pacman config to the target 2022-10-22 20:51:54 +08:00
Mike Yuan
8be9340001
pacstrap: add option '-K' to initialize an empty keyring in the new root 2022-08-25 22:45:07 +08:00
Sean Anderson
58ff428757 Use separate pid namespace for worker processes
As described in 2be79c6 ("run the chroot in a new PID namespace"), child
processes can hang around and keep various files open. This may prevent
filesystems from being unmounted (as they are still in-use).

When adding unshare mode, I did not quite understand this distinction
(and I wasn't testing with e.g. gnupg) so I didn't catch this. Fix this
by always using unshare to create a second pid namespace for "worker"
processes. This ensures that all children are dead when we start
unmounting things. As the top-level unshare is no longer always
necessary, convert the unshare variable to a binary value.

Fixes: ee9db7d ("Add unshare mode to pacstrap")
Closes: #21
2022-07-28 10:02:31 -04:00
Sean Anderson
ee9db7d580 Add unshare mode to pacstrap
This adds an "unshare" mode to pacstrap. This mode lets a regular user
create a new arch root filesystem. We use -N because both -U and -u are
taken in pacstrap and arch-chroot, respectively. There are two major
changes to pacstrap: we need to run many commands in under unshare, and
the setup process for mounts is different.

Because unshare starts a new shell, it is difficult to run many commands
in sequence. To get around this, we create a function for the rest of
the commands we wish to run, and then declare all functions and
variables in the unshare'd shell. This is pretty convenient. An
alternative method would be to generate the shell script as a HERE
document, and pipe it to bash.

Because unshare starts a new shell, we can only communicate using
stdin/out and any command line arguments. And we need to defer some
setup until after we are root. To get around this, we create a function
for the rest of the commands we wish to run, and then declare all
functions and variables in the unshare'd shell. I also considered having
a separate helper script which would contain the contents of pacstrap().
But I think this would be confusing, because the logic would then live
in a separate file (instead of just a separate function). That method is
also tricky because every variable has to be passed in through the
command-line arguments. One last method would be to generate a script on
the fly (e.g. using a HERE doc). I think that method could work as well.

The primary difference to the setup process is that we need to mount
filesystems in a different manner:
- We bind-mount the root directory. This is so commands which want to
  determine how much free space there is (or otherwise work with mounts)
  expect a mount on /. We unmount it with --lazy, since otherwise sys
  will cause an error (see below).
- proc can be mounted multiple times and is mounted in the same way
- sys cannot be mounted again, but we can recursively bind-mount it.
  When mounted this way, we can't unmount it until the mount namespace
  is deleted (likely because sys has a number of sub-mounts), so we have
  to use --lazy when unmounting it.
- dev can be bind-mounted, but this results in errors because some
  packages try and modify files in /dev if they exist. Since we don't
  have permission to do that on the host system, this fails. Instead, we
  just bind-mount a minimal set of files.
- run is not bind-mounted, but is instead created as a new tmpfs.
  According to aea51ba ("Bind mount /run from host into new root"), the
  reason this was done was to avoid lengthy timeouts when scanning for
  lvm devices. Because unshare does not (and cannot) use lvm devices, we
  don't need to bind-mount.
- tmp is created as usual.

Closes: #8
2021-12-08 17:44:51 -05:00
Sean Anderson
88c0c9db0b Don't warn if ownership changes when copying /etc/pacman.d/gnupg
In an unshare environment, /etc/pacman.d/gnupg is owned by the original
root, who is now "nobody". cp will warn about this, since we can't
create files owned by the original root, and it instead creates them as
the unshare'd root (the original user). This is benign, so ignore it.
2021-11-17 13:47:54 -05:00
Eli Schwartz
e1a84d1056
pacstrap: support local file mode
Allow passing files to the underlying pacman command, instead of relying
on the syncdb. This allows fine-grained control over the package files
to be installed, which can be useful when initializing a build chroot
for reproducible builds.
2019-11-13 12:03:38 -05:00
Eli Schwartz
8652c5a724
consistently use -v <val> for help text descriptions 2019-06-05 15:26:59 -04:00
Eli Schwartz
53debcefab
pacstrap: try to copy the host keyring before installing packages
When there is no keyring in the new root, attempting to install e.g.
archlinux-keyring will result in the post-install script silently
failing to do anything (because there are no keys, and, critically, no
secret keys). The potentially very outdated keyring is then copied over
from the host, secret key and all, so subsequent pacman operations have
a trusted keyring that is at least as recent as the ISO or other host
system... but if there has been a keyring update between the date of the
ISO creation and the date of the install, those keys will continue to be
missing until the next keyring update, resulting in a bad out-of-the-box
experience.

This also means that if a thirdparty keyring package was scheduled to be
installed, it will not be populated at all; this affects downstream
archlinux32 build chroots.

There's no reason to delay this until after packages are installed -- we
aren't afraid of e.g. the mirrorlist resulting in file conflicts due to
a packaged pacman-mirrorlist, because the gnupg configuration should not
be getting packaged directly.

Fixes FS#61296 FS#61304 FS#61309 FS#61312 FS#62355
2019-05-21 01:32:52 -04:00
Dave Reisner
1f6e69f03e Clarify that -i means run interactively
ref: https://bugs.archlinux.org/task/60096
2019-01-05 11:21:09 -05:00
Dave Reisner
0c7d9e570f Rephrase description of -i to be less awful 2018-09-17 17:40:19 -04:00
Dave Reisner
0af6884aca pacstrap: retire -d flag
Similar to 232784ec, this logic has been around forever with no
discernible value. Retire the flag from the code and documentation, but
leave it behind as a vestige in order to not break scripts found in the
wild.
2018-01-27 07:17:30 -05:00
Dave Reisner
e44af861eb use consistent messaging for chroot_setup failure 2014-12-16 23:15:17 -05:00
Dave Reisner
b5832066c5 rename chroot setup-related functions
make it more obvious that these are really related functions.
2014-12-15 23:23:39 -05:00
Alan Braithwaite
a54860044f Remove redundant variable declaration
Unless I'm mistaken, newroot is assigned later, and never referenced in between:
```
(( $# )) || die "No root directory specified"
newroot=$1; shift
```
2014-10-30 14:19:48 -07:00
Dave Reisner
1d35997222 common: auto-register api_fs_umount EXIT trap
This corrects some weird/wrong EXIT trap decls in arch-chroot and
pacstrap that should have been touched as part of the cleanup in
517fcff074.
2013-05-23 12:06:29 -04:00
Dave Reisner
cf84170321 add the -h option to the usage 2012-11-12 21:00:09 -05:00
Dave Reisner
ea41f437d2 pacstrap: add -C option for using an alternate config
I grappled with the inability of pacstrap to do this while trying to
setup an i686 chroot for myself based on a pacman config from devtools,
rather than my own config which bombs on a "missing" multilib repo.
2012-10-03 22:55:49 -04:00
Dave Reisner
dc2c7623e4 pacstrap: ignore ENOENT on already existing API dirs 2012-09-24 09:50:30 -04:00
techryda
367e1fe12b Create /var/log in $newroot
Allows pacman.log to be created
2012-09-17 06:56:40 -06:00
Dave Reisner
3f4a9149a1 pacstrap: add options to inhibit copying settings
Add -G and -M which tells pacstrap to avoid copying pacman's gnupg.d
directory and mirrorlist, respectively, to the new root.
2012-09-15 11:46:48 -04:00
Dave Reisner
cc53a33bfd pacstrap: enforce permissions on root directories 2012-09-15 11:37:04 -04:00
Daniel Wallace
d195e48981 allow turning off --noconfirm
use -i (interactive) to allow for choosing packages from groups

[dave: alter option description]
2012-08-03 08:43:01 -04:00
Dave Reisner
ced04ef0f9 pacstrap: create package cache along with DBPath
pacman creates this for us, but seems to have problems writing to it.

Hackily addresses FS#30807
2012-07-22 20:10:47 -04:00
Dave Reisner
1d9c98c5ee enforce user-specified root directory
Remove the -r option, forcing the user to explicitly pass a root
directory. This removes some confusion wherein we set defaults, but
wouldn't allow all the defaults to be accepted.

This also adds some mild documentation to the help output for genfstab
and pacstrap.
2012-07-15 10:07:11 -04:00
Dave Reisner
de68d4cc02 reverse default and set values for hostcache option 2012-07-14 09:33:46 -04:00
Tom Gundersen
7d8ef4c747 pacstrap: store cache on target system by default
However, add a '-c' switch to use the host cache instead. The default is
useful for when installing a system from an install media (which has
possibly constrained storage), but the '-c' switch is useful when
e.g. creating build-chroots.

I considered doing this the other way around ('-c' being the default).
However, I think it makes sense to default to the expected behavior for
install both because a new user is less likely to know that they need to
add a switch, and because the errormessage they'd get when they run out
of space/memory is nonsensical and would cause lots of annoying
questions.

[dave: use proper array addition, nuke readlink, use arithmetic flag]

Signed-off-by: Tom Gundersen <teg@jklm.no>
2012-06-22 18:55:04 -04:00
Tom Gundersen
e032c0305e pacstrap: copy the mirrorlist from the host to the new root
This would overwrite an existing mirrorlist, but the one at the host
is known to be good at this point, so the loss is minimal.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2012-06-22 18:55:04 -04:00
Tom Gundersen
c5c20fd966 pacstrap: don't copy over keyring if it exist already
We want to be able to call pacstrap with the target being an existing
install (in case it has been severely broken), and hence we might want
to preserve the existing keyring.

Signed-off-by: Tom Gundersen <teg@jklm.no>
2012-06-22 18:55:04 -04:00
Pierre Schmitz
b0af617480 pacstrap: Fix creation of default directories
$newroot might be a relative path, so remove the leading slash.

Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-06-22 15:33:11 +02:00
Dave Reisner
542e888b48 pacstrap/arch-chroot: require root privileges to run
Suggested by Pierre. This makes sense since somewhere along the line,
pacman or mount are going to complain.
2012-06-19 08:13:52 -04:00
Dave Reisner
b60114252c pacstrap: copy the keyring into the new root 2012-06-19 08:13:06 -04:00
Dave Reisner
252a7306c1 pacstrap: set umount trap prior to calling api_mount
the api_mount function could, for some bizzare reason, fail midway
through, leaving the user with a half mounted chroot. set the trap
before the function instead, but mask errors since we might see "foo
not mounted" errors.
2012-06-18 16:51:38 -04:00
Dave Reisner
120d233639 properly error on options missing an optarg 2012-06-18 11:02:40 -04:00
Pierre Schmitz
6fcfe3b268 Create a project Makefile
* the Makefile uses m4 to build the common lib into the scripts
* it includes install, uninstall and clean targets
* the dist target creates a source tar from a tag

Signed-off-by: Pierre Schmitz <pierre@archlinux.de>
2012-06-18 11:17:42 +02:00