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:
2
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3
sdb 8:16 0 10G 0 disk
4
└─sdb1 8:17 0 10G 0 part
5
sr0 11:0 1 1024M 0 rom
6
sda 8:0 0 50G 0 disk
7
├─sda2 8:2 0 1K 0 part
8
├─sda5 8:5 0 1021M 0 part [SWAP]
9
└─sda1 8:1 0 49G 0 part /
10
11
[email protected]:~# which mkfs
12
/sbin/mkfs
Copied!
We saw that mkfs is a front end for other commands:
1
[email protected]:~# ls /sbin | grep mkfs
2
mkfs
3
mkfs.bfs
4
mkfs.cramfs
5
mkfs.ext2
6
mkfs.ext3
7
mkfs.ext4
8
mkfs.ext4dev
9
mkfs.fat
10
mkfs.minix
11
mkfs.msdos
12
mkfs.ntfs
13
mkfs.vfat
Copied!
We can use mkfs.ext4 /dev/sdb1 to format a partition or in another format:
1
[email protected]:~# mkfs -t ext4 /dev/sdb1
2
mke2fs 1.42.13 (17-May-2015)
3
Creating filesystem with 2621184 4k blocks and 655360 inodes
4
Filesystem UUID: 3f940f9b-d46d-423e-9f20-4cf74564e7ac
5
Superblock backups stored on blocks:
6
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
7
8
Allocating group tables: done
9
Writing inode tables: done
10
Creating journal (32768 blocks): done
11
Writing superblocks and filesystem accounting information: done
Copied!

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.
1
[email protected]:~# which fsck
2
/sbin/fsck
3
[email protected]:~# ls /sbin | grep fsck
4
dosfsck
5
e2fsck
6
fsck
7
fsck.cramfs
8
fsck.ext2
9
fsck.ext3
10
fsck.ext4
11
fsck.ext4dev
12
fsck.fat
13
fsck.minix
14
fsck.msdos
15
fsck.nfs
16
fsck.vfat
17
fsck.xfs
Copied!
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.
1
[email protected]:~# mount /dev/sdb1 /mnt/my10gdisk/
3
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
4
sdb 8:16 0 10G 0 disk
5
└─sdb1 8:17 0 10G 0 part /mnt/my10gdisk
6
sr0 11:0 1 1024M 0 rom
7
sda 8:0 0 50G 0 disk
8
├─sda2 8:2 0 1K 0 part
9
├─sda5 8:5 0 1021M 0 part [SWAP]
10
└─sda1 8:1 0 49G 0 part /
11
[email protected]:~# fsck /dev/sdb1
12
fsck from util-linux 2.27.1
13
e2fsck 1.42.13 (17-May-2015)
14
/dev/sdb1 is mounted.
15
e2fsck: Cannot continue, aborting.
Copied!
Do not forget you can not check a filesystem while you are using that, so do not forget to unmount!!!
1
[email protected]:~# umount /mnt/my10gdisk
2
[email protected]:~# fsck /dev/sdb1
3
fsck from util-linux 2.27.1
4
e2fsck 1.42.13 (17-May-2015)
5
/dev/sdb1: clean, 11/655360 files, 79663/2621184 blocks
Copied!

fsck exit codes:

