2017-03-22 11:01:02 -04:00
# mkstage4
2014-05-18 17:52:33 -04:00
2014-05-18 17:59:40 -04:00
This is a bash script to create stage 4 tarballs either for the running system, or a system at a specified mount point.
The script is a new edition of an earlier [mkstage4 script ](https://github.com/gregf/bin/blob/master/mkstage4 ) by Greg Fitzgerald (unmaintained as of 2012) which is itself a revamped edition of the [original mkstage4 ](http://blinkeye.ch/dokuwiki/doku.php/projects/mkstage4 ) by Reto Glauser (unmaintaied as of 2009).
More information on mkstage4 can be found on its own Chymeric Tutorials article: [mkstage4 - Stage 4 Tarballs Made Easy ](http://tutorials.chymera.eu/blog/2014/05/18/mkstage4-stage4-tarballs-made-easy/ ).
2014-05-18 17:52:33 -04:00
2018-05-11 00:27:22 -04:00
Chinese Introduction [中文说明 ](http://liuk.io/blog/gentoo-stage4 )
2017-03-22 11:01:02 -04:00
## Installation
2014-09-18 02:18:20 -04:00
2014-09-13 19:24:51 -04:00
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):
2014-05-18 17:52:33 -04:00
```bash
2014-05-18 17:59:40 -04:00
git clone https://github.com/TheChymera/mkstage4.git /your/mkstage4/directory
2014-05-18 17:52:33 -04:00
cd /your/mkstage4/directory
chmod +x mkstage4.sh
```
2014-09-20 05:27:02 -04:00
For [Gentoo Linux ](http://en.wikipedia.org/wiki/Gentoo_linux ) and [Derivatives ](http://en.wikipedia.org/wiki/Category:Gentoo_Linux_derivatives ), mkstage4 is also available in [Portage ](http://en.wikipedia.org/wiki/Portage_(software )) via the *[chymeric overlay](https://github.com/TheChymera/chymeric)* (which can be enabled with just two commands, as seen in [the README ](https://github.com/TheChymera/chymeric )).
2014-09-13 19:24:51 -04:00
After you have enabled the overlay, just run the following command:
```
emerge app-backup/mkstage4
```
2014-09-18 02:18:20 -04:00
2017-03-22 11:01:02 -04:00
## Usage
2014-09-18 02:18:20 -04:00
2016-02-19 15:23:40 -05:00
*If you are running the script from the containing folder (first install method) please make sure you use the `./mkstage4.sh` command instead of just `mkstage4` !*
2014-09-13 19:24:51 -04:00
2014-05-18 17:52:33 -04:00
Archive your current system (mounted at /):
```bash
2014-09-13 19:24:51 -04:00
mkstage4 -s archive_name
2014-05-18 17:52:33 -04:00
```
Archive system located at a custom mount point:
```bash
2014-09-13 19:24:51 -04:00
mkstage4 -t /custom/mount/point archive_name
2014-05-18 17:52:33 -04:00
```
2016-02-23 00:38:51 -05:00
Command line arguments:
2014-05-18 17:52:33 -04:00
2016-02-23 00:38:51 -05:00
```
2018-05-10 23:13:12 -04:00
mkstage4.sh [-q -c -b -l -k] [-s || -t < target-mountpoint > ] [-e < additional excludes dir * > ] < archive-filename > [custom-tar-options]
2016-02-23 00:38:51 -05:00
-q: activates quiet mode (no confirmation).
-c: excludes connman network lists.
-b: excludes boot directory.
-l: excludes lost+found directory.
2018-05-10 23:13:12 -04:00
-e: an additional excludes directory (one dir one -e).
2016-02-23 00:38:51 -05:00
-s: makes tarball of current system.
2018-05-11 00:27:22 -04:00
-k: separately save current kernel modules and src (smaller & save decompression time).
2016-02-23 00:38:51 -05:00
-t: makes tarball of system located at the < target-mountpoint > .
-h: displays help message.
```
2014-05-18 17:52:33 -04:00
2018-05-11 00:27:22 -04:00
eg.
```bash
liuk@localhost ~/proj/mkstage4 $ sudo ./mkstage4.sh -l -s -k -e /dataA -e /home/liuk/dataZ1/ /dataB/gentoo-stage4-20180511 --exclude=/dataB/* --exclude=/ssd/*
Are you sure that you want to make a stage 4 tarball of the system
located under the following directory?
/
WARNING: since all data is saved by default the user should exclude all
security- or privacy-related files and directories, which are not
already excluded by mkstage4 options (such as -c), manually per cmdline.
example: $ mkstage4.sh -s /my-backup --exclude=/etc/ssh/ssh_host*
COMMAND LINE PREVIEW:
tar -cjpP --ignore-failed-read --exclude=/home/*/.bash_history --exclude=/dev/* --exclude=/var/tmp/* --exclude=/media/* --exclude=/mnt/*/* --exclude=/proc/* --exclude=/run/* --exclude=/sys/* --exclude=/tmp/* --exclude=/usr/portage/* --exclude=/var/lock/* --exclude=/var/log/* --exclude=/var/run/* --exclude=/dataA --exclude=/home/liuk/dataZ1/ --exclude=/usr/src/* --exclude=/lib64/modules/* --exclude=dataB/gentoo-stage4-20180511.tar.bz2 --exclude=lost+found --exclude=/dataB/* --exclude=/ssd/* -f /dataB/gentoo-stage4-20180511.tar.bz2 /*
tar -cjpP --ignore-failed-read -f /dataB/gentoo-stage4-20180511.tar.bz2.ksrc /usr/src/linux-4.16.6-gentoo*
tar -cjpP --ignore-failed-read -f /dataB/gentoo-stage4-20180511.tar.bz2.kmod /lib64/modules/4.16.6-gentoo*
Type "yes" to continue or anything else to quit: yes
```
### -k separately save current kernel modules and src
It will save current running kernel modules and src in separate tar file. It save decompression time.
2017-03-22 11:01:02 -04:00
## Extract Tarball
2014-05-18 17:52:33 -04:00
Tarballs created with mkstage4 can be extracted with:
```bash
tar xvjpf archive_name.tar.bz2
```
2018-05-11 00:27:22 -04:00
If you use -k option, extract src & modules separately
```bash
tar xvjpf archive_name.tar.bz2.kmod
tar xvjpf archive_name.tar.bz2.ksrc
```
2017-03-22 11:01:02 -04:00
## Dependencies
2014-05-18 17:52:33 -04:00
* **[Bash](https://en.wikipedia.org/wiki/Bash_(Unix_shell))** - in [Portage ](http://en.wikipedia.org/wiki/Portage_(software )) as **app-shells/bash**
* **[tar](https://en.wikipedia.org/wiki/Tar_(computing))** - in Portage as **app-arch/tar**
2014-09-18 02:25:24 -04:00
*Please note that these are very basic dependencies and should already be included in any Linux system.*
2014-05-18 17:52:33 -04:00
2014-09-13 19:24:51 -04:00
---
2014-05-18 17:52:33 -04:00
Released under the GPLv3 license.
Project led by Horea Christian (address all correspondence to: h.chr@mail.ru).