203.2. Maintaining a Linux filesystem

203.2 Maintaining a Linux filesystem​

Weight:3

Description: Candidates should be able to properly maintain a Linux filesystem using system utilities. This objective includes manipulating standard filesystems and monitoring SMART devices.

Key Knowledge Areas:

  • Tools and utilities to manipulate and ext2, ext3 and ext4

  • Tools and utilities to perform basic Btrfs operations, including subvolumes and snapshots

  • Tools and utilities to manipulate XFS

  • Awareness of ZFS

Terms and Utilities:

  • mkfs (mkfs.*)

  • mkswap

  • fsck (fsck.*)

  • tune2fs, dumpe2fs and debugfs

  • btrfs, btrfs-convert

  • xfs_info, xfs_check, xfs_repair, xfsdump and xfsrestore

  • smartd, smartctl

File Systems Overview

Since lpic 1 course we have got familiar with some File Systems. Lets Compare important ones:

File System

Architecture

Max File Size

Max Volume Size

extends

journal

snapshot

ext2 (1993)

h-tree

2 Tbytes

32 Tbytes

No

No

No

ext3 (2001)

h-tree

2 Tbytes

32 Tbytes

No

Yes

No

ext4 (2006)

h-tree

16 Tbytes

1 Ebytes

Yes

Yes

No

xfs (1994)

b-tree

8 Ebytes

8 Ebytes

No

Yes

Planned

btrfs (2009)

b-tree

16 Ebytes

16 Ebytes

Yes

Yes

Yes

mkfs

mkfs (Make a file System) command is used to create a File System on a device.To review LPIC1:

root@server1:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0   10G  0 part 
sr0     11:0    1 1024M  0 rom  
sda      8:0    0   50G  0 disk 
├─sda2   8:2    0    1K  0 part 
├─sda5   8:5    0 1021M  0 part [SWAP]
└─sda1   8:1    0   49G  0 part /

root@server1:~# which mkfs
/sbin/mkfs

We saw that mkfs is a front end for other commands:

root@server1:~# ls /sbin | grep mkfs
mkfs
mkfs.bfs
mkfs.cramfs
mkfs.ext2
mkfs.ext3
mkfs.ext4
mkfs.ext4dev
mkfs.fat
mkfs.minix
mkfs.msdos
mkfs.ntfs
mkfs.vfat

We can use mkfs.ext4 /dev/sdb1 to format a partition or in another format:

root@server1:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 2621184 4k blocks and 655360 inodes
Filesystem UUID: 3f940f9b-d46d-423e-9f20-4cf74564e7ac
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

mkswap

There is an exception among File Systems which is swap. We have mentioned that swap can be a file or an entire partition. To make a swap partition use mkswap /dev/sdXY command

File System maintenance Tools

Each file system has it own tools to maintain the problems.

fsck

fsck ( File System consistency check) is a tool for checking and repairing linux file system. Like mkfs, fsck is a front of other commands.

root@server1:~# which fsck
/sbin/fsck
root@server1:~# ls /sbin | grep fsck
dosfsck
e2fsck
fsck
fsck.cramfs
fsck.ext2
fsck.ext3
fsck.ext4
fsck.ext4dev
fsck.fat
fsck.minix
fsck.msdos
fsck.nfs
fsck.vfat
fsck.xfs

fsck is originally an ext tool . Try not to use fsck for other file systems because it might cause damage or data lost! How ever it is smart about other file systems like XFS and avoid running on them.

root@server1:~# mount /dev/sdb1 /mnt/my10gdisk/
root@server1:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sdb      8:16   0   10G  0 disk 
└─sdb1   8:17   0   10G  0 part /mnt/my10gdisk
sr0     11:0    1 1024M  0 rom  
sda      8:0    0   50G  0 disk 
├─sda2   8:2    0    1K  0 part 
├─sda5   8:5    0 1021M  0 part [SWAP]
└─sda1   8:1    0   49G  0 part /
root@server1:~# fsck /dev/sdb1
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
/dev/sdb1 is mounted.
e2fsck: Cannot continue, aborting.

