# I need help to interpret smartctl result

## apiaio

In the morning I had booted into win7 installed on sda1. After that I rebooted into gentoo on sda2. Since this time sda is completely broken. I can see partitions

```
fdisk -l /dev/sda

Disk /dev/sda: 447.13 GiB, 480103981056 bytes, 937703088 sectors

Disk model: INTEL SSDSC2KW48

Units: sectors of 1 * 512 = 512 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disklabel type: dos

Disk identifier: 0xf74451e6

Device     Boot     Start       End   Sectors   Size Id Type

/dev/sda1            2048 251660287 251658240   120G  7 HPFS/NTFS/exFAT

/dev/sda2       251660288 440403967 188743680    90G 83 Linux

/dev/sda3  *    440403968 629147647 188743680    90G 83 Linux

/dev/sda4       629149694 937703087 308553394 147.1G  5 Extended

/dev/sda5       629149696 817893375 188743680    90G 83 Linux

/dev/sda6       817895424 937703087 119807664  57.1G 83 Linux

```

but I cant mount any of them. So that I ran smartctl long test. Here is the result

```
smartctl -l selftest /dev/sda

smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.4.80-gentoo] (local build)

Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF READ SMART DATA SECTION ===

SMART Self-test log structure revision number 1

Num  Test_Description    Status                  Remaining  LifeTime(hours)  LBA_of_first_error

# 1  Extended offline    Completed without error       00%       416         -

# 2  Extended offline    Completed without error       00%       415         -

# 3  Extended offline    Completed without error       00%         4         -

```

I do not know what is wrong. Any help appreciated

----------

## Cazzantonio

can you post the output of 

```
smartctl -a /dev/sda 
```

Other things:

Are you using EFI or legay bios boot?

I suppose the latter since you have a dos partition instead of a gpt one

Did you try to reinstall grub? The long process of chrooting into gentoo and running grub-install

----------

## apiaio

```
smartctl -a /dev/sda

smartctl 7.2 2020-12-30 r5155 [x86_64-linux-5.4.80-gentoo] (local build)

Copyright (C) 2002-20, Bruce Allen, Christian Franke, www.smartmontools.org

=== START OF INFORMATION SECTION ===

Model Family:     Intel 540 Series SSDs

Device Model:     INTEL SSDSC2KW480H6

Serial Number:    BTLT646205UR480EGN

LU WWN Device Id: 5 5cd2e4 14d877fbb

Firmware Version: LSF036C

User Capacity:    480,103,981,056 bytes [480 GB]

Sector Size:      512 bytes logical/physical

Rotation Rate:    Solid State Device

Form Factor:      2.5 inches

TRIM Command:     Available, deterministic

Device is:        In smartctl database [for details use: -P show]

ATA Version is:   ACS-3 (minor revision not indicated)

SATA Version is:  SATA 3.2, 6.0 Gb/s (current: 6.0 Gb/s)

Local Time is:    Sat Mar  5 16:08:00 2022 CET

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:  (0x01) Offline data collection activity

                                        is in a Reserved state.

                                        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:        (  30) minutes.

SCT capabilities:              (0x0039) SCT Status supported.

                                        SCT Error Recovery Control supported.

                                        SCT Feature Control supported.

                                        SCT Data Table supported.

SMART Attributes Data Structure revision number: 1025

Vendor Specific SMART Attributes with Thresholds:

ID# ATTRIBUTE_NAME          FLAG     VALUE WORST THRESH TYPE      UPDATED  WHEN_FAILED RAW_VALUE

  5 Reallocated_Sector_Ct   0x0032   100   100   000    Old_age   Always       -       1024

  9 Power_On_Hours_and_Msec 0x0032   100   100   000    Old_age   Always       -       417h+00m+00.000s

 12 Power_Cycle_Count       0x0032   100   100   000    Old_age   Always       -       5295

170 Available_Reservd_Space 0x0033   089   089   010    Pre-fail  Always       -       0

171 Program_Fail_Count      0x0032   100   100   010    Old_age   Always       -       0

172 Erase_Fail_Count        0x0032   100   100   010    Old_age   Always       -       0

174 Unexpect_Power_Loss_Ct  0x0032   100   100   000    Old_age   Always       -       45

183 SATA_Downshift_Count    0x0032   100   100   000    Old_age   Always       -       12

184 End-to-End_Error        0x0033   095   095   090    Pre-fail  Always       -       5

187 Uncorrectable_Error_Cnt 0x0032   100   100   000    Old_age   Always       -       2

190 Airflow_Temperature_Cel 0x0032   033   038   000    Old_age   Always       -       33 (Min/Max 22/38)

192 Power-Off_Retract_Count 0x0032   100   100   000    Old_age   Always       -       45

199 UDMA_CRC_Error_Count    0x0032   100   100   000    Old_age   Always       -       0

225 Host_Writes_32MiB       0x0032   100   100   000    Old_age   Always       -       220864

226 Workld_Media_Wear_Indic 0x0032   100   100   000    Old_age   Always       -       0

227 Workld_Host_Reads_Perc  0x0032   100   100   000    Old_age   Always       -       0

228 Workload_Minutes        0x0032   100   100   000    Old_age   Always       -       0

232 Available_Reservd_Space 0x0033   089   089   010    Pre-fail  Always       -       0

233 Media_Wearout_Indicator 0x0032   097   097   000    Old_age   Always       -       0

241 Total_LBAs_Written      0x0032   100   100   000    Old_age   Always       -       220864

242 Total_LBAs_Read         0x0032   100   100   000    Old_age   Always       -       561635

249 NAND_Writes_1GiB        0x0032   100   100   000    Old_age   Always       -       2911

252 Unknown_Attribute       0x0032   100   100   000    Old_age   Always       -       11

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  Extended offline    Completed without error       00%       416         -

# 2  Extended offline    Completed without error       00%       415         -

# 3  Extended offline    Completed without error       00%         4         -

SMART Selective self-test log data structure revision number 1

 SPAN         MIN_LBA         MAX_LBA  CURRENT_TEST_STATUS

    1  70403103932424  70403103932424  Not_testing

    2  70403103932424  70403103932424  Not_testing

    3  70403103932424  70403103932424  Not_testing

    4  70403103932424  70403103932424  Not_testing

    5  70403103932424  70403103932424  Not_testing

Selective self-test flags (0x4008):

  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.
```

