I was updating my resume a little, converting it from a lousy Gimp project file to a LaTeX file (I know, should have done this waaaay sooner) on my laptop, when the battery died. Not really a problem, we have chargers for that! I plugged it in and booted it up. The first thing I noticed was that my awesomewm network speed, process counter and memory widgets weren't working. "Strange, maybe the lua script took a while to load", I thought. However, when I moved to the mount point of my 2nd M.2 (Samsung 860 evo) SSD, there was nothing there...
I rebooted to see if that was the issue, but that did not fix it. I then took it out and put it into the M.2 SSD enclosure and plugged it into my PC. The device did get recognized but it didn't get mounted as a storage device. I then put it back in my laptop and checked the BIOS to see if it was detected, and that also just worked. The only issue left was something with the data or the partition table (*subtle foreshadowing increases*)
When checking dmesg, I did see the device got detected, as a sata device on /dev/sda:
ata5: SATA link up 6.0 Gbps
ata5.00: ATA-11: Samsung SSD 860 EVO M.2 500GB
sd 4:0:0:0: [sda] Attached SCSI disk
So the device got detected, but it did not get mounted. In my fstab I mount the device per the HOMEWORK label, but apparently that went wrong now
# / was on /dev/nvme0n1p2 during installation
UUID=92920666-a0d5-441c-9def-2375802eb957 / ext4 errors=remount-ro 0 1
# /boot/efi was on /dev/nvme0n1p1 during installation
UUID=78A2-D7F8 /boot/efi vfat umask=0077 0 1
/swapfile none swap sw 0 0
LABEL=Homework /mnt/Homework auto nosuid,nodev,nofail,x-gvfs-show 0 0
When running the sudo blkid /dev/sda command, I did not get any output, which indicated the system did not see any partition on it. This was further confirmed by the output of the fdisk -l result:
Disk /dev/sda: 465.76 GiB, 500107862016 bytes, 976773168 sectors
Disk model: Samsung SSD 860
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
This meant that the partition table was gone and the partition probably slightly corrupt. Luckily, the testdisk command exists, which saved my ass. I installed and ran it:
sudo apt install testdisk
sudo testdisk
To write the partition table again, I used the following steps:
- Select: Create
- Select disk: /dev/sda
- Partition table type:
- If you installed Linux normally: EFI GPT
- If unsure: choose Intel/PC — TestDisk will detect the correct one automatically.
- Choose: Analyse
- Choose: Quick Search
- TestDisk will scan the entire disk and almost always find your old partition(s).
- Highlight the partition
- Press p to list files → if you see your data, it's correct
- Press Enter
- Select Write to restore the partition table
After that, when trying to mount it, I still got the error
mount: /mnt/Homework: mount(2) system call failed: Structure needs cleaning.
Which indicated that the partition was still partly corrupt. I fixed this with the sudo fsck -f /dev/sda1 command and entering "yes" for everything.
After that, my data was there again!