Do not forget you can not check a filesystem while you are using that, so do not forget to unmount!!!

root@server1:~# umount /mnt/my10gdisk 
root@server1:~# fsck /dev/sdb1
fsck from util-linux 2.27.1
e2fsck 1.42.13 (17-May-2015)
/dev/sdb1: clean, 11/655360 files, 79663/2621184 blocks

fsck exit codes:

Based on health of ext Partition, different exit codes might be generated by fsck:

0-No errors
1-Filesystem errors corrected
2-System should be rebooted
4-Filesystem errors left uncorrected
8-Operational error
16-Usage or syntax error
32-Checking canceled by user request
128-Shared-library error

fsck usefull switeches

Description

-v

Produce Verbose output, include all file-system specific commands that are executed

-f

force fixing errors, ask conformation before each repair

-y

say "yes" to confirm fixing all errors

-n

emulate fixing errors, but no real write on hard disk

-N

Tell what fsck command will be run, and nothing is exexuted

-b <SuperBlockBackupLocation>

Restore super block from the backup

tune2fs

tune2fs Change different aspects of file system

root@server1:~# tune2fs --help
tune2fs 1.42.13 (17-May-2015)
tune2fs: invalid option -- '-'
Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-g group]
    [-i interval[d|m|w]] [-j] [-J journal_options] [-l]
    [-m reserved_blocks_percent] [-o [^]mount_options[,...]] [-p mmp_update_interval]
    [-r reserved_blocks_count] [-u user] [-C mount_count] [-L volume_label]
    [-M last_mounted_dir] [-O [^]feature[,...]]
    [-Q quota_options]
    [-E extended-option[,...]] [-T last_check_time] [-U UUID]
    [ -I new_inode_size ] device

fsck , tune2fs , fstab relation

Previously we see the fstab file for making automatic mounts, in the last field of fstab file we saw pass parameter:

# <file system> <mount point>   <type>  <options>       <dump>  <pass>
# / was on /dev/sda1 during installation
UUID=142a64e5-96f3-4789-9c91-1dc1570057b7 /               ext4    errors=remount-ro 0       1

We discussed then that the pass parameter can be 0, 1 or 2.

0

Never be checked by fsck during boot process

1

Check the partition with fsck duting boot with priority 1

2

Check the partition after other partitions with fsck priority2

But if you put 1 in fstab it would not work! Why? Because fsck look at other parameters of Partition File System and check intervals:

root@server1:~# tune2fs -l /dev/sdb1
tune2fs 1.42.13 (17-May-2015)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          395e0905-bcc7-4b8d-b3ca-3193c266b749
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655360
Block count:              2621184
Reserved block count:     131059
Free blocks:              2541521
Free inodes:              655349
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      639
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Sat Dec 30 04:03:38 2017
Last mount time:          Sat Dec 30 04:03:54 2017
Last write time:          Sat Dec 30 04:44:35 2017
Mount count:              0
Maximum mount count:      -1
Last checked:             Sat Dec 30 04:44:35 2017
Check interval:           0 (<none>)
Lifetime writes:          291 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:              256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      54a34eb1-0de8-40af-8e37-e4817b1f3046
Journal backup:           inode blocks

Among this long list Check interval and mount count are realy important. fsck check partitions we have mentioned in fstab if specific time interval arrives or number of mount count reach.

usefull commands

Description

tune2fs -L KING8GIG /dev/sdc1

Change Volume Name

tune2fs -i 7 /dev/sdb1

Change check interval to 7 days

tune2fs -c 10 /dev/sdb1

Change mount count to 10 times

tune2fs -m 0 /dev/sdb1

Change reserved Blocks to 0

dumpe2fs

dumpe2fs Show all super blocks info. SuperBlocks are kind of meta data of File System which keeps information about size, block size, the empty and filled blocks, size and location of inodes and many many more information. dumpe2fs can be used while partition is mounted.