I am using bios. I do not need to reinstall grub, because I boot from sdc3. MBR is on sda.

----------

## Hu

None of that output looks obviously wrong to me.  What made you think that SMART was the answer here?  What fails when you try to mount the filesystem?

----------

## NeddySeagoon

apiaio,

That SMART data looks good.

Tell us more about the can't mount. 

What command do you give?

What error do you get in response?

----------

## apiaio

```
# mount /dev/sda5 /mnt

mount: /mnt: can't read superblock on /dev/sda5.
```

----------

## Hu

What is the output of blkid ; file -s /dev/sda??  Does dmesg record anything useful when the mount fails?

----------

## apiaio

```
# blkid

/dev/sdb2: UUID="73057596-4607-4f9f-bf3f-90d52e7e13a4" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="5223f61f-02"

/dev/sdb7: BLOCK_SIZE="512" UUID="4B02A213613257C5" TYPE="ntfs" PARTUUID="5223f61f-07"

/dev/sdb5: UUID="c555e748-ae69-460c-a4a5-273021b62c0d" BLOCK_SIZE="4096" TYPE="xfs" PARTUUID="5223f61f-05"

/dev/sdb3: UUID="4154aff0-9889-48e3-809a-be5ec4e26067" TYPE="swap" PARTUUID="5223f61f-03"

/dev/sdb1: BLOCK_SIZE="512" UUID="184C465D4C4635B2" TYPE="ntfs" PARTUUID="5223f61f-01"

/dev/sdb8: BLOCK_SIZE="512" UUID="946847106846F092" TYPE="ntfs" PARTUUID="5223f61f-08"

/dev/sdb6: BLOCK_SIZE="512" UUID="2ED7EC5E06125BC0" TYPE="ntfs" PARTUUID="5223f61f-06"

/dev/sdc2: UUID="9c5e5d9c-b9c8-4899-b80b-72cca722ffda" BLOCK_SIZE="4096" TYPE="ext4" PTTYPE="dos" PARTUUID="0f74d1f0-02"

/dev/sdc7: UUID="84b50409-3535-4365-966b-1b3c87532ef3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0f74d1f0-07"

/dev/sdc5: UUID="0817d642-c979-4303-b186-4fc97dab54e5" BLOCK_SIZE="512" TYPE="xfs" PARTUUID="0f74d1f0-05"

/dev/sdc3: UUID="a38ed8be-cd74-4760-a921-72e05b4f9fe3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0f74d1f0-03"

/dev/sdc1: UUID="d93e13af-dfb4-4501-a9c8-d0652f126dad" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0f74d1f0-01"

/dev/sdc8: BLOCK_SIZE="512" UUID="10CAA47B79449DFC" TYPE="ntfs" PARTUUID="0f74d1f0-08"

/dev/sdc6: UUID="84b50409-3535-4365-966b-1b3c87532ef3" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0f74d1f0-06"

/dev/sda2: UUID="a6010605-b185-4011-a6cc-f4f30ab30fab" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="f74451e6-02"

/dev/sda5: UUID="657053d0-6d36-44c5-984c-a1fcc09c74dd" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="f74451e6-05"

/dev/sda3: UUID="9810782d-55ba-47fd-8c23-99c25191fe91" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="f74451e6-03"

/dev/sda1: BLOCK_SIZE="512" UUID="F0C8738AC8734E3A" TYPE="ntfs" PARTUUID="f74451e6-01"

/dev/sda6: UUID="05b77b95-680c-4bba-902d-e809f859375d" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="f74451e6-06"

```

