Day to Day Linux Fixes Handbook
Preface
A quick day to day linux fixes to save you time looking for solutions in outdated forums, I’ll be updating this post every time I feel the need to document a “frequent issue” related to Linux.
NTFS
Unless you live in a bubble away from Microsoft Windows and Windows users, you’re gonna see NTFS from time to time, either an old drive from Windows days that you’re too afraid to format into a superior file system, or a friend or colleague hands you an NTFS drive that you have to deal with.
Mounting
You put an NTFS drive into your computer, sure you’re safe from nasty Windows viruses (unless if you ran a worm using Wine lol), but you’ll see an error like
wrong fs type, bad option, bad superblock on /dev/sdb1, missing codepage or helper program, or other error.
It must be annoying when trying to get a file quick from someone.
That’s why ntfs-3g made interacting with NTFS really easy on Linux (and other Unix-like systems), find your distor’s package from pkgs.org => ntfs-3g.
A quick install list so you won’t bother looking.
# Gentoo
emerge -av ntfs-3g
# Arch
pacman -Sy ntfs-3g
# Fedora/Red Hat
dnf install ntfs-3g
# openSUSE
zypper install ntfs-3g
# Debian/Ubuntu
apt install ntfs-3g
Then simply locate and mount your drive, either using bare mount or udisks
Mount command
Using mount, must run as root
mount /dev/sdb1 /mnt/ntfs-drive
Then you can access your drive at /mnt/ntfs-drive
Udisks utility
Using udisks can run as a regular user, but needs escelation, the difference between here and mount is that the mounted drive’s directory will have your permissions, i.e. you can r/w out of the box.
udisksctl mount -b /dev/sdb1
Then you can access your drive at:
/media/USER/DRIVE_LABEL_OR_UUID; on Debian and Ubunti/run/media/USER/DRIVE_LABEL_OR_UUID; on everything else
Formatting
Once you’ve installed ntfs-3g you’re good to go, i.e. you can just use mkfs.ntfs, e.g.
WARNING: This will erase the drive’s partition at /dev/sdb1.
mkfs.ntfs -L SomethingWindowsy -Q /dev/sdb1
FSCK
You’ve installed ntfs-3g but yet you get the nasty error when trying to mount the drive.
wrong fs type, bad option, bad superblock on /dev/sdb1, missing codepage or helper program, or other error.
Well, NTFS is kinda stupid and sensitive, that’s one of the many reasons Windows gets a blue screen of death after a sudden power outage.
Here you have 2 options, plug the drive back into a Windows machine (the person’s who’s giving you the drive).
Or just fix it on your device like a chad, again using ntfs-3g or ntfsprogs (most distros pack ntfsprogs within ntfs-3g).
Check for ntfsfix’s exitence in your system.
which ntfsfix
If it doesn’t exist, make sure you’ve installed ntfs-3g and check again.
Now after it’s installed, run the disk repair command as root.
ntfsfix -d /dev/sdb1
And voila you can just mount it.
PS: you can make it visible to fsck by linking ntfsfix into fsck.ntfs, i.e. (as root)
ln -s /bin/ntfsfix /sbin/fsck.ntfs
ln -s /bin/ntfsfix /sbin/fsck.ntfs-3g
Then you can run fsck which will use ntfsfix under the hood.
Something like:
fsck -db /dev/sdb1
And voila again.
Quote of the day
“Microsoft isn’t the problem, it’s the symptom”
- Eric S. Raymond