Based on health of ext Partition, different exit codes might be generated by fsck:
1
0-No errors
2
1-Filesystem errors corrected
3
2-System should be rebooted
4
4-Filesystem errors left uncorrected
5
8-Operational error
6
16-Usage or syntax error
7
32-Checking canceled by user request
8
128-Shared-library error
Copied!
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
1
[email protected]:~# tune2fs --help
2
tune2fs 1.42.13 (17-May-2015)
3
tune2fs: invalid option -- '-'
4
Usage: tune2fs [-c max_mounts_count] [-e errors_behavior] [-g group]
5
[-i interval[d|m|w]] [-j] [-J journal_options] [-l]
6
[-m reserved_blocks_percent] [-o [^]mount_options[,...]] [-p mmp_update_interval]
7
[-r reserved_blocks_count] [-u user] [-C mount_count] [-L volume_label]
8
[-M last_mounted_dir] [-O [^]feature[,...]]
9
[-Q quota_options]
10
[-E extended-option[,...]] [-T last_check_time] [-U UUID]
11
[ -I new_inode_size ] device
Copied!

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:
1
# <file system> <mount point> <type> <options> <dump> <pass>
2
# / was on /dev/sda1 during installation
3
UUID=142a64e5-96f3-4789-9c91-1dc1570057b7 / ext4 errors=remount-ro 0 1
Copied!
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:
1
[email protected]:~# tune2fs -l /dev/sdb1
2
tune2fs 1.42.13 (17-May-2015)
3
Filesystem volume name: <none>
4
Last mounted on: <not available>
5
Filesystem UUID: 395e0905-bcc7-4b8d-b3ca-3193c266b749
6
Filesystem magic number: 0xEF53
7
Filesystem revision #: 1 (dynamic)
8
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
9
Filesystem flags: signed_directory_hash
10
Default mount options: user_xattr acl
11
Filesystem state: clean
12
Errors behavior: Continue
13
Filesystem OS type: Linux
14
Inode count: 655360
15
Block count: 2621184
16
Reserved block count: 131059
17
Free blocks: 2541521
18
Free inodes: 655349
19
First block: 0
20
Block size: 4096
21
Fragment size: 4096
22
Reserved GDT blocks: 639
23
Blocks per group: 32768
24
Fragments per group: 32768
25
Inodes per group: 8192
26
Inode blocks per group: 512
27
Flex block group size: 16
28
Filesystem created: Sat Dec 30 04:03:38 2017
29
Last mount time: Sat Dec 30 04:03:54 2017
30
Last write time: Sat Dec 30 04:44:35 2017
31
Mount count: 0
32
Maximum mount count: -1
33
Last checked: Sat Dec 30 04:44:35 2017
34
Check interval: 0 (<none>)
35
Lifetime writes: 291 MB
36
Reserved blocks uid: 0 (user root)
37
Reserved blocks gid: 0 (group root)
38
First inode: 11
39
Inode size: 256
40
Required extra isize: 28
41
Desired extra isize: 28
42
Journal inode: 8
43
Default directory hash: half_md4
44
Directory Hash Seed: 54a34eb1-0de8-40af-8e37-e4817b1f3046
45
Journal backup: inode blocks
Copied!
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.
1
[email protected]:~# dumpe2fs /dev/sdb1
2
dumpe2fs 1.42.13 (17-May-2015)
3
Filesystem volume name: <none>
4
Last mounted on: <not available>
5
Filesystem UUID: 395e0905-bcc7-4b8d-b3ca-3193c266b749
6
Filesystem magic number: 0xEF53
7
Filesystem revision #: 1 (dynamic)
8
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
9
Filesystem flags: signed_directory_hash
10
Default mount options: user_xattr acl
11
Filesystem state: clean
12
Errors behavior: Continue
13
Filesystem OS type: Linux
14
Inode count: 655360
15
Block count: 2621184
16
Reserved block count: 131059
17
Free blocks: 2541521
18
Free inodes: 655349
19
First block: 0
20
Block size: 4096
21
Fragment size: 4096
22
Reserved GDT blocks: 639
23
Blocks per group: 32768
24
Fragments per group: 32768
25
Inodes per group: 8192
26
Inode blocks per group: 512
27
Flex block group size: 16
28
Filesystem created: Sat Dec 30 04:03:38 2017
29
Last mount time: Sat Dec 30 04:03:54 2017
30
Last write time: Sat Dec 30 04:05:42 2017
31
Mount count: 1
32
Maximum mount count: -1
33
Last checked: Sat Dec 30 04:03:38 2017
34
Check interval: 0 (<none>)
35
Lifetime writes: 291 MB
36
Reserved blocks uid: 0 (user root)
37
Reserved blocks gid: 0 (group root)
38
First inode: 11
39
Inode size: 256
40
Required extra isize: 28
41
Desired extra isize: 28
42
Journal inode: 8
43
Default directory hash: half_md4
44
Directory Hash Seed: 54a34eb1-0de8-40af-8e37-e4817b1f3046
45
Journal backup: inode blocks
46
Journal features: (none)
47
Journal size: 128M
48
Journal length: 32768
49
Journal sequence: 0x00000004
50
Journal start: 0
51
52
53
Group 0: (Blocks 0-32767) [ITABLE_ZEROED]
54
Checksum 0xe944, unused inodes 8181
55
Primary superblock at 0, Group descriptors at 1-1
56
Reserved GDT blocks at 2-640
57
Block bitmap at 641 (+641), Inode bitmap at 657 (+657)
58
Inode table at 673-1184 (+673)
59
23897 free blocks, 8181 free inodes, 2 directories, 8181 unused inodes
60
Free blocks: 8871-32767
61
Free inodes: 12-8192
62
Group 1: (Blocks 32768-65535) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
63
Checksum 0xda21, unused inodes 8192
64
Backup superblock at 32768, Group descriptors at 32769-32769
65
Reserved GDT blocks at 32770-33408
66
Block bitmap at 642 (bg #0 + 642), Inode bitmap at 658 (bg #0 + 658)
67
Inode table at 1185-1696 (bg #0 + 1185)
68
32127 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
69
Free blocks: 33409-65535
70
Free inodes: 8193-16384
71
Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
72
Checksum 0x8c02, unused inodes 8192
73
Block bitmap at 643 (bg #0 + 643), Inode bitmap at 659 (bg #0 + 659)
74
Inode table at 1697-2208 (bg #0 + 1697)
75
32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
76
Free blocks: 65536-98303
77
Free inodes: 16385-24576
78
.
79
..
80
...
81
82
Group 78: (Blocks 2555904-2588671) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]
83
Checksum 0x2104, unused inodes 8192
84
Block bitmap at 2097166 (bg #64 + 14), Inode bitmap at 2097182 (bg #64 + 30)
85
Inode table at 2104352-2104863 (bg #64 + 7200)
86
32768 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
87
Free blocks: 2555904-2588671
88
Free inodes: 638977-647168
89
Group 79: (Blocks 2588672-2621183) [INODE_UNINIT, ITABLE_ZEROED]
90
Checksum 0x8657, unused inodes 8192
91
Block bitmap at 2097167 (bg #64 + 15), Inode bitmap at 2097183 (bg #64 + 31)
92
Inode table at 2104864-2105375 (bg #64 + 7712)
93
32512 free blocks, 8192 free inodes, 0 directories, 8192 unused inodes
94
Free blocks: 2588672-2621183
95
Free inodes: 647169-655360
Copied!
As superbloacks are so important Files System is designed to keep back of them by copying them on several places of hard disk.
1
[email protected]:~# dumpe2fs /dev/sdb1 | grep -i Superblock
2
dumpe2fs 1.42.13 (17-May-2015)
3
Primary superblock at 0, Group descriptors at 1-1
4
Backup superblock at 32768, Group descriptors at 32769-32769
5
Backup superblock at 98304, Group descriptors at 98305-98305
6
Backup superblock at 163840, Group descriptors at 163841-163841
7
Backup superblock at 229376, Group descriptors at 229377-229377
8
Backup superblock at 294912, Group descriptors at 294913-294913
9
Backup superblock at 819200, Group descriptors at 819201-819201
10
Backup superblock at 884736, Group descriptors at 884737-884737
11
Backup superblock at 1605632, Group descriptors at 1605633-1605633
Copied!
There is another way to observe location of super blocks backup:
1
[email protected]:~# mkfs.ext4 -n /dev/sdb1
2
mke2fs 1.42.13 (17-May-2015)
3
/dev/sdb1 contains a ext4 file system
4
last mounted on Sat Dec 30 04:03:54 2017
5
Proceed anyway? (y,n) y
6
Creating filesystem with 2621184 4k blocks and 655360 inodes
7
Filesystem UUID: 9979d6a3-985e-4435-b445-f399f3715e79
8
Superblock backups stored on blocks:
9
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Copied!
-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.
1
[email protected]:~# debugfs /dev/sdb1
2
debugfs 1.42.13 (17-May-2015)
3
debugfs: help
4
5
Available debugfs requests:
6
7
show_debugfs_params, params
8
Show debugfs parameters
9
open_filesys, open Open a filesystem
10
close_filesys, close Close the filesystem
11
freefrag, e2freefrag Report free space fragmentation
12
feature, features Set/print superblock features
13
dirty_filesys, dirty Mark the filesystem as dirty
14
init_filesys Initialize a filesystem (DESTROYS DATA)
15
show_super_stats, stats Show superblock statistics
16
ncheck Do inode->name translation
17
icheck Do block->inode translation
18
change_root_directory, chroot
19
Change root directory
20
change_working_directory, cd
21
Change working directory
22
list_directory, ls List directory
23
show_inode_info, stat Show inode information
24
dump_extents, extents, ex
25
Dump extents information
26
blocks Dump blocks used by an inode
27
filefrag Report fragmentation information for an inode
28
link, ln Create directory link
29
unlink Delete a directory link
30
mkdir Create a directory
31
rmdir Remove a directory
32
rm Remove a file (unlink and kill_file, if appropriate)
33
kill_file Deallocate an inode and its blocks
34
clri Clear an inode's contents
35
freei Clear an inode's in-use flag
36
seti Set an inode's in-use flag
37
testi Test an inode's in-use flag
38
freeb Clear a block's in-use flag
39
setb Set a block's in-use flag
40
testb Test a block's in-use flag
41
modify_inode, mi Modify an inode by structure
42
find_free_block, ffb Find free block(s)
43
find_free_inode, ffi Find free inode(s)
44
print_working_directory, pwd
45
Print current working directory
46
expand_dir, expand Expand directory
47
mknod Create a special file
48
list_deleted_inodes, lsdel
49
List deleted inodes
50
undelete, undel Undelete file
51
write Copy a file from your native filesystem
52
dump_inode, dump Dump an inode out to a file
53
cat Dump an inode out to stdout
54
lcd Change the current directory on your native filesystem
55
rdump Recursively dump a directory to the native filesystem
56
set_super_value, ssv Set superblock value
57
set_inode_field, sif Set inode field
58
set_block_group, set_bg Set block group descriptor field
59
logdump Dump the contents of the journal
60
htree_dump, htree Dump a hash-indexed directory
61
dx_hash, hash Calculate the directory hash of a filename
62
dirsearch Search a directory for a particular filename
63
bmap Calculate the logical->physical block mapping for an inode
64
punch, truncate Punch (or truncate) blocks from an inode by deallocating them
65
symlink Create a symbolic link
66
imap Calculate the location of an inode
67
dump_unused Dump unused blocks
68
set_current_time Set current time to use when setting filesystem fields
69
supported_features Print features supported by this version of e2fsprogs
70
dump_mmp Dump MMP information
71
set_mmp_value, smmp Set MMP value
72
extent_open, eo Open inode for extent manipulation
73
zap_block, zap Zap block: fill with 0, pattern, flip bits etc.
74
block_dump, bdump, bd Dump contents of a block
75
list_quota, lq List quota
76
get_quota, gq Get quota
77
inode_dump, idump, id Dump the inode structure in hex
78
help Display info on command or topic.
79
list_requests, lr, ? List available commands.
80
quit, q Leave the subsystem.
Copied!

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:
1
2
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3
sda 8:0 0 50G 0 disk
4
├─sda1 8:1 0 1G 0 part /boot
5
└─sda2 8:2 0 49G 0 part
6
├─centos-root 253:0 0 45.1G 0 lvm /
7
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
8
sdb 8:16 0 10G 0 disk
9
└─sdb1 8:17 0 10G 0 part
10
sr0 11:0 1 1024M 0 rom
11
[[email protected] ~]# mkfs.xfs /dev/sdb1
12
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks
13
= sectsz=512 attr=2, projid32bit=1
14
= crc=1 finobt=0, sparse=0
15
data = bsize=4096 blocks=2621184, imaxpct=25
16
= sunit=0 swidth=0 blks
17
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
18
log =internal log bsize=4096 blocks=2560, version=2
19
= sectsz=512 sunit=0 blks, lazy-count=1
20
realtime =none extsz=4096 blocks=0, rtextents=0
21
23
xfs_admin xfs_estimate xfsinvutil xfs_mkfile xfs_rtcp
24
xfs_bmap xfs_freeze xfs_io xfs_ncheck
25
xfs_copy xfs_fsr xfs_logprint xfs_quota
26
xfs_db xfs_growfs xfs_mdrestore xfs_repair
27
xfsdump xfs_info xfs_metadump xfsrestore
Copied!
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

1
[[email protected] ~]# mkdir /mnt/my10gxfs
2
[[email protected] ~]# mount /dev/sdb1 /mnt/my10gxfs/
3
[[email protected] ~]# xfs_info /mnt/my10gxfs/
4
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks
5
= sectsz=512 attr=2, projid32bit=1
6
= crc=1 finobt=0 spinodes=0
7
data = bsize=4096 blocks=2621184, imaxpct=25
8
= sunit=0 swidth=0 blks
9
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
10
log =internal bsize=4096 blocks=2560, version=2
11
= sectsz=512 sunit=0 blks, lazy-count=1
12
realtime =none extsz=4096 blocks=0, rtextents=0
Copied!

xfs_repair

1
[[email protected] ~]# umount /mnt/my10gxfs/
2
3
[[email protected] ~]# xfs_repair -n /dev/sdb1
4
Phase 1 - find and verify superblock...
5
Phase 2 - using internal log
6
- zero log...
7
- scan filesystem freespace and inode maps...
8
- found root inode chunk
9
Phase 3 - for each AG...
10
- scan (but don't clear) agi unlinked lists...
11
- process known inodes and perform inode discovery...
12
- agno = 0
13
- agno = 1
14
- agno = 2
15
- agno = 3
16
- process newly discovered inodes...
17
Phase 4 - check for duplicate blocks...
18
- setting up duplicate extent list...
19
- check for inodes claiming duplicate blocks...
20
- agno = 0
21
- agno = 2
22
- agno = 3
23
- agno = 1
24
No modify flag set, skipping phase 5
25
Phase 6 - check inode connectivity...
26
- traversing filesystem ...
27
- traversal finished ...
28
- moving disconnected inodes to lost+found ...
29
Phase 7 - verify link counts...
30
No modify flag set, skipping filesystem flush and exiting.
Copied!
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.
1
2
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
3
sda 8:0 0 50G 0 disk
4
├─sda1 8:1 0 1G 0 part /boot
5
└─sda2 8:2 0 49G 0 part
6
├─centos-root 253:0 0 45.1G 0 lvm /
7
└─centos-swap 253:1 0 3.9G 0 lvm [SWAP]
8
sdb 8:16 0 10G 0 disk
9
└─sdb1 8:17 0 10G 0 part
10
sr0 11:0 1 1024M 0 rom
11
[[email protected] ~]# mount -t xfs /dev/sdb1 /mnt/my10gxfs/
12
[[email protected] ~]# mkdir /mnt/mybackups
13
[[email protected] ~]# cd /mnt/mybackups/
14
15
[[email protected] mybackups]# xfsdump -f /mnt/mybackups/backup1jun18 /mnt/my10gxfs
16
xfsdump: using file dump (drive_simple) strategy
17
xfsdump: version 3.1.4 (dump format 3.0) - type ^C for status and control
18
19
============================= dump label dialog ==============================
20
21
please enter label for this dump session (timeout in 300 sec)
22
-> etcbackup
23
session label entered: "etcbackup"
24
25
--------------------------------- end dialog ---------------------------------
26
27
xfsdump: level 0 dump of server1:/mnt/my10gxfs
28
xfsdump: dump date: Mon Jan 1 02:03:26 2018
29
xfsdump: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97
30
xfsdump: session label: "etcbackup"
31
xfsdump: ino map phase 1: constructing initial dump list
32
xfsdump: ino map phase 2: skipping (no pruning necessary)
33
xfsdump: ino map phase 3: skipping (only one dump stream)
34
xfsdump: ino map construction complete
35
xfsdump: estimated dump size: 20800 bytes
36
xfsdump: /var/lib/xfsdump/inventory created
37
38
============================= media label dialog =============================
39
40
please enter label for media in drive 0 (timeout in 300 sec)
41
42
-> bak1jun18label
43
media label entered: "bak1jun18label"
44
45
--------------------------------- end dialog ---------------------------------
46
47
xfsdump: creating dump session media file 0 (media 0, file 0)
48
xfsdump: dumping ino map
49
xfsdump: dumping directories
50
xfsdump: dumping non-directory files
51
xfsdump: ending media file
52
xfsdump: media file size 21016 bytes
53
xfsdump: dump size (non-dir files) : 0 bytes
54
xfsdump: dump complete: 201 seconds elapsed
55
xfsdump: Dump Summary:
56
xfsdump: stream 0 /mnt/mybackups/backup1jun18 OK (success)
57
xfsdump: Dump Status: SUCCESS
Copied!
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:
1
[[email protected] mybackups]# ls
2
backup1jun18
3
[[email protected] mybackups]# cat backup1jun18
4
xFSdump0"v��ZI�>������zH,����I,��Ӿ����server1etcbackupQbak1jun18label�z]4��K7�?`%�\s�/mnt/my10gxfs/dev/sdb1xfs�n$��tG��P���ᳵ?�@@@#��[email protected]�ZI�ÎZI�Î��������
Copied!
and try to restore:
1
[[email protected] mnt]# xfsrestore -f /mnt/mybackups/backup1jun18 /mnt/restore/
2
xfsrestore: using file dump (drive_simple) strategy
3
xfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and control
4
xfsrestore: searching media for dump
5
xfsrestore: examining media file 0
6
xfsrestore: dump description:
7
xfsrestore: hostname: server1
8
xfsrestore: mount point: /mnt/my10gxfs
9
xfsrestore: volume: /dev/sdb1
10
xfsrestore: session time: Mon Jan 1 02:03:26 2018
11
xfsrestore: level: 0
12
xfsrestore: session label: "etcbackup"
13
xfsrestore: media label: "bak1jun18label"
14
xfsrestore: file system id: 966e24bf-dc74-47ba-a250-80fe84e1b3b5
15
xfsrestore: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97
16
xfsrestore: media id: e87a5d34-a49b-4b37-a33f-6025ab5c73eb
17
xfsrestore: using online session inventory
18
xfsrestore: searching media for directory dump
19
xfsrestore: reading directories
20
xfsrestore: 1 directories and 0 entries processed
21
xfsrestore: directory post-processing
22
xfsrestore: restore complete: 0 seconds elapsed
23
xfsrestore: Restore Summary:
24
xfsrestore: stream 0 /mnt/mybackups/backup1jun18 OK (success)
25
xfsrestore: Restore Status: SUCCESS
26
27
[[email protected] mnt]# cd my10gxfs/
28
[[email protected] my10gxfs]# ls
Copied!
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:
1
[[email protected] my10gxfs]# xfsrestore -I
2
file system 0:
3
fs id: 966e24bf-dc74-47ba-a250-80fe84e1b3b5
4
session 0:
5
mount point: server1:/mnt/my10gxfs
6
device: server1:/dev/sdb1
7
time: Mon Jan 1 02:03:26 2018
8
session label: "etcbackup"
9
session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97
10
level: 0
11
resumed: NO
12
subtree: NO
13
streams: 1
14
stream 0:
15
pathname: /mnt/mybackups/backup1jun18
16
start: ino 0 offset 0
17
end: ino 1 offset 0
18
interrupted: NO
19
media files: 1
20
media file 0:
21
mfile index: 0
22
mfile type: data
23
mfile size: 21016
24
mfile start: ino 0 offset 0
25
mfile end: ino 1 offset 0
26
media label: "bak1jun18label"
27
media id: e87a5d34-a49b-4b37-a33f-6025ab5c73eb
28
xfsrestore: Restore Status: SUCCESS
Copied!

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.
1
[email protected]:~# apt install smartmontools
Copied!
and to check weather our hard disk supports SMART and its enabled:
1
[email protected]:~# smartctl -i /dev/sda
2
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
3
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
4
5
=== START OF INFORMATION SECTION ===
6
Model Family: Samsung based SSDs
7
Device Model: Samsung SSD 850 EVO 500GB
8
Serial Number: S2R9NX0H503451W
9
LU WWN Device Id: 5 002538 d40e515dc
10
Firmware Version: EMT02B6Q
11
User Capacity: 500,107,862,016 bytes [500 GB]
12
Sector Size: 512 bytes logical/physical
13
Rotation Rate: Solid State Device
14
Form Factor: 2.5 inches
15
Device is: In smartctl database [for details use: -P show]
16
ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c
17
SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
18
Local Time is: Mon Jan 1 13:37:38 2018 +0330
19
SMART support is: Available - device has SMART capability.
20
SMART support is: Enabled
Copied!
to do the <short|long|...> test on hard disk :
1
[email protected]:~# smartctl -t
2
afterselect,off long scttempint, select,redo
3
afterselect,on offline select, short
4
conveyance pending, select,next vendor,
5
6
[email protected]:~# smartctl -t short /dev/sda
7
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
8
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
9
10
=== START OF OFFLINE IMMEDIATE AND SELF-TEST SECTION ===
11
Sending command: "Execute SMART Short self-test routine immediately in off-line mode".
12
Drive command "Execute SMART Short self-test routine immediately in off-line mode" successful.
13
Testing has begun.
14
Please wait 2 minutes for test to complete.
15
Test will complete after Mon Jan 1 13:45:37 2018
16
17
Use smartctl -X to abort test.
Copied!
and for watching results:
1
[email protected]:~# smartctl -a /dev/sda
2
smartctl 6.5 2016-01-24 r4214 [x86_64-linux-4.10.0-40-generic] (local build)
3
Copyright (C) 2002-16, Bruce Allen, Christian Franke, www.smartmontools.org
4
5
=== START OF INFORMATION SECTION ===
6
Model Family: Samsung based SSDs
7
Device Model: Samsung SSD 850 EVO 500GB
8
Serial Number: S2R9NX0H503451W
9
LU WWN Device Id: 5 002538 d40e515dc
10
Firmware Version: EMT02B6Q
11
User Capacity: 500,107,862,016 bytes [500 GB]
12
Sector Size: 512 bytes logical/physical
13
Rotation Rate: Solid State Device
14
Form Factor: 2.5 inches
15
Device is: In smartctl database [for details use: -P show]
16
ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4c
17
SATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)
18
Local Time is: Mon Jan 1 14:02:06 2018 +0330
19
SMART support is: Available - device has SMART capability.
20
SMART support is: Enabled
21
22
=== START OF READ SMART DATA SECTION ===
23
SMART overall-health self-assessment test result: PASSED
24
25
General SMART Values:
26
Offline data collection status: (0x00) Offline data collection activity
27
was never started.
28
Auto Offline Data Collection: Disabled.
29
Self-test execution status: ( 0) The previous self-test routine completed
30
without error or no self-test has ever
31
been run.
32
Total time to complete Offline
33
data collection: ( 0) seconds.
34
Offline data collection
35
capabilities: (0x53) SMART execute Offline immediate.
36
Auto Offline data collection on/off support.
37
Suspend Offline collection upon new
38
command.
39
No Offline surface scan supported.
40
Self-test supported.
41
No Conveyance Self-test supported.
42
Selective Self-test supported.
43
SMART capabilities: (0x0003) Saves SMART data before entering
44
power-saving mode.
45
Supports SMART auto save timer.
46
Error logging capability: (0x01) Error logging supported.
47
General Purpose Logging supported.
48
Short self-test routine
49
recommended polling time: ( 2) minutes.
50
Extended self-test routine
51
recommended polling time: ( 265) minutes.
52
SCT capabilities: (0x003d) SCT Status supported.
53
SCT Error Recovery Control supported.
54
SCT Feature Control supported.
55
SCT Data Table supported.
56
57
SMART Attributes Data Structure revision number: 1
58
Vendor Specific SMART Attributes with Thresholds:
59
ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE
60
5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 0
61
9 Power_On_Hours 0x0032 099 099 000 Old_age Always - 1136
62
12 Power_Cycle_Count 0x0032 098 098 000 Old_age Always - 1292
63
177 Wear_Leveling_Count 0x0013 099 099 000 Pre-fail Always - 6
64
179 Used_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 0
65
181 Program_Fail_Cnt_Total 0x0032 100 100 010 Old_age Always - 0
66
182 Erase_Fail_Count_Total 0x0032 100 100 010 Old_age Always - 0
67
183 Runtime_Bad_Block 0x0013 100 100 010 Pre-fail Always - 0
68
187 Uncorrectable_Error_Cnt 0x0032 100 100 000 Old_age Always - 0
69
190 Airflow_Temperature_Cel 0x0032 068 052 000 Old_age Always - 32
70
195 ECC_Error_Rate 0x001a 200 200 000 Old_age Always - 0
71
199 CRC_Error_Count 0x003e 100 100 000 Old_age Always - 0
72
235 POR_Recovery_Count 0x0012 099 099 000 Old_age Always - 72
73
241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 7397082470
74
75
SMART Error Log Version: 1
76
No Errors Logged
77
78
SMART Self-test log structure revision number 1
79
Num Test_Description Status Remaining LifeTime(hours) LBA_of_first_error
80
# 1 Short offline Completed without error 00% 1135 -
81
# 2 Short offline Completed without error 00% 1 -
82
83
SMART Selective self-test log data structure revision number 1
84
SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS
85
1 0 0 Not_testing
86
2 0 0 Not_testing
87
3 0 0 Not_testing
88
4 0 0 Not_testing
89
5 0 0 Not_testing
90
255 0 65535 Read_scanning was never started
91
Selective self-test flags (0x0):
92
After scanning selected spans, do NOT read-scan remainder of disk.
93
If Selective self-test is pending on power-up, resume after 0 minute delay.
Copied!
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 :
1
# Defaults for smartmontools initscript (/etc/init.d/smartmontools)
2
# This is a POSIX shell fragment
3
4
# List of devices you want to explicitly enable S.M.A.R.T. for
5
# Not needed (and not recommended) if the device is monitored by smartd
6
#enable_smart="/dev/hda /dev/hdb"
7
8
# uncomment to start smartd on system startup
9
start_smartd=yes
10
11
# uncomment to pass additional options to smartd on startup
12
#smartd_opts="--interval=1800"
Copied!
and make sure smartd is running and enabled:
1
[email protected]:~# systemctl list-unit-files --type=service | grep -i smart
2
smartd.service enabled
3
smartmontools.service enabled
4
[email protected]:~# systemctl status smartd
5
● smartd.service - Self Monitoring and Reporting Technology (SMART) Daemon
6
Loaded: loaded (/lib/systemd/system/smartd.service; enabled; vendor preset: enabled)
7
Active: active (running) since Mon 2018-01-01 13:35:51 +0330; 43min ago
8
Docs: man:smartd(8)
9
man:smartd.conf(5)
10
Main PID: 4507 (smartd)
11
CGroup: /system.slice/smartd.service
12
└─4507 /usr/sbin/smartd -n
13
14
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda, type changed from 'scsi' to 'sat'
15
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], opened
16
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
17
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], found in smartd database: Samsung based SSDs
18
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Current_Pending_Sector count - no Attribute 197
19
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198
20
Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], is SMART capable. Adding to "monitor" list.
21
Jan 01 13:35:51 server1 smartd[4507]: Monitoring 1 ATA and 0 SCSI devices
22
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
23
Jan 01 13:35:51 server1 systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.
Copied!
Last modified 2yr ago