```
# file -s /dev/sda

/dev/sda: DOS/MBR boot sector
```

Part of dmesg after mounting

```
[  569.943518] ata1: limiting SATA link speed to 1.5 Gbps

[  569.943523] ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x6

[  569.943526] ata1.00: irq_stat 0x40000001

[  569.943530] ata1.00: failed command: WRITE DMA EXT

[  569.943539] ata1.00: cmd 35/00:08:00:10:80/00:00:25:00:00/e0 tag 20 dma 4096 out

                        res 51/04:08:00:10:80/00:00:25:00:00/e0 Emask 0x1 (device error)

[  569.943542] ata1.00: status: { DRDY ERR }

[  569.943544] ata1.00: error: { ABRT }

[  569.943548] ata1: hard resetting link

[  570.253303] ata1: SATA link up 1.5 Gbps (SStatus 113 SControl 310)

[  570.254143] ata1.00: configured for UDMA/133

[  570.254165] sd 0:0:0:0: [sda] tag#20 FAILED Result: hostbyte=DID_OK driverbyte=DRIVER_SENSE

[  570.254170] sd 0:0:0:0: [sda] tag#20 Sense Key : Illegal Request [current] 

[  570.254174] sd 0:0:0:0: [sda] tag#20 Add. Sense: Unaligned write command

[  570.254179] sd 0:0:0:0: [sda] tag#20 CDB: Write(10) 2a 00 25 80 10 00 00 00 08 00

[  570.254185] blk_update_request: I/O error, dev sda, sector 629149696 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0

[  570.254192] blk_update_request: I/O error, dev sda, sector 629149696 op 0x1:(WRITE) flags 0x800 phys_seg 1 prio class 0

[  570.254196] Buffer I/O error on dev sda5, logical block 0, lost sync page write

[  570.254214] ata1: EH complete

[  570.254251] EXT4-fs (sda5): I/O error while writing superblock

[  570.254535] EXT4-fs (sda5): mount failed

```

----------

## NeddySeagoon

apiaio,

```
[  569.943518] ata1: limiting SATA link speed to 1.5 Gbps

[  569.943523] ata1.00: exception Emask 0x0 SAct 0x0 SErr 0x0 action 0x6 
```

The error handler is well underway there. 

Put all of dmesg onto a pastebin as the interesting bit is not shown.

There are several things to do but you will be happier doing them if you have a backup or an image.

I will be happier to recommend things after I've seen more of dmesg.

----------

## apiaio

dmesg http://dpaste.com/9QUPCPGRB

Edit:

In the meantime I made backup of the most important partition using 

```
dd if=/dev/sda2 of=/dev/sdc5
```

----------

## NeddySeagoon

apiaio,

```
[    1.950348] EXT4-fs (sdc3): INFO: recovery required on readonly filesystem
```

That may indicate that you do not shut down your system cleanly. That can lead to corrupted filesystems.

