­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ ­ # Save Filesystem layout Log "Begin saving filesystem layout" # If available wipefs is used in the recovery system by 130_include_filesystem_code.sh # as a generic way to cleanup disk partitions before creating a filesystem on a disk partition, # see https://github.com/rear/rear/issues/540 # and https://github.com/rear/rear/issues/649#issuecomment-148725865 # Therefore if wipefs exists here in the original system it is added to REQUIRED_PROGS # so that it will become also available in the recovery system (cf. 260_crypt_layout.sh): has_binary wipefs && REQUIRED_PROGS+=( wipefs ) || true # Comma separated list of filesystems that is used for "mount/findmnt -t " below: supported_filesystems="ext2,ext3,ext4,vfat,xfs,reiserfs,btrfs" # Read filesystem information from the system by default using the traditional mount command # limited to only the supported filesystems which results output lines of the form # device mountpoint filesystem (list,of,options) # for example # /dev/sda2 / btrfs (rw,relatime,space_cache) # /dev/sda2 /.snapshots btrfs (rw,relatime,space_cache) # /dev/sda2 /var/tmp btrfs (rw,relatime,space_cache) read_filesystems_command="mount -t $supported_filesystems | cut -d ' ' -f 1,3,5,6" # If the findmnt command is available use it instead of the traditional mount command # because (since SLE12) "man 8 mount" reads: # The listing mode is maintained for backward compatibility only. # For more robust and customizable output use findmnt(8), especially in your scripts. # It is limited to only the supported filesystems which results output lines of the form # device mountpoint filesystem list,of,options # for example # /dev/sda2 / btrfs rw,relatime,space_cache # /dev/sda2 /.snapshots btrfs rw,relatime,space_cache # /dev/sda2 /var/tmp btrfs rw,relatime,space_cache # The only difference is that the traditional mount command output has the list of options in parenthesis. findmnt_command="$( type -P findmnt )" if test -x "$findmnt_command" ; then # Use the (deprecated) "findmnt -m" to avoid issues # as in https://github.com/rear/rear/issues/882 # FIXME: Replace using the deprecated '-m' option with a future proof solution. read_filesystems_command="$findmnt_command -mnrv -o SOURCE,TARGET,FSTYPE,OPTIONS -t $supported_filesystems" Log "Saving filesystem layout (using the findmnt command)." else Log "Saving filesystem layout (using the traditional mount command)." fi # Remove duplicate lines for the same device: # -t ' ' space is the field delimiter # -k 1,1 the sort key starts and ends at field 1 (i.e. device is the only sort key) # -u unique regarding the sort key (i.e. remove duplicate lines regarding the sort key) # so that in the above example the resulting output using the traditional mount command is # /dev/sda2 / btrfs (rw,relatime,space_cache) # and the resulting output using using the findmnt command is # /dev/sda2 / btrfs rw,relatime,space_cache # The sorting relies on that mount and findmnt output the first mounted thing first # so that in particular what is mounted at '/' is output before other stuff. read_filesystems_command="$read_filesystems_command | sort -t ' ' -k 1,1 -u" # The Docker daemon mounts file systems for its Docker containers, see also # https://docs.docker.com/storage/storagedriver/device-mapper-driver/#configure-direct-lvm-mode-for-production # As it is for container usage only we do not to backup these up or recreate as this disk device is completely # under control by Docker itself (even the recreation of it incl, the creation of the volume group). # Usually this is done via a kind of cookbook (Chef, puppet or ansible). docker_is_running="" docker_root_dir="" if service docker status ; then docker_is_running="yes" # When the Docker daemon/service is running, try to get its 'Docker Root Dir': # Kill 'docker info' with SIGTERM after 5 seconds and with SIGKILL after additional 2 seconds # because there are too many crippled Docker installations, cf. https://github.com/rear/rear/pull/2021 docker_root_dir=$( timeout -k 2s 5s docker info | grep 'Docker Root Dir' | awk '{print $4}' ) # Things may go wrong in the 'Docker specific exclude part' below # when Docker is used but its 'Docker Root Dir' cannot be determined # cf. https://github.com/rear/rear/issues/1989 if test "$docker_root_dir" ; then LogPrint "Docker is running, skipping filesystems mounted below Docker Root Dir $docker_root_dir" else LogPrintError "Cannot determine Docker Root Dir - things may go wrong - check $DISKLAYOUT_FILE" fi fi # Begin of the subshell that appends its stdout to DISKLAYOUT_FILE: ( echo "# Filesystems (only $supported_filesystems are supported)." echo "# Format: fs [uuid=] [label=