root@server1:~# dumpe2fs /dev/sdb1
dumpe2fs 1.42.13 (17-May-2015)
Filesystem volume name:   <none>
Last mounted on:          <not available>
Filesystem UUID:          395e0905-bcc7-4b8d-b3ca-3193c266b749
Filesystem magic number:  0xEF53
Filesystem revision #:    1 (dynamic)
Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent flex_bg sparse_super large_file huge_file uninit_bg dir_nlink extra_isize
Filesystem flags:         signed_directory_hash 
Default mount options:    user_xattr acl
Filesystem state:         clean
Errors behavior:          Continue
Filesystem OS type:       Linux
Inode count:              655360
Block count:              2621184
Reserved block count:     131059
Free blocks:              2541521
Free inodes:              655349
First block:              0
Block size:               4096
Fragment size:            4096
Reserved GDT blocks:      639
Blocks per group:         32768
Fragments per group:      32768
Inodes per group:         8192
Inode blocks per group:   512
Flex block group size:    16
Filesystem created:       Sat Dec 30 04:03:38 2017
Last mount time:          Sat Dec 30 04:03:54 2017
Last write time:          Sat Dec 30 04:05:42 2017
Mount count:              1
Maximum mount count:      -1
Last checked:             Sat Dec 30 04:03:38 2017
Check interval:           0 (<none>)
Lifetime writes:          291 MB
Reserved blocks uid:      0 (user root)
Reserved blocks gid:      0 (group root)
First inode:              11
Inode size:              256
Required extra isize:     28
Desired extra isize:      28
Journal inode:            8
Default directory hash:   half_md4
Directory Hash Seed:      54a34eb1-0de8-40af-8e37-e4817b1f3046
Journal backup:           inode blocks
Journal features:         (none)
Journal size:             128M
Journal length:           32768
Journal sequence:         0x00000004
Journal start:            0


Group 0: (Blocks 0-32767) [ITABLE_ZEROED]
  Checksum 0xe944, unused inodes 8181
  Primary superblock at 0, Group descriptors at 1-1
  Reserved GDT blocks at 2-640
  Block bitmap at 641 (+641), Inode bitmap at 657 (+657)
  Inode table at 673-1184 (+673)
  23897 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
  Free blocks: 8871-32767
  Free inodes: 12-8192
Group 1: (Blocks 32768-65535) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Checksum 0xda21, unused inodes 8192
  Backup superblock at 32768, Group descriptors at 32769-32769
  Reserved GDT blocks at 32770-33408
  Block bitmap at 642 (bg #0 + 642), Inode bitmap at 658 (bg #0 + 658)
  Inode table at 1185-1696 (bg #0 + 1185)
  32127 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 33409-65535
  Free inodes: 8193-16384
Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Checksum 0x8c02, unused inodes 8192
  Block bitmap at 643 (bg #0 + 643), Inode bitmap at 659 (bg #0 + 659)
  Inode table at 1697-2208 (bg #0 + 1697)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 65536-98303
  Free inodes: 16385-24576
.
..
...

Group 78: (Blocks 2555904-2588671) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
  Checksum 0x2104, unused inodes 8192
  Block bitmap at 2097166 (bg #64 + 14), Inode bitmap at 2097182 (bg #64 + 30)
  Inode table at 2104352-2104863 (bg #64 + 7200)
  32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 2555904-2588671
  Free inodes: 638977-647168
Group 79: (Blocks 2588672-2621183) [INODE_UNINIT, ITABLE_ZEROED]
  Checksum 0x8657, unused inodes 8192
  Block bitmap at 2097167 (bg #64 + 15), Inode bitmap at 2097183 (bg #64 + 31)
  Inode table at 2104864-2105375 (bg #64 + 7712)
  32512 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
  Free blocks: 2588672-2621183
  Free inodes: 647169-655360

As superbloacks are so important Files System is designed to keep back of them by copying them on several places of hard disk.

root@server1:~# dumpe2fs /dev/sdb1 | grep -i Superblock
dumpe2fs 1.42.13 (17-May-2015)
  Primary superblock at 0, Group descriptors at 1-1
  Backup superblock at 32768, Group descriptors at 32769-32769
  Backup superblock at 98304, Group descriptors at 98305-98305
  Backup superblock at 163840, Group descriptors at 163841-163841
  Backup superblock at 229376, Group descriptors at 229377-229377
  Backup superblock at 294912, Group descriptors at 294913-294913
  Backup superblock at 819200, Group descriptors at 819201-819201
  Backup superblock at 884736, Group descriptors at 884737-884737
  Backup superblock at 1605632, Group descriptors at 1605633-1605633

There is another way to observe location of super blocks backup:

root@server1:~# mkfs.ext4 -n /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
/dev/sdb1 contains a ext4 file system
    last mounted on Sat Dec 30 04:03:54 2017
Proceed anyway? (y,n) y
Creating filesystem with 2621184 4k blocks and 655360 inodes
Filesystem UUID: 9979d6a3-985e-4435-b445-f399f3715e79
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632

-n cuase no changes on Hard disk and just show what it would do if it were to create a file system. And finally try dumpe2fs -h to get information about super blocks. Try it your self :)

debugfs

debugfs interactive file system editor.Its better to unmount the partition first.

root@server1:~# debugfs /dev/sdb1
debugfs 1.42.13 (17-May-2015)
debugfs:  help

Available debugfs requests:

show_debugfs_params, params
                         Show debugfs parameters
open_filesys, open       Open a filesystem
close_filesys, close     Close the filesystem
freefrag, e2freefrag     Report free space fragmentation
feature, features        Set/print superblock features
dirty_filesys, dirty     Mark the filesystem as dirty
init_filesys             Initialize a filesystem (DESTROYS DATA)
show_super_stats, stats  Show superblock statistics
ncheck                   Do inode->name translation
icheck                   Do block->inode translation
change_root_directory, chroot
                         Change root directory
change_working_directory, cd
                         Change working directory
list_directory, ls       List directory
show_inode_info, stat    Show inode information 
dump_extents, extents, ex
                         Dump extents information 
blocks                   Dump blocks used by an inode 
filefrag                 Report fragmentation information for an inode
link, ln                 Create directory link
unlink                   Delete a directory link
mkdir                    Create a directory
rmdir                    Remove a directory
rm                       Remove a file (unlink and kill_file, if appropriate)
kill_file                Deallocate an inode and its blocks
clri                     Clear an inode's contents
freei                    Clear an inode's in-use flag
seti                     Set an inode's in-use flag
testi                    Test an inode's in-use flag
freeb                    Clear a block's in-use flag
setb                     Set a block's in-use flag
testb                    Test a block's in-use flag
modify_inode, mi         Modify an inode by structure
find_free_block, ffb     Find free block(s)
find_free_inode, ffi     Find free inode(s)
print_working_directory, pwd
                         Print current working directory
expand_dir, expand       Expand directory
mknod                    Create a special file
list_deleted_inodes, lsdel
                         List deleted inodes
undelete, undel          Undelete file
write                    Copy a file from your native filesystem
dump_inode, dump         Dump an inode out to a file
cat                      Dump an inode out to stdout
lcd                      Change the current directory on your native filesystem
rdump                    Recursively dump a directory to the native filesystem
set_super_value, ssv     Set superblock value
set_inode_field, sif     Set inode field
set_block_group, set_bg  Set block group descriptor field
logdump                  Dump the contents of the journal
htree_dump, htree        Dump a hash-indexed directory
dx_hash, hash            Calculate the directory hash of a filename
dirsearch                Search a directory for a particular filename
bmap                     Calculate the logical->physical block mapping for an inode
punch, truncate          Punch (or truncate) blocks from an inode by deallocating them
symlink                  Create a symbolic link
imap                     Calculate the location of an inode
dump_unused              Dump unused blocks
set_current_time         Set current time to use when setting filesystem fields
supported_features       Print features supported by this version of e2fsprogs
dump_mmp                 Dump MMP information
set_mmp_value, smmp      Set MMP value
extent_open, eo          Open inode for extent manipulation
zap_block, zap           Zap block: fill with 0, pattern, flip bits etc.
block_dump, bdump, bd    Dump contents of a block
list_quota, lq           List quota
get_quota, gq            Get quota
inode_dump, idump, id    Dump the inode structure in hex
help                     Display info on command or topic.
list_requests, lr, ?     List available commands.
quit, q                  Leave the subsystem.

maintenance XFS File System

XFS File System has its own tools.Base on our distro we might need to install xfsprogs to use XFS tools but XFS is Redhat Favorite File system so we use centOS7 here:

[root@server1 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0 45.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
└─sdb1            8:17   0   10G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@server1 ~]# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0, sparse=0
data     =                       bsize=4096   blocks=2621184, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal log           bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

[root@server1 ~]# xfs
xfs_admin      xfs_estimate   xfsinvutil     xfs_mkfile     xfs_rtcp
xfs_bmap       xfs_freeze     xfs_io         xfs_ncheck     
xfs_copy       xfs_fsr        xfs_logprint   xfs_quota      
xfs_db         xfs_growfs     xfs_mdrestore  xfs_repair     
xfsdump        xfs_info       xfs_metadump   xfsrestore

Okey we have Formatted and re partitioned /dev/sdb1 lets get to know about some XFS File System tools:

xfsprogs

Description

xfs_info

Give info about XFS Partition, partition must be mounted

xfs_repair

Fix XFS File System problem

xfs_check

Depricated ! Check XFS File System problems with no verbosity, use -v or "xfs_repair -n" instead

xfsdump & xfsrestore

XFS backup and restore commands, They can work with mounted partition as they are Backup & Restore process

xfs_info

[root@server1 ~]# mkdir /mnt/my10gxfs
[root@server1 ~]# mount /dev/sdb1 /mnt/my10gxfs/
[root@server1 ~]# xfs_info /mnt/my10gxfs/
meta-data=/dev/sdb1              isize=512    agcount=4, agsize=655296 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=1        finobt=0 spinodes=0
data     =                       bsize=4096   blocks=2621184, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=1
log      =internal               bsize=4096   blocks=2560, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0

xfs_repair

[root@server1 ~]# umount /mnt/my10gxfs/

[root@server1 ~]# xfs_repair -n /dev/sdb1
Phase 1 - find and verify superblock...
Phase 2 - using internal log
        - zero log...
        - scan filesystem freespace and inode maps...
        - found root inode chunk
Phase 3 - for each AG...
        - scan (but don't clear) agi unlinked lists...
        - process known inodes and perform inode discovery...
        - agno = 0
        - agno = 1
        - agno = 2
        - agno = 3
        - process newly discovered inodes...
Phase 4 - check for duplicate blocks...
        - setting up duplicate extent list...
        - check for inodes claiming duplicate blocks...
        - agno = 0
        - agno = 2
        - agno = 3
        - agno = 1
No modify flag set, skipping phase 5
Phase 6 - check inode connectivity...
        - traversing filesystem ...
        - traversal finished ...
        - moving disconnected inodes to lost+found ...
Phase 7 - verify link counts...
No modify flag set, skipping filesystem flush and exiting.

and if any problems have found use xfs_repair for that.

xfsdump , xfsrestore

There are two old xfs commands for backing up and restoring. They history back to days when tape media were only backup media.

[root@server1 ~]# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda               8:0    0   50G  0 disk 
├─sda1            8:1    0    1G  0 part /boot
└─sda2            8:2    0   49G  0 part 
  ├─centos-root 253:0    0 45.1G  0 lvm  /
  └─centos-swap 253:1    0  3.9G  0 lvm  [SWAP]
sdb               8:16   0   10G  0 disk 
└─sdb1            8:17   0   10G  0 part 
sr0              11:0    1 1024M  0 rom  
[root@server1 ~]# mount -t xfs /dev/sdb1 /mnt/my10gxfs/
[root@server1 ~]# mkdir /mnt/mybackups
[root@server1 ~]# cd /mnt/mybackups/

[root@server1 mybackups]# xfsdump -f /mnt/mybackups/backup1jun18 /mnt/my10gxfs
xfsdump: using file dump (drive_simple) strategy
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control

 ============================= dump label dialog ==============================

please enter label for this dump session (timeout in 300 sec)
 -> etcbackup
session label entered: "etcbackup"

 --------------------------------- end dialog ---------------------------------

xfsdump: level 0 dump of server1:/mnt/my10gxfs
xfsdump: dump date: Mon Jan  1 02:03:26 2018
xfsdump: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97
xfsdump: session label: "etcbackup"
xfsdump: ino map phase 1: constructing initial dump list
xfsdump: ino map phase 2: skipping (no pruning necessary)
xfsdump: ino map phase 3: skipping (only one dump stream)
xfsdump: ino map construction complete
xfsdump: estimated dump size: 20800 bytes
xfsdump: /var/lib/xfsdump/inventory created

 ============================= media label dialog =============================

please enter label for media in drive 0 (timeout in 300 sec)

-> bak1jun18label
media label entered: "bak1jun18label"

 --------------------------------- end dialog ---------------------------------

xfsdump: creating dump session media file 0 (media 0, file 0)
xfsdump: dumping ino map
xfsdump: dumping directories
xfsdump: dumping non-directory files
xfsdump: ending media file
xfsdump: media file size 21016 bytes
xfsdump: dump size (non-dir files) : 0 bytes
xfsdump: dump complete: 201 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /mnt/mybackups/backup1jun18 OK (success)
xfsdump: Dump Status: SUCCESS

There Three levels of backups that can be done woth xfsdump

xfsdump backup level

descriptio

0

Full backup

1

Only backup changed Files since Last backup

2

Backup File Changes since last full or Incremental Backup

Lets see the result:

[root@server1 mybackups]# ls
backup1jun18
[root@server1 mybackups]# cat backup1jun18 
xFSdump0"v��ZI�>������zH,����I,��Ӿ����server1etcbackupQbak1jun18label�z]4��K7�?`%�\s�/mnt/my10gxfs/dev/sdb1xfs�n$��tG��P���ᳵ?�@@@#��c@A�ZI�ÎZI�Î��������

and try to restore:

[root@server1 mnt]# xfsrestore -f /mnt/mybackups/backup1jun18 /mnt/restore/
xfsrestore: using file dump (drive_simple) strategy
xfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and control
xfsrestore: searching media for dump
xfsrestore: examining media file 0
xfsrestore: dump description: 
xfsrestore: hostname: server1
xfsrestore: mount point: /mnt/my10gxfs
xfsrestore: volume: /dev/sdb1
xfsrestore: session time: Mon Jan  1 02:03:26 2018
xfsrestore: level: 0
xfsrestore: session label: "etcbackup"
xfsrestore: media label: "bak1jun18label"
xfsrestore: file system id: 966e24bf-dc74-47ba-a250-80fe84e1b3b5
xfsrestore: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97
xfsrestore: media id: e87a5d34-a49b-4b37-a33f-6025ab5c73eb
xfsrestore: using online session inventory
xfsrestore: searching media for directory dump
xfsrestore: reading directories
xfsrestore: 1 directories and 0 entries processed
xfsrestore: directory post-processing
xfsrestore: restore complete: 0 seconds elapsed
xfsrestore: Restore Summary:
xfsrestore:   stream 0 /mnt/mybackups/backup1jun18 OK (success)
xfsrestore: Restore Status: SUCCESS

[root@server1 mnt]# cd my10gxfs/
[root@server1 my10gxfs]# ls

As you might not be an only admin of system use xfsrestore -I command to have a list of what ever has been backed up with xfsdump, including file sessions IDs and backup session IDs:

[root@server1 my10gxfs]# xfsrestore -I
file system 0:
    fs id:        966e24bf-dc74-47ba-a250-80fe84e1b3b5
    session 0:
        mount point:    server1:/mnt/my10gxfs
        device:        server1:/dev/sdb1
        time:        Mon Jan  1 02:03:26 2018
        session label:    "etcbackup"
        session id:    482cd1f2-eed5-492c-bf8b-d3befb97be97
        level:        0
        resumed:    NO
        subtree:    NO
        streams:    1
        stream 0:
            pathname:    /mnt/mybackups/backup1jun18
            start:        ino 0 offset 0
            end:        ino 1 offset 0
            interrupted:    NO
            media files:    1
            media file 0:
                mfile index:    0
                mfile type:    data
                mfile size:    21016
                mfile start:    ino 0 offset 0
                mfile end:    ino 1 offset 0
                media label:    "bak1jun18label"
                media id:    e87a5d34-a49b-4b37-a33f-6025ab5c73eb
xfsrestore: Restore Status: SUCCESS

smartd , smartctl

S.M.A.R.T. (Self-Monitoring, Analysis and Reporting Technology) is a monitoring system included in computer hard disk drives (HDDs) and even solid-state drives (SSDs).So it is not linux specific tool or feature . it its duty is monitoring various indicators of Drive reliability in order to avoid hardware failures . Usually there is a software or 3rd party utility which is running on Host operating system which reads SMART data and notify user about health status of Disk Drive to avoid data lost.

Linux has two tiny tools smartd and smartctl for reading SMART data.Based on your distro you might need install smartmontool.

root@server1:~# apt install smartmontools

and to check weather our hard disk supports SMART and its enabled:

root@server1:~# smartctl -i /dev/sda
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Samsung based SSDs
Device Model:     Samsung SSD 850 EVO 500GB
Serial Number:    S2R9NX0H503451W
LU WWN Device Id: 5 002538 d40e515dc
Firmware Version: EMT02B6Q
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Form Factor:      2.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4c
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon Jan  1 13:37:38 2018 +0330
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

to do the <short|long|...> test on hard disk :

root@server1:~# smartctl -t 
afterselect,off  long             scttempint,      select,redo
afterselect,on   offline          select,          short
conveyance       pending,         select,next      vendor,

root@server1:~# smartctl -t short /dev/sda
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
Testing has begun.
Please wait 2 minutes for test to complete.
Test will complete after Mon Jan  1 13:45:37 2018

Use smartctl -X to abort test.

and for watching results:

root@server1:~# smartctl -a /dev/sda
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===
Model Family:     Samsung based SSDs
Device Model:     Samsung SSD 850 EVO 500GB
Serial Number:    S2R9NX0H503451W
LU WWN Device Id: 5 002538 d40e515dc
Firmware Version: EMT02B6Q
User Capacity:    500,107,862,016 bytes [500 GB]
Sector Size:      512 bytes logical/physical
Rotation Rate:    Solid State Device
Form Factor:      2.5 inches
Device is:        In smartctl database [for details use: -P show]
ATA Version is:   ACS-2, ATA8-ACS T13/1699-D revision 4c
SATA Version is:  SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
Local Time is:    Mon Jan  1 14:02:06 2018 +0330
SMART support is: Available - device has SMART capability.
SMART support is: Enabled

=== START OF READ SMART DATA SECTION ===
SMART overall-health self-assessment test result: PASSED

General SMART Values:
Offline data collection status:  (0x00)    Offline data collection activity
                    was never started.
                    Auto Offline Data Collection: Disabled.
Self-test execution status:      (   0)    The previous self-test routine completed
                    without error or no self-test has ever 
                    been run.
Total time to complete Offline 
data collection:         (    0) seconds.
Offline data collection
capabilities:              (0x53) SMART execute Offline immediate.
                    Auto Offline data collection on/off support.
                    Suspend Offline collection upon new
                    command.
                    No Offline surface scan supported.
                    Self-test supported.
                    No Conveyance Self-test supported.
                    Selective Self-test supported.
SMART capabilities:            (0x0003)    Saves SMART data before entering
                    power-saving mode.
                    Supports SMART auto save timer.
Error logging capability:        (0x01)    Error logging supported.
                    General Purpose Logging supported.
Short self-test routine 
recommended polling time:      (   2) minutes.
Extended self-test routine
recommended polling time:      ( 265) minutes.
SCT capabilities:            (0x003d)    SCT Status supported.
                    SCT Error Recovery Control supported.
                    SCT Feature Control supported.
                    SCT Data Table supported.

SMART Attributes Data Structure revision number: 1
Vendor Specific SMART Attributes with Thresholds:
ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE
  5 Reallocated_Sector_Ct   0x0033   100   100   010    Pre-fail  Always       -       0
  9 Power_On_Hours          0x0032   099   099   000    Old_age   Always       -       1136
 12 Power_Cycle_Count       0x0032   098   098   000    Old_age   Always       -       1292
177 Wear_Leveling_Count     0x0013   099   099   000    Pre-fail  Always       -       6
179 Used_Rsvd_Blk_Cnt_Tot   0x0013   100   100   010    Pre-fail  Always       -       0
181 Program_Fail_Cnt_Total  0x0032   100   100   010    Old_age   Always       -       0
182 Erase_Fail_Count_Total  0x0032   100   100   010    Old_age   Always       -       0
183 Runtime_Bad_Block       0x0013   100   100   010    Pre-fail  Always       -       0
187 Uncorrectable_Error_Cnt 0x0032   100   100   000    Old_age   Always       -       0
190 Airflow_Temperature_Cel 0x0032   068   052   000    Old_age   Always       -       32
195 ECC_Error_Rate          0x001a   200   200   000    Old_age   Always       -       0
199 CRC_Error_Count         0x003e   100   100   000    Old_age   Always       -       0
235 POR_Recovery_Count      0x0012   099   099   000    Old_age   Always       -       72
241 Total_LBAs_Written      0x0032   099   099   000    Old_age   Always       -       7397082470

SMART Error Log Version: 1
No Errors Logged

SMART Self-test log structure revision number 1
Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error
# 1  Short offline       Completed without error       00%      1135         -
# 2  Short offline       Completed without error       00%         1         -

SMART Selective self-test log data structure revision number 1
 SPAN  MIN_LBA  MAX_LBA  CURRENT_TEST_STATUS
    1        0        0  Not_testing
    2        0        0  Not_testing
    3        0        0  Not_testing
    4        0        0  Not_testing
    5        0        0  Not_testing
  255        0    65535  Read_scanning was never started
Selective self-test flags (0x0):
  After scanning selected spans, do NOT read-scan remainder of disk.
If Selective self-test is pending on power-up, resume after 0 minute delay.

some other usefull smartctl commands:

smartctl command

Description

smartctl -h /dev/sda

Print Help

smartctl -H /dev/sda

Print Health Status of Disk Drive

smartctl -c /dev/sda

Print SMART capabilities that have been implemented

Monitoring Disk Health inorder to avoid data lost can be an every day task, but SMART has deamon smartd wich dose it for us:

lets enable and use it vi /etc/default/smartmontools :

# Defaults for smartmontools initscript (/etc/init.d/smartmontools)
# This is a POSIX shell fragment

# List of devices you want to explicitly enable S.M.A.R.T. for
# Not needed (and not recommended) if the device is monitored by smartd
#enable_smart="/dev/hda /dev/hdb"

# uncomment to start smartd on system startup
start_smartd=yes

# uncomment to pass additional options to smartd on startup
#smartd_opts="--interval=1800"

and make sure smartd is running and enabled:

root@server1:~# systemctl list-unit-files --type=service  | grep -i smart
smartd.service                             enabled 
smartmontools.service                      enabled 
root@server1:~# systemctl status smartd
● smartd.service - Self Monitoring and Reporting Technology (SMART) Daemon
   Loaded: loaded (/lib/systemd/system/smartd.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2018-01-01 13:35:51 +0330; 43min ago
     Docs: man:smartd(8)
           man:smartd.conf(5)
 Main PID: 4507 (smartd)
   CGroup: /system.slice/smartd.service
           └─4507 /usr/sbin/smartd -n

Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda, type changed from 'scsi' to 'sat'
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], opened
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], Samsung SSD 850 EVO 500GB, S/N:S2R9NX0H503451W, WWN:5-002538-d40e515dc, FW:EMT02B6Q, 5
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], found in smartd database: Samsung based SSDs
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.
Jan 01 13:35:51 server1 smartd[4507]: Monitoring 1 ATA and 0 SCSI devices
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], state written to /var/lib/smartmontools/smartd.Samsung_SSD_850_EVO_500GB-S2R9NX0H50345
Jan 01 13:35:51 server1 systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.

Last updated