How do you shut down?

At face value, 

```
[  139.437704] ata1.00: READ LOG DMA EXT failed, trying PIO

[  139.437708] ata1: failed to read log page 10h (errno=-5)

[  139.437714] ata1.00: exception Emask 0x1 SAct 0x20000000 SErr 0x0 action 0x6 frozen

[  139.437716] ata1.00: irq_stat 0x40000001

[  139.437721] ata1.00: failed command: WRITE FPDMA QUEUED

[  139.437730] ata1.00: cmd 61/08:e8:00:10:80/00:00:25:00:00/40 tag 29 ncq dma 4096 out

                        res 51/04:e8:00:10:80/00:00:25:00:00/40 Emask 0x1 (device error)

[  139.437733] ata1.00: status: { DRDY ERR }

[  139.437735] ata1.00: error: { ABRT }

[  139.437740] ata1: hard resetting link
```

says that the drive is not ready but there are error messages later that suggest that's not true.

Shut down cleanly and check the SATA data cable. 'Wiping' the contacts at both ends by disconnecting the cable and plugging it in again two or three times can work wonders for a few months. If that appears to fix it replace the SATA data cable.

From the SMART data, the drive is good. If its not the SATA data cable, try a different SATA part on the motherboard.

That may make all your drive names change, as kernel names are allocated in device detection order.

After that, it gets a bit more invasive. The ext range of filesystems have backup superblocks. We can try using one of them, if the filesystem is ext.

Do not run fsck. When faced with inconsistancies, it has to guess. When it guesses incorrectly, it makes a bad situation worse.

Your only way out then is with your backups,.

----------

## apiaio

I changed SATA data cable and changed position on motherboard. Now it is ata2, but resul is the same. I was trying format one partition

```
# mkfs.ext4 /dev/sda6

mke2fs 1.46.4 (18-Aug-2021)

Discarding device blocks: done                            

Creating filesystem with 14975958 4k blocks and 3744608 inodes

Filesystem UUID: 8cd1af72-5c76-425c-b79b-1f191954e159

Superblock backups stored on blocks: 

        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 

        4096000, 7962624, 11239424

Allocating group tables: done                            

Writing inode tables: done                            

Creating journal (65536 blocks): done

Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file system

```

----------

## NeddySeagoon

apiaio,

```
Writing superblocks and filesystem accounting information: mkfs.ext4: Input/output error while writing out and closing file system 
```

That says that it failed. The end of dmesg will say what happened.

The problem does appear to be more that one filesystem. 

Notice the 

```
Superblock backups stored on blocks: 32768 ...
```

 That's filesystem block numbers and ext can use 1k, 2k or 4k blocks. 4k is the most common.

Translating to 1k disk blocks, we get 131072.

Try 

```
mount -o ro,sb=131072 /dev/sd... /mnt/someplace
```

to tell mount to use the first backup superblock.

If it works, copy your data off. The -ro option stops mount setting the filesystem dirty bit, so it avoids a write, which is what seems to fail.

----------

## apiaio

I have successfully  mounted and copied data. Expect of that I ran smartctl long test once more. Result is the same.

Does exist any other method how to test the drive? Or should I replace it?

----------

## NeddySeagoon

apiaio,

That's encouraging. I suspect the primary superblock has become corrupt due to an unclean shutdown.

How do you shut down?

Now that you have your data, its safe to run fsck on the filesystem.

It will repair the primary superblock.

If that is *all* that fsck does, you are probably good and we need to look at how you shut down to make sure unclean shut downs are rare.

----------

## apiaio

When the problem started, I rebooted from win7 to gentoo, Both installed on sda. No unclean shutdown. 

Now I will try fsck.

Thanks

----------

## NeddySeagoon

apiaio,

How did you reboot?

Its happened more recently too as your root filesystem needed to be repaired in the dmesg you shared.

----------

## apiaio

Normal I do it in win7 using shutdown / restart button.

Fsck doesn't work on sda

```
# fsck /dev/sda2

fsck from util-linux 2.37.4

e2fsck 1.46.4 (18-Aug-2021)

/dev/sda2: recovering journal

fsck.ext4: Input/output error while recovering journal of /dev/sda2

fsck.ext4: unable to set superblock flags on /dev/sda2

/dev/sda2: ********** WARNING: Filesystem still has errors **********

```

