Gentoo Stage 4 Utilities Suite
Find a file
2024-08-07 22:25:08 -04:00
.github/workflows Updated bats environment 2023-03-12 01:18:40 -05:00
tests Correct exclusions, include repo, exclude caches 2024-08-07 22:25:08 -04:00
.gitignore Initial commit 2014-05-18 23:52:33 +02:00
gen2extract Don't make gen2extract verbose by default, since a user can add -v themselves 2024-08-05 14:05:35 -04:00
gen2stage4 Correct exclusions, include repo, exclude caches 2024-08-07 22:25:08 -04:00
gen2sync Comment/code cleanup 2024-08-04 02:24:07 -04:00
LICENSE Initial commit 2014-05-18 23:52:33 +02:00
README.md Fork complete 2024-08-04 10:55:57 -04:00

gen2stage4

CI GitHub release Gentoo package LiGurOS package

This is a Bash script which creates “stage 4” tarballs (i.e. system archives) either for the running system, or a system at a specified mount point. The script was inspired by an earlier mkstage4 script by Greg Fitzgerald (unmaintained as of 2012) which itself was a revamped edition of the original mkstage4 by Reto Glauser (unmaintained as of 2009).

Installation

The script can be run directly from its containing folder (and thus, is installed simply by downloading or cloning it from here - and adding run permissions):

git clone https://github.com/erenfro/gen2stage4.git /your/gen2stage4/directory
cd /your/gen2stage4/directory
chmod +x gen2sync gen2extract gen2stage4

For Gentoo Linux and Derivatives, gen2stage4 is also available in Portage via the base Gentoo overlay. On any Gentoo system, just run the following command:

emerge app-backup/gen2stage4

Usage

If you are running the script from the containing folder (first install method) please make sure you use the e.g. ./gen2stage4 command instead of just gen2stage4!

Note that the extension (e.g. .tar.xz) will be automatically appended to the archive_name string which you specify in calling the gen2stage4 command. This is done based on the compression type, which can be specifiled via the -C parameter, if another compression than the default (bz2, creating files ending in .tar.bz2) is desired.

Examples

Archive your current system (mounted at /):

gen2stage4 -s archive_name

Archive a system located at a custom path:

gen2stage4 -t /custom/path archive_name

Copy a system to a separate drive, e.g. for quick backup.

gen2sync -s /run/media/myuser/mybackupdrive

Copy a system located at a custom path:

gen2sync -t /custom/path /run/media/myuser/mybackupdrive

Command line arguments

Usage:
gen2stage4 [-b -c -k -l -q] [-C <type>] [-s || -t <target>] [-e <exclude>...] [-i <include>...] <archive> [-- [tar-opts]]
Position Arguments:
    <archive>    archive name to create with optional path
    [tar-opts]   additional options to pass to tar command

Options:
    -b           excludes boot directory
    -c           excludes some confidential files (currently only .bash_history and connman network lists)
    -k           separately save current kernel modules and src (creates smaller targetArchives and saves decompression time)
    -l           includes lost+found directory
    -q           activates quiet mode (no confirmation)
    -C <type>    specify tar compression (default: ${optCompressType}, available: ${!compressAvail[*]})
    -s           makes archive of current system
    -t <path>    makes archive of system located at the <path>
    -e <exclude> an additional exclude directory (one dir one -e, do not use it with *)
    -i <include> an additional include. This has higher precedence than -e, -t, and -s
    -h           display this help message.

System Tarball Extraction

Automatic (Multi-threaded)

Provides is a script for convenient extraction, gen2extract, which is shipped with this package. Currently it simply automates the Multi-threaded extraction selection listed below and otherwise has no functionality except checking that the file name looks sane. If in doubt, use one of the explicit extraction methods described below. Otherwise, you can extract an archive inplace with:

gen2extract -s archive_name.tar.bz2

To extract in the current directory, or:

gen2extract -t /target/path archive_name.tar.bz2

To extract to the target path.

Explicit Single-threaded

Archives created with gen2stage4 can also be extracted with tar as well.

To preserve binary attributes and use numeric owner identifiers, you can simply append the relevant flags to the respective tar commands, e.g.:

tar xvpf archive_name.tar.bz2 --xattrs-include='*.*' --numeric-owner

To extract in the current directory, or:

tar xvpf archive_name.tar.bz2 --xattrs-include='*.*' --numeric-owner -C /target/path

To extract to the target path.

If you use the -k option, extract the src and modules archives separately:

tar xvpf archive_name.kmod.tar.bz2
tar xvpf archive_name.ksrc.tar.bz2

Explicit Multi-threaded

If you have a parallel de/compressor installed, you can extract the archive with one of the respective commands:

pbzip2

tar -I pbzip2 -xvf archive_name.tar.bz2 --xattrs-include='*.*' --numeric-owner

xz

tar -I 'xz -T0' -xvf archive_name.tar.xz --xattrs-include='*.*' --numeric-owner

gzip

Similarly to other compressors, gzip uses a separate binary for parallel decompression:

tar -I unpigz -xvf archive_name.tar.gz --xattrs-include='*.*' --numeric-owner

zst

tar -I 'zstd -T0' -xvf archive_name.tar.gz --xattrs-include='*.*' --numeric-owner

Dependencies

Please note that these are very basic dependencies and should already be included in any Linux system.

Optionals: If one the following is installed the archive will be compressed using multiple parallel threads when available, in order of succession: