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
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 (Make a file System) command is used to create a File System on a device.To review LPIC1:
[email protected]:~# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsdb 8:16 0 10G 0 disk└─sdb1 8:17 0 10G 0 partsr0 11:0 1 1024M 0 romsda 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 /[email protected]:~# which mkfs/sbin/mkfs
We saw that mkfs is a front end for other commands:
[email protected]:~# ls /sbin | grep mkfsmkfsmkfs.bfsmkfs.cramfsmkfs.ext2mkfs.ext3mkfs.ext4mkfs.ext4devmkfs.fatmkfs.minixmkfs.msdosmkfs.ntfsmkfs.vfat
We can use mkfs.ext4 /dev/sdb1 to format a partition or in another format:
[email protected]:~# mkfs -t ext4 /dev/sdb1mke2fs 1.42.13 (17-May-2015)Creating filesystem with 2621184 4k blocks and 655360 inodesFilesystem UUID: 3f940f9b-d46d-423e-9f20-4cf74564e7acSuperblock backups stored on blocks:32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: doneWriting inode tables: doneCreating journal (32768 blocks): doneWriting superblocks and filesystem accounting information: done
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
Each file system has it own tools to maintain the problems.
fsck ( File System consistency check) is a tool for checking and repairing linux file system. Like mkfs, fsck is a front of other commands.
[email protected]:~# which fsck/sbin/fsck[email protected]:~# ls /sbin | grep fsckdosfscke2fsckfsckfsck.cramfsfsck.ext2fsck.ext3fsck.ext4fsck.ext4devfsck.fatfsck.minixfsck.msdosfsck.nfsfsck.vfatfsck.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.
[email protected]:~# mount /dev/sdb1 /mnt/my10gdisk/[email protected]:~# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsdb 8:16 0 10G 0 disk└─sdb1 8:17 0 10G 0 part /mnt/my10gdisksr0 11:0 1 1024M 0 romsda 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 /[email protected]:~# fsck /dev/sdb1fsck from util-linux 2.27.1e2fsck 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!!!
[email protected]:~# umount /mnt/my10gdisk[email protected]:~# fsck /dev/sdb1fsck from util-linux 2.27.1e2fsck 1.42.13 (17-May-2015)/dev/sdb1: clean, 11/655360 files, 79663/2621184 blocks
Based on health of ext Partition, different exit codes might be generated by fsck:
0-No errors1-Filesystem errors corrected2-System should be rebooted4-Filesystem errors left uncorrected8-Operational error16-Usage or syntax error32-Checking canceled by user request128-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 Change different aspects of file system
[email protected]:~# tune2fs --helptune2fs 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
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 installationUUID=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:
[email protected]:~# tune2fs -l /dev/sdb1tune2fs 1.42.13 (17-May-2015)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: 395e0905-bcc7-4b8d-b3ca-3193c266b749Filesystem magic number: 0xEF53Filesystem 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_isizeFilesystem flags: signed_directory_hashDefault mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 655360Block count: 2621184Reserved block count: 131059Free blocks: 2541521Free inodes: 655349First block: 0Block size: 4096Fragment size: 4096Reserved GDT blocks: 639Blocks per group: 32768Fragments per group: 32768Inodes per group: 8192Inode blocks per group: 512Flex block group size: 16Filesystem created: Sat Dec 30 04:03:38 2017Last mount time: Sat Dec 30 04:03:54 2017Last write time: Sat Dec 30 04:44:35 2017Mount count: 0Maximum mount count: -1Last checked: Sat Dec 30 04:44:35 2017Check interval: 0 (<none>)Lifetime writes: 291 MBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 28Desired extra isize: 28Journal inode: 8Default directory hash: half_md4Directory Hash Seed: 54a34eb1-0de8-40af-8e37-e4817b1f3046Journal 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 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.
[email protected]:~# dumpe2fs /dev/sdb1dumpe2fs 1.42.13 (17-May-2015)Filesystem volume name: <none>Last mounted on: <not available>Filesystem UUID: 395e0905-bcc7-4b8d-b3ca-3193c266b749Filesystem magic number: 0xEF53Filesystem 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_isizeFilesystem flags: signed_directory_hashDefault mount options: user_xattr aclFilesystem state: cleanErrors behavior: ContinueFilesystem OS type: LinuxInode count: 655360Block count: 2621184Reserved block count: 131059Free blocks: 2541521Free inodes: 655349First block: 0Block size: 4096Fragment size: 4096Reserved GDT blocks: 639Blocks per group: 32768Fragments per group: 32768Inodes per group: 8192Inode blocks per group: 512Flex block group size: 16Filesystem created: Sat Dec 30 04:03:38 2017Last mount time: Sat Dec 30 04:03:54 2017Last write time: Sat Dec 30 04:05:42 2017Mount count: 1Maximum mount count: -1Last checked: Sat Dec 30 04:03:38 2017Check interval: 0 (<none>)Lifetime writes: 291 MBReserved blocks uid: 0 (user root)Reserved blocks gid: 0 (group root)First inode: 11Inode size: 256Required extra isize: 28Desired extra isize: 28Journal inode: 8Default directory hash: half_md4Directory Hash Seed: 54a34eb1-0de8-40af-8e37-e4817b1f3046Journal backup: inode blocksJournal features: (none)Journal size: 128MJournal length: 32768Journal sequence: 0x00000004Journal start: 0Group 0: (Blocks 0-32767) [ITABLE_ZEROED]Checksum 0xe944, unused inodes 8181Primary superblock at 0, Group descriptors at 1-1Reserved GDT blocks at 2-640Block 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 inodesFree blocks: 8871-32767Free inodes: 12-8192Group 1: (Blocks 32768-65535) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Checksum 0xda21, unused inodes 8192Backup superblock at 32768, Group descriptors at 32769-32769Reserved GDT blocks at 32770-33408Block 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 inodesFree blocks: 33409-65535Free inodes: 8193-16384Group 2: (Blocks 65536-98303) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Checksum 0x8c02, unused inodes 8192Block 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 inodesFree blocks: 65536-98303Free inodes: 16385-24576......Group 78: (Blocks 2555904-2588671) [INODE_UNINIT, BLOCK_UNINIT, ITABLE_ZEROED]Checksum 0x2104, unused inodes 8192Block 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 inodesFree blocks: 2555904-2588671Free inodes: 638977-647168Group 79: (Blocks 2588672-2621183) [INODE_UNINIT, ITABLE_ZEROED]Checksum 0x8657, unused inodes 8192Block 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 inodesFree blocks: 2588672-2621183Free 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.
[email protected]:~# dumpe2fs /dev/sdb1 | grep -i Superblockdumpe2fs 1.42.13 (17-May-2015)Primary superblock at 0, Group descriptors at 1-1Backup superblock at 32768, Group descriptors at 32769-32769Backup superblock at 98304, Group descriptors at 98305-98305Backup superblock at 163840, Group descriptors at 163841-163841Backup superblock at 229376, Group descriptors at 229377-229377Backup superblock at 294912, Group descriptors at 294913-294913Backup superblock at 819200, Group descriptors at 819201-819201Backup superblock at 884736, Group descriptors at 884737-884737Backup superblock at 1605632, Group descriptors at 1605633-1605633
There is another way to observe location of super blocks backup:
r[email protected]:~# mkfs.ext4 -n /dev/sdb1mke2fs 1.42.13 (17-May-2015)/dev/sdb1 contains a ext4 file systemlast mounted on Sat Dec 30 04:03:54 2017Proceed anyway? (y,n) yCreating filesystem with 2621184 4k blocks and 655360 inodesFilesystem UUID: 9979d6a3-985e-4435-b445-f399f3715e79Superblock 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 interactive file system editor.Its better to unmount the partition first.
[email protected]:~# debugfs /dev/sdb1debugfs 1.42.13 (17-May-2015)debugfs: helpAvailable debugfs requests:show_debugfs_params, paramsShow debugfs parametersopen_filesys, open Open a filesystemclose_filesys, close Close the filesystemfreefrag, e2freefrag Report free space fragmentationfeature, features Set/print superblock featuresdirty_filesys, dirty Mark the filesystem as dirtyinit_filesys Initialize a filesystem (DESTROYS DATA)show_super_stats, stats Show superblock statisticsncheck Do inode->name translationicheck Do block->inode translationchange_root_directory, chrootChange root directorychange_working_directory, cdChange working directorylist_directory, ls List directoryshow_inode_info, stat Show inode informationdump_extents, extents, exDump extents informationblocks Dump blocks used by an inodefilefrag Report fragmentation information for an inodelink, ln Create directory linkunlink Delete a directory linkmkdir Create a directoryrmdir Remove a directoryrm Remove a file (unlink and kill_file, if appropriate)kill_file Deallocate an inode and its blocksclri Clear an inode's contentsfreei Clear an inode's in-use flagseti Set an inode's in-use flagtesti Test an inode's in-use flagfreeb Clear a block's in-use flagsetb Set a block's in-use flagtestb Test a block's in-use flagmodify_inode, mi Modify an inode by structurefind_free_block, ffb Find free block(s)find_free_inode, ffi Find free inode(s)print_working_directory, pwdPrint current working directoryexpand_dir, expand Expand directorymknod Create a special filelist_deleted_inodes, lsdelList deleted inodesundelete, undel Undelete filewrite Copy a file from your native filesystemdump_inode, dump Dump an inode out to a filecat Dump an inode out to stdoutlcd Change the current directory on your native filesystemrdump Recursively dump a directory to the native filesystemset_super_value, ssv Set superblock valueset_inode_field, sif Set inode fieldset_block_group, set_bg Set block group descriptor fieldlogdump Dump the contents of the journalhtree_dump, htree Dump a hash-indexed directorydx_hash, hash Calculate the directory hash of a filenamedirsearch Search a directory for a particular filenamebmap Calculate the logical->physical block mapping for an inodepunch, truncate Punch (or truncate) blocks from an inode by deallocating themsymlink Create a symbolic linkimap Calculate the location of an inodedump_unused Dump unused blocksset_current_time Set current time to use when setting filesystem fieldssupported_features Print features supported by this version of e2fsprogsdump_mmp Dump MMP informationset_mmp_value, smmp Set MMP valueextent_open, eo Open inode for extent manipulationzap_block, zap Zap block: fill with 0, pattern, flip bits etc.block_dump, bdump, bd Dump contents of a blocklist_quota, lq List quotaget_quota, gq Get quotainode_dump, idump, id Dump the inode structure in hexhelp Display info on command or topic.list_requests, lr, ? List available commands.quit, q Leave the subsystem.
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:
[[email protected] ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 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 partsr0 11:0 1 1024M 0 rom[[email protected] ~]# mkfs.xfs /dev/sdb1meta-data=/dev/sdb1 isize=512 agcount=4, agsize=655296 blks= sectsz=512 attr=2, projid32bit=1= crc=1 finobt=0, sparse=0data = bsize=4096 blocks=2621184, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal log bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0[[email protected] ~]# xfsxfs_admin xfs_estimate xfsinvutil xfs_mkfile xfs_rtcpxfs_bmap xfs_freeze xfs_io xfs_ncheckxfs_copy xfs_fsr xfs_logprint xfs_quotaxfs_db xfs_growfs xfs_mdrestore xfs_repairxfsdump 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 |
[[email protected] ~]# mkdir /mnt/my10gxfs[[email protected] ~]# mount /dev/sdb1 /mnt/my10gxfs/[[email protected] ~]# 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=0data = bsize=4096 blocks=2621184, imaxpct=25= sunit=0 swidth=0 blksnaming =version 2 bsize=4096 ascii-ci=0 ftype=1log =internal bsize=4096 blocks=2560, version=2= sectsz=512 sunit=0 blks, lazy-count=1realtime =none extsz=4096 blocks=0, rtextents=0
[[email protected] ~]# umount /mnt/my10gxfs/[[email protected] ~]# xfs_repair -n /dev/sdb1Phase 1 - find and verify superblock...Phase 2 - using internal log- zero log...- scan filesystem freespace and inode maps...- found root inode chunkPhase 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 = 1No modify flag set, skipping phase 5Phase 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.
There are two old xfs commands for backing up and restoring. They history back to days when tape media were only backup media.
[[email protected] ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 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 partsr0 11:0 1 1024M 0 rom[[email protected] ~]# mount -t xfs /dev/sdb1 /mnt/my10gxfs/[[email protected] ~]# mkdir /mnt/mybackups[[email protected] ~]# cd /mnt/mybackups/[[email protected] mybackups]# xfsdump -f /mnt/mybackups/backup1jun18 /mnt/my10gxfsxfsdump: using file dump (drive_simple) strategyxfsdump: 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)-> etcbackupsession label entered: "etcbackup"--------------------------------- end dialog ---------------------------------xfsdump: level 0 dump of server1:/mnt/my10gxfsxfsdump: dump date: Mon Jan 1 02:03:26 2018xfsdump: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97xfsdump: session label: "etcbackup"xfsdump: ino map phase 1: constructing initial dump listxfsdump: ino map phase 2: skipping (no pruning necessary)xfsdump: ino map phase 3: skipping (only one dump stream)xfsdump: ino map construction completexfsdump: estimated dump size: 20800 bytesxfsdump: /var/lib/xfsdump/inventory created============================= media label dialog =============================please enter label for media in drive 0 (timeout in 300 sec)-> bak1jun18labelmedia label entered: "bak1jun18label"--------------------------------- end dialog ---------------------------------xfsdump: creating dump session media file 0 (media 0, file 0)xfsdump: dumping ino mapxfsdump: dumping directoriesxfsdump: dumping non-directory filesxfsdump: ending media filexfsdump: media file size 21016 bytesxfsdump: dump size (non-dir files) : 0 bytesxfsdump: dump complete: 201 seconds elapsedxfsdump: 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:
[[email protected] mybackups]# lsbackup1jun18[[email protected] mybackups]# cat backup1jun18xFSdump0"v��ZI�>������zH,����I,��Ӿ����server1etcbackupQbak1jun18label�z]4��K7�?`%�\s�/mnt/my10gxfs/dev/sdb1xfs�n$��tG��P���ᳵ?�@@@#��[email protected]�ZI�ÎZI�Î��������
and try to restore:
[[email protected] mnt]# xfsrestore -f /mnt/mybackups/backup1jun18 /mnt/restore/xfsrestore: using file dump (drive_simple) strategyxfsrestore: version 3.1.4 (dump format 3.0) - type ^C for status and controlxfsrestore: searching media for dumpxfsrestore: examining media file 0xfsrestore: dump description:xfsrestore: hostname: server1xfsrestore: mount point: /mnt/my10gxfsxfsrestore: volume: /dev/sdb1xfsrestore: session time: Mon Jan 1 02:03:26 2018xfsrestore: level: 0xfsrestore: session label: "etcbackup"xfsrestore: media label: "bak1jun18label"xfsrestore: file system id: 966e24bf-dc74-47ba-a250-80fe84e1b3b5xfsrestore: session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97xfsrestore: media id: e87a5d34-a49b-4b37-a33f-6025ab5c73ebxfsrestore: using online session inventoryxfsrestore: searching media for directory dumpxfsrestore: reading directoriesxfsrestore: 1 directories and 0 entries processedxfsrestore: directory post-processingxfsrestore: restore complete: 0 seconds elapsedxfsrestore: Restore Summary:xfsrestore: stream 0 /mnt/mybackups/backup1jun18 OK (success)xfsrestore: Restore Status: SUCCESS[[email protected] mnt]# cd my10gxfs/[[email protected] 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:
[[email protected] my10gxfs]# xfsrestore -Ifile system 0:fs id: 966e24bf-dc74-47ba-a250-80fe84e1b3b5session 0:mount point: server1:/mnt/my10gxfsdevice: server1:/dev/sdb1time: Mon Jan 1 02:03:26 2018session label: "etcbackup"session id: 482cd1f2-eed5-492c-bf8b-d3befb97be97level: 0resumed: NOsubtree: NOstreams: 1stream 0:pathname: /mnt/mybackups/backup1jun18start: ino 0 offset 0end: ino 1 offset 0interrupted: NOmedia files: 1media file 0:mfile index: 0mfile type: datamfile size: 21016mfile start: ino 0 offset 0mfile end: ino 1 offset 0media label: "bak1jun18label"media id: e87a5d34-a49b-4b37-a33f-6025ab5c73ebxfsrestore: Restore Status: SUCCESS
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.
[email protected]:~# apt install smartmontools
and to check weather our hard disk supports SMART and its enabled:
[email protected]:~# smartctl -i /dev/sdasmartctl 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 SSDsDevice Model: Samsung SSD 850 EVO 500GBSerial Number: S2R9NX0H503451WLU WWN Device Id: 5 002538 d40e515dcFirmware Version: EMT02B6QUser Capacity: 500,107,862,016 bytes [500 GB]Sector Size: 512 bytes logical/physicalRotation Rate: Solid State DeviceForm Factor: 2.5 inchesDevice is: In smartctl database [for details use: -P show]ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4cSATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)Local Time is: Mon Jan 1 13:37:38 2018 +0330SMART support is: Available - device has SMART capability.SMART support is: Enabled
to do the <short|long|...> test on hard disk :
[email protected]:~# smartctl -tafterselect,off long scttempint, select,redoafterselect,on offline select, shortconveyance pending, select,next vendor,[email protected]:~# smartctl -t short /dev/sdasmartctl 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 2018Use smartctl -X to abort test.
and for watching results:
[email protected]:~# smartctl -a /dev/sdasmartctl 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 SSDsDevice Model: Samsung SSD 850 EVO 500GBSerial Number: S2R9NX0H503451WLU WWN Device Id: 5 002538 d40e515dcFirmware Version: EMT02B6QUser Capacity: 500,107,862,016 bytes [500 GB]Sector Size: 512 bytes logical/physicalRotation Rate: Solid State DeviceForm Factor: 2.5 inchesDevice is: In smartctl database [for details use: -P show]ATA Version is: ACS-2, ATA8-ACS T13/1699-D revision 4cSATA Version is: SATA 3.1, 6.0 Gb/s (current: 6.0 Gb/s)Local Time is: Mon Jan 1 14:02:06 2018 +0330SMART support is: Available - device has SMART capability.SMART support is: Enabled=== START OF READ SMART DATA SECTION ===SMART overall-health self-assessment test result: PASSEDGeneral SMART Values:Offline data collection status: (0x00) Offline data collection activitywas never started.Auto Offline Data Collection: Disabled.Self-test execution status: ( 0) The previous self-test routine completedwithout error or no self-test has everbeen run.Total time to complete Offlinedata collection: ( 0) seconds.Offline data collectioncapabilities: (0x53) SMART execute Offline immediate.Auto Offline data collection on/off support.Suspend Offline collection upon newcommand.No Offline surface scan supported.Self-test supported.No Conveyance Self-test supported.Selective Self-test supported.SMART capabilities: (0x0003) Saves SMART data before enteringpower-saving mode.Supports SMART auto save timer.Error logging capability: (0x01) Error logging supported.General Purpose Logging supported.Short self-test routinerecommended polling time: ( 2) minutes.Extended self-test routinerecommended 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: 1Vendor Specific SMART Attributes with Thresholds:ID# ATTRIBUTE_NAME FLAG VALUE WORST THRESH TYPE UPDATED WHEN_FAILED RAW_VALUE5 Reallocated_Sector_Ct 0x0033 100 100 010 Pre-fail Always - 09 Power_On_Hours 0x0032 099 099 000 Old_age Always - 113612 Power_Cycle_Count 0x0032 098 098 000 Old_age Always - 1292177 Wear_Leveling_Count 0x0013 099 099 000 Pre-fail Always - 6179 Used_Rsvd_Blk_Cnt_Tot 0x0013 100 100 010 Pre-fail Always - 0181 Program_Fail_Cnt_Total 0x0032 100 100 010 Old_age Always - 0182 Erase_Fail_Count_Total 0x0032 100 100 010 Old_age Always - 0183 Runtime_Bad_Block 0x0013 100 100 010 Pre-fail Always - 0187 Uncorrectable_Error_Cnt 0x0032 100 100 000 Old_age Always - 0190 Airflow_Temperature_Cel 0x0032 068 052 000 Old_age Always - 32195 ECC_Error_Rate 0x001a 200 200 000 Old_age Always - 0199 CRC_Error_Count 0x003e 100 100 000 Old_age Always - 0235 POR_Recovery_Count 0x0012 099 099 000 Old_age Always - 72241 Total_LBAs_Written 0x0032 099 099 000 Old_age Always - 7397082470SMART Error Log Version: 1No Errors LoggedSMART Self-test log structure revision number 1Num 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 1SPAN MIN_LBA MAX_LBA CURRENT_TEST_STATUS1 0 0 Not_testing2 0 0 Not_testing3 0 0 Not_testing4 0 0 Not_testing5 0 0 Not_testing255 0 65535 Read_scanning was never startedSelective 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 startupstart_smartd=yes# uncomment to pass additional options to smartd on startup#smartd_opts="--interval=1800"
and make sure smartd is running and enabled:
[email protected]:~# systemctl list-unit-files --type=service | grep -i smartsmartd.service enabledsmartmontools.service enabled[email protected]:~# systemctl status smartd● smartd.service - Self Monitoring and Reporting Technology (SMART) DaemonLoaded: loaded (/lib/systemd/system/smartd.service; enabled; vendor preset: enabled)Active: active (running) since Mon 2018-01-01 13:35:51 +0330; 43min agoDocs: man:smartd(8)man:smartd.conf(5)Main PID: 4507 (smartd)CGroup: /system.slice/smartd.service└─4507 /usr/sbin/smartd -nJan 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], openedJan 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, 5Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], found in smartd database: Samsung based SSDsJan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Current_Pending_Sector count - no Attribute 197Jan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], can't monitor Offline_Uncorrectable count - no Attribute 198Jan 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 devicesJan 01 13:35:51 server1 smartd[4507]: Device: /dev/sda [SAT], state written to /var/lib/smartmontools/smartd.Samsung_SSD_850_EVO_500GB-S2R9NX0H50345Jan 01 13:35:51 server1 systemd[1]: Started Self Monitoring and Reporting Technology (SMART) Daemon.