Announcement

Collapse
No announcement yet.

Btrfs scrub command

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Btrfs scrub command

    "btrfs scrub is used to scrub a btrfs filesystem, which will read all data and metadata blocks from all devices and verify checksums, and automatically repair corrupted blocks if there’s a correct copy available. (That assumes you are using RAID1 --GG)
    Note: Scrub is not a filesystem checker (fsck) and does not verify nor repair structural damage in the filesystem."

    Code:
    :~$ [B][FONT=courier new]sudo -i[/FONT][/B]
    
    :~# [B][FONT=courier new]mount /dev/disk/by-uuid/47a4794f-b168-4c61-9d0c-cc22f4880116 /mnt
      (Note:  I did not have to mount the <ROOT_FS> as a scrub target.  I could have pointed scrub to /  I mount <ROOT_FS> for all my btrfs work as a matter of habit. -GG)
    [/FONT][/B]
    :~# [COLOR=#ff0000][FONT=courier new][B]btrfs scrub start /mnt[/B][/FONT][/COLOR]
    scrub started on /mnt, fsid 47a4794f-b168-4c61-9d0c-cc22f4880116 (pid=28079)
    
    :~#[B] [FONT=courier new]btrfs scrub status /mnt[/FONT][/B]
    scrub status for 47a4794f-b168-4c61-9d0c-cc22f4880116
            scrub started at Sun Jul 15 20:16:45 2018, running for 00:00:20
            total bytes scrubbed: 1.31GiB with 0 errors
    ...
    
    :~# [FONT=courier new][B]btrfs scrub status /mnt[/B][/FONT]
    scrub status for 47a4794f-b168-4c61-9d0c-cc22f4880116
            scrub started at Sun Jul 15 20:16:45 2018, running for 00:10:15
            total bytes scrubbed: 70.60GiB with 0 errors
    :~#[FONT=courier new][B] btrfs scrub status /mnt[/B][/FONT]
    scrub status for 47a4794f-b168-4c61-9d0c-cc22f4880116
            scrub started at Sun Jul 15 20:16:45 2018 and [B]finished[/B] after 00:16:17
            total bytes scrubbed: [B]108.00GiB[/B] with 0 errors
    Scrub also tells me how many GB of data I have on my filesystem. The btrfs usage command gives the same results:
    Code:
    :~# btrfs fi usage /mnt
    Overall:
        Device size:                 698.64GiB
        Device allocated:            128.07GiB
        Device unallocated:          570.57GiB
        Device missing:                  0.00B
        [B]Used:                        108.00GiB[/B]
        Free (estimated):            587.97GiB      (min: 302.69GiB)
        Data ratio:                       1.00
        Metadata ratio:                   2.00
        Global reserve:              159.78MiB      (used: 0.00B)
    
    Data,single: Size:124.01GiB, Used:106.60GiB
       /dev/sda1     124.01GiB
    
    Metadata,DUP: Size:2.00GiB, Used:719.48MiB
       /dev/sda1       4.00GiB
    
    System,DUP: Size:32.00MiB, Used:16.00KiB
       /dev/sda1      64.00MiB
    
    Unallocated:
       /dev/sda1     570.57GiB
    Here is the man page for btrfs-scrub:
    Code:
    BTRFS-SCRUB(8)                                        Btrfs Manual                                       BTRFS-SCRUB(8)
    
    NAME
           btrfs-scrub - scrub btrfs filesystem
    
    SYNOPSIS
           btrfs scrub <subcommand> <args>
    
    DESCRIPTION
           btrfs scrub is used to scrub a btrfs filesystem, [COLOR=#ff0000][B]which will read all data from all disks 
          and verify checksums.  [I](Note:  that's "read all the data".  Scrub will replace a bad
          file with a good copy IF you are using RAID1, but it will not fix structual damage.
          Aslo, the  defrag command WILL force snapshot population due to COW. - GG)[/I][/B][/COLOR]
    SUBCOMMAND
           cancel <path>|<device>
               If a scrub is running on the filesystem identified by <path>, cancel it.
    
               Progress is saved in the scrub progress file and scrubbing can be resumed later using the scrub resume
               command. If a <device> is given, the corresponding filesystem is found and scrub cancel behaves as if it
              was called on that filesystem.
    
           resume [-BdqrR] [-c <ioprio_class> -n <ioprio_classdata>] <path>|<device>
               Resume a canceled or interrupted scrub cycle on the filesystem identified by <path> or on a given <device>.
    
               Does not start a new scrub if the last scrub finished successfully.
    
               Options
    
               see scrub start.
    
           start [-BdqrRf] [-c <ioprio_class> -n <ioprio_classdata>] <path>|<device>
               Start a scrub on all devices of the filesystem identified by <path> or on a single <device>. If a scrub is
               already running, the new one fails.
    
               Without options, scrub is started as a background process. Progress can be obtained with the scrub status
               command. Scrubbing involves reading all data from all disks and verifying checksums. Errors are corrected
               along the way if possible.
    
               The default IO priority of scrub is the idle class. The priority can be configured similar to the ionice(1)
               syntax using -c and -n options.
    
               Options
    
               -B
                   Do not background and print scrub statistics when finished.
    
               -d
                   Print separate statistics for each device of the filesystem (-B only).
    
               -q
                   Quiet. Omit error messages and statistics.
    
               -r
                   Read only mode. Do not attempt to correct anything.
    
               -R
                   Raw print mode. Print full data instead of summary.
    
               -c <ioprio_class>
                   Set IO priority class (see ionice(1) manpage).
    
               -n <ioprio_classdata>
                   Set IO priority classdata (see ionice(1) manpage).
    
               -f
                   Force starting new scrub even if a scrub is already running. This is useful when scrub stat record file
                   is damaged.
    
           status [-d] <path>|<device>
               Show status of a running scrub for the filesystem identified by <path> or for the specified <device>.
    
               If no scrub is running, show statistics of the last finished or canceled scrub for that filesystem or
               device.
    
               Options
    
               -d
                   Print separate statistics for each device of the filesystem.
    
    EXIT STATUS
           btrfs scrub returns a zero exit status if it succeeds. Non zero is returned in case of failure.
    
    AVAILABILITY
           btrfs is part of btrfs-progs. Please refer to the btrfs wiki http://btrfs.wiki.kernel.org for further details.
    
    SEE ALSO
           mkfs.btrfs(8),
    
    Btrfs [B][COLOR=#ff0000]v4.4 [/COLOR][/B]                                           [COLOR=#ff0000][B] 06/15/2017  [/B][/COLOR]                                      BTRFS-SCRUB(8)
    EDIT:
    I forgot to add that if your btrfs root_fs fails to mount you can still run scrub on the device it is on by using:
    sudo btrfs scrub start /dev/sda1
    Last edited by GreyGeek; Jul 16, 2018, 02:05 PM.
    "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
    – John F. Kennedy, February 26, 1962.
Working...
X