NAME

Sys::Export::Linux - Export subsets of a Linux system

SYNOPSIS

use Sys::Export::Linux;
my $exporter= Sys::Export::Linux->new(
  src => '/', dst => '/initrd'
);
$exporter->add('bin/busybox');
$exporter->add_passwd;
$exporter->add_localtime("UTC");

DESCRIPTION

This object extends Sys::Export::Unix with Linux-specific helpers and special cases.

See Sys::Export::Unix for the list of core attributes and methods.

METHODS

parse_ld_so_conf

@lib_paths= $exporter->parse_ld_so_conf($filename = 'etc/ld.so.conf');

Return a list of library paths parsed from a ld.so.conf file.

parse_nsswitch_conf

%db_info= $exporter->parse_nsswitch_conf($filename => 'etc/nsswitch.conf');
# (
#    aliases => [ @module_names ],
#    hosts   => [ @module_names ],
#    ...
# )

The GNU Libc "nsswitch" system lets you dynamically plug libraries to support various libc database lookups. In the hashref data returned by this function, the key is the name of the database, like 'hosts' or 'passwd', and the value is an arrayref of which plugins will be consulted, and in what order they will be queried.

add_nsswitch_libs

$exporter->add_nsswitch_libs;
$exporter->add_nsswitch_libs(@module_names);

With glibc, the binaries do not directly refer to the dynamically-configured nsswitch modules, so the modules won't get automatically included. If you want your chroot image to be able to do things like DNS name lookups or passwd file lookups, you need to include any NSS module configured for them.

This method defaults to the set of all modules returned by "parse_nsswitch_conf", and then adds libraries for each of them, like "lib64/libnss_dns.so.2". Missing libraries generate a warning (not an exception).

With newer glibc, the modules 'files' and 'dns' are built-in, to aid with chroots, though the libnss_files.so and libnss_dns.so still exist in the lib directory. This method doesn't attempt to add a special case for omitting them.

add_passwd

$exporter->add_passwd(%options)

This method writes the Linux password files ( /etc/passwd, /etc/group, /etc/shadow ) either according to the contents of "dst_userdb" in Sys::Export::Unix (if you used name-based exports) or according to "src_userdb" in Sys::Export::Unix filtered by "dst_uid_used" in Sys::Export::Unix if dst_userdb is not defined.

In the first pattern, you've either pre-specified the dst_userdb users, or built it lazily as you exported files. The dst_userdb contains the complete contents of passwd, group, and shadow and this method simply generates and adds those files.

In the second pattern, you want the destination userdb to be a subset of the source userdb according to which UIDs and GIDs were actually used.

If you actually just want to copy the entire source user database files, you could just call

$exporter->add(qw( /etc/passwd /etc/group /etc/shadow ));

so that pattern doesn't need a special helper method.

Options:

etc_path

Specify an alternative directory to '/etc' to write the files

add_localtime

$exporter->add_localtime($tz_name);

Generate the symlink in /etc/localtime, *or* export the timezone file directly to that path if the system image lacks /usr/share/zoneinfo.

Linux uses a symlink at /etc/localtime to point to a compiled zoneinfo file describing the current time zone. You can simply export this symlink, but if you are building a minimal system image (like initrd) you might not be exporting the timezone database at /usr/share/zoneinfo. In that case, you want the single timezone file copied to /etc/localtime.

This method looks for the zone file in your destination filesystem, and if not found there, it looks in the source filesystem, and if not there either, it checks the host filesystem. If it can't find this timezone in any of those locations, it dies.

VERSION

version 0.005_002

AUTHOR

Michael Conrad <mike@nrdvana.net>

COPYRIGHT AND LICENSE

This software is copyright (c) 2026 by Michael Conrad.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.