Command Line Hints and Tips

2024/02/26

Jez Caudle

Hints and tips.

A few hints and tips that I’m keeping here for my own information. Maybe someone else will find them helpful.

OpenBSD Formatting a disk bigger than 2TB

Master Boot Record only supports drives up to 2TB in size. For larger drives you’ll need to use a GUID Partition Table.

fdisk -gy sdX
disklabel -E sdX

sdX> a a
offset: [64] <return>
size: [some_number] *
FS type: [4.2BSD] <return>
sdX*> w
sdX> q
No label changes.

newfs sdXa

Searching for bad blocks using Linux

I bought two hard disks from CEX. One gave errors when placed into an OpenBSD softraid. I booted System Rescue from a USB disk and ran badblocks on it:

fdisk -l #list the disks
badblocks -v -s -o bad.txt /dev/sdX

The -v is for verbose output, -s shows a progress meter, -o is the file to store the bad block addresses that might be needed later and finally the device itself which you found using the fdisk command.

One drive had zero errors, the other 8,389 bad blocks. CEX refunded me the money for the bad disk without any fuss or bother.

Creating a repaired file from two broken files.

I had two copies of the same file. One had a corrupted start and the other a corrupted ending. I was able to merge the two using:

dd conv=notrunc if=./first_part of=./last_part bs=<size> count=<how_many_blocks>

The merged files will be saved as last_part so maybe copy both files first and use the copies?

Finding and deleting empty directories

I started off an unzipping of a file into the wrong directory so stopped it with a trusty Ctr-c but not before the creation of a loads of empty directories. A simple command to delete all the empty directories is:

find . -empty -type d -delete

man find for further details