I was trying clean partitions using fsdisk, but when I want to save changes i/o error is reported.

Does exist any method how to clean entire disk?

----------

## NeddySeagoon

apiaio,

If you really want to zero the entire drive, use the security erase function.

That leaves the SSD erased, so its ready for writes.

If you want to write to it all, 

```
dd if=/dev/zero of=/dev/... bs=1M 
```

Both will make all the data on the output device vanish, so do get it right.

dd will not erase the SSD, it will be written with zero's instead, so will need to be erased before it can be used.

Making a filesystem will trim the entire filesystem space, that's as good as an erase. No extra steps are required.

Security erase is the entire drive.

dd can be directed at a partition.

----------

## apiaio

I used dd, but it doesn't work. I am not able to erase MBR on sda.

After 

```
dd if=/dev/zero of=/dev/sda bs=446 count=1
```

MBR is not zeroed. I think, that disk is broken. It is possible to read not  to write.

I booted from win7 dvd trying to format or delete any partition on sda. No success.

 *Quote:*   

> apiaio,
> 
> How did you reboot?

 

Now I realize what you asked. Up to now I was thinking only about situation when the sda was corrupted.

I know, that when I was doing something with sda. I think zeroing sda6 with dd, system frozen. Using shutdown

or ctrl+alt+del did not work. I restarted PC manually. I know, that is not correct, but I think, that I did not

have any other possibility.

----------

## NeddySeagoon

apiaio,

Going read only, is a wear out failure mode in some SSDs.

The whole drive goes read only.

It looks like your warranty expired in Nov-21.

The Intel site says your drive is a TLC design.

The 240GB model spec sheet says Endurance Rating (Lifetime Writes) 73 TBW, so your 480GB drive should be good for 146 TBW,

That's about 300 erase cycles spread evenly over the entire drive. The wear levelling should to that.

The Power_On_Hours_and_Msec must have wrapped. You drive is over 5 years old (the warranty period) but only 417h power on hours? 

```
smartctl -x /dev/sda 
```

should tell a lot more but it may not be useful.

----------

## apiaio

 *Quote:*   

> The Power_On_Hours_and_Msec must have wrapped. You drive is over 5 years old (the warranty period) but only 417h power on hours? 

 

Strange. My PC has been on everyday for hours.

 *Quote:*   

> Going read only, is a wear out failure mode in some SSDs.
> 
> The whole drive goes read only.
> 
> It looks like your warranty expired in Nov-21. 

 

Does it mean that I should  to choose ssd according warranty time?

Just now I have possibility to purchase WD Blue WDF500G2BOA. Is it good choice? Warranty 60 months.

----------

## NeddySeagoon

apiaio,

Look at the Endurance Rating (Lifetime Writes) and divide it by the size of the drive.

That's the rated erase cycles.

SSDs now are Quad Level Cells (QLC) and Triple Level Cells (TLC).

The more bits per cell, the worse the Endurance Rating.

QLC drives have terrible Endurance Rating. Personally, I would not buy one for gentoo. However, as they store 4 bits per memory cell, they are lower cost that 3 bits per cell devices as they need fewer memory cells for the same capacity. 

That WD Blue WDF500G2BOA is rated about 400 erase cycles but beware, from the data sheet, some models in the range are not rated that many.

I suspect the smaller capacities ore TLC and the larger ones are QLC but there is no data on that.

----------

## apiaio

Neddy.

Could you please tell us where  found, that "warranty expired in Nov-21"? I am not able to find it.

I would like to check expiration of another 1T ssd, so I will have time to make backups in advance.

----------

## NeddySeagoon

apiaio,

The Intel Warranty page starts here.

Choose Intel NAND Solid State Drives from the drop down.

Then fill in your drive serial number, which I got from your smartcll output.

----------

## Hu

Drives don't necessarily fail when the warranty period runs out.  They also don't necessarily live long enough for the warranty to run out.  You should maintain backups for important data regardless of the age of the device containing it.  Warranty periods are chosen with the hope that most drives sold will outlive the warranty period, so that the manufacturer will not be obligated to fulfill the warranty's promise.  From that, you could infer that a long warranty period implies the manufacturer has a higher confidence in the longevity of the drive.  They would be foolish to offer a 60 month warranty on a drive family that routinely fails after 24 months, since that would obligate them to replace many of the drives under the warranty terms.  However, even if the manufacturer offered a 20 year warranty, you could still be unlucky and get a drive that dies after 1 year.

----------

## apiaio

A matter of course I do backups for important data as programing codes. I do not have backups of at least 3 operating systems but gentoo, which I have on my PC. Doing dd of the partitions with OS save the time. That is the point. Expect of that I do not have backups of plenty music and movies which I like. 

Talking about backup of OS. If I dd /dev/<ntfs partition> to /dev/<ntfs partition on other  disk> and after that dd back to the new disk would be win7 useful?

----------

## figueroa

dd isn't that great for backups of data. Use tar (or a backup program) to archive the data you value for maximum flexibility.

----------

## apiaio

IMHO backup of data is not the same like backup of operating system. Now I am in Gentoo installation which was backuped

using dd. After I had prepared the new drive into sda position an stored on the same partition, I have booted without any problem.

Unfortunately I was not lucky with Win7. I have to start from scratch.

----------

## figueroa

As long as you use the right tar switches:

```
 --acls --xattrs --numeric-owner
```

you can safely and efficienlty tar and compress your Gentoo Linux OS for restoration back to the same or some other location.

For example, my stage4 script is:

```
#!/bin/sh

#stage4.scr

# Also note: https://wiki.archlinux.org/index.php/rsync#Full_system_backup

# (to check for diffs) tar -d -f /mnt/backup0/stage4/stage4.tar.zst -I zstd

# (to restore) tar xpf /mnt/backup0/stage4.tar.zst -I zstd --acls --xattrs-include='*.*' --numeric-owner

mount /mnt/backup4

cd /

date > /mnt/backup4/stage4date.txt

tar cpf /mnt/backup4/stage4.tar.zst -I "zstd -9 -T0" --acls --xattrs --numeric-owner --no-wildcards-match-slash -X /PATH_TO/exclude.stage4 /

date >> /mnt/backup4/stage4date.txt

cd

sync

umount /mnt/backup4
```

My excludes are:

```
dev/*

home/*/*

home/lost+found

lost+found

media/*

mnt/*/*

proc/*

root/.cache/*

root/.thumbnails/*

root/.dbus/session-bus/*

run/*

sys/*

tmp/*

var/cache/distfiles/*

var/log/portage/*

var/tmp/*
```

Adjust to suit your layout. This give me a 3.8 GB zstd compressed stage4 tarball WITH all user accounts, but no user data (/home is a separate partition). I use it primarily as a backup. Takes 16 minutes on my spinning rust. I am able to restore this in-place, or to another partition, drive, or computer. If restoring to another computer, it may be necessary to recompile everything for different hardware and make new compatible kernel. Attention may be needed for /etc/fstab and network settings.

Other Linux OS can also be backed up with way with special attention to their unique disk layout.

For example, I use the following for an MX-Linux (Debian stable) "stage4."

```
lost+found

.cache/*

.fehbg

etc/NetworkManager/system-connections/*

dev/*

home/*/*

home/lost+found

media/*/*

mnt/*/*

proc/*

root/.cache/*

root/.dbus/session-bus/*

run/*

sys/*

tmp/*

var/cache/apt/archives/*.deb

var/cache/apt-xapian-index/index.*

var/cache/apt-show-versions/*

var/cache/apt/*.bin

var/cache/apt/apt-file/*

var/cache/debconf/*-old

var/cache/lightdm

var/cache/samba/browse.dat

var/cache/brightness-settings-cache/*

var/lib/apt/lists/*

var/lib/dbus/machine-id

var/lib/dhcp/*

var/lib/dpkg/*-old

var/lib/lightdm/.cache

var/lib/lightdm/.Xauthority

var/lib/NetworkManager/*

var/lib/nfs/rpc_pipefs/*

var/lib/sudo/*

var/lib/udisks/*

var/lib/urandom/*

var/log/!(samba|clamav)

var/log/clamav/*

var/log/samba/*

var/tmp/*
```

MX-Linux actually has a snapshot utility that creates a bootable and installable ISO with these exclusions. That's brilliant, of course, but a stage4 tarball is more flexible as one can easily extract a single or multiple files/directories for selective restoration in the event of goofs.

----------

