ChatGPT fucked up my fstab file (I was also an idiot)
Background story I have a server where I need some more storage, with the only option being an external hard drive. This means that I need my server to auto mount my volume on system boot. Now this is actually fairly easy… One would think.
However, on Linux to do this in unmaintained mode (no user interaction with the system and no login) you need to edit /etc/fstab.
Where fstab stands for File System Table.
An entry in this file may look like this:
UUID=5821140f-ac3f-4dff-8969-02c54de796d8 / btrfs subvol=root 0 0
The UUID is an identifier for the device (for shadowing for the chatGPT fuck up). / is the mount point path. btrfs is the file system. subvol=root are options.
Finally 0 0 The first 0 is dump and the second is pass. I will not go into details on the different options, dump, and passes in this post. They are not really relevant.
However, I did not recall how to write such a line in the fstab file and to not search the web, I felt lazy.
I asked chatGPT to do it for me with the following prompt:
How to edit /etc/fstab to auto mount external harddrive
With the following response.
/dev/sdb1 /home/youruser/mydisk auto user,noauto 0 0
There are a few issues in this line and before I blame chatGPT to much this was partially me being stupid and trusting the damn thing to much.
I blindly copied this to my fstab file remembering that it was a valid way to do this.
I of course update /dev/sdb1 and /home/youruser/mydisk to what fit my needs.
I reboot the machine and I could not boot, due to issues with attempting to mount /dev/sdb1.
To bring my system to a bootable state, I need a live USB.
Boot into the live image, mount the root partition of the disk and remove the faulty line.
Test with mount -a which mounts all systems and also tells you if something is wrong.
Then reboot machine.
I forgot to run mount -a before reboot. Which makes me a flipping idiot… but we will get back to that.
So what is the problem, is the actual problem with the answer chatGPT gave?
Well first of using /dev/sdb1 is very, very old school and does not really work anymore.
You have to use the UUID for the device instead.
Which you can find by running sudo blkid /dev/sdb1 which for me gave:
/dev/sdb1: UUID="d966687c-91fc-4954-bfe1-f4d7d7a34c87" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="0137f5a5-01"
So I had to replace /dev/sdb1 with UUID=d966687c-91fc-4954-bfe1-f4d7d7a34c87.
Next, the file system type auto.
That is wrong.
From what I have been able to find afterwards.
File system type equal to auto has never worked with the default mount command nor in an fstab file.
I might not have looked deep enough but at least at surface level, you have to specify the file system type which for me is ext4.
Then the option noauto. OH MY FUCKING GODS!!!! From the mount commands manual page:
noauto
Can only be mounted explicitly (i.e., the -a option will not cause the filesystem to be mounted).
So using mount -a would not have tested if it actually could mount.
I was unaware of this and that is sort of my fault.
But it is crazy that chatGPT even suggest it.
Then finally and that is not a mistake in the above, but rather a thing that (in my opinion) always should be added for external drives.
That is to add the option nofail. From the mount commands manual page:
nofail
Do not report errors for this device if it does not exist.
What this means (amongst other things), is that the system will still be bootable even if the external drive has errors.
Thus, again I altered the /etc/fstab file ending up with the entry below. With the exception of nofails are irrelevant.
I just found them necessary for what I need to do.
The same for dump and check.
UUID=d966687c-91fc-4954-bfe1-f4d7d7a34c87 /home/youruser/mydisk ext4 nofail,rw,user,exec 0 1
So to summarise.
I tried to use chatGPT to quickly solve my issue.
I failed and caused quite a headache.
It generated an faulty fstab entry that caused my system to not be able to boot properly and even not testable with mount -a.
Whilst that was at the fault of chatGPT, I should not have taken its answer at face value.
I tried to save seconds, which caused an error that cost me roughly 15 minutes of fix time (including downloading the live USB image).
I could instead have gotten the correct answer from the Unix and Linux Stack Exchange Question: fstab mount problem.
Which took me less than a minute to find when searching online.
This is the second time I have tried where chatGPT caused or would have caused a system.
The first time was when I was asking some user permission rules and what I got back I could see was garbage.
This is not including where its suggesting for allowing to mount a single USB via usbguard was simply to disable usbguard.
Where the correct option is usbguard allow-device <DEVICE identifier>.
In conclusion, I will not be able to recommend chatGPT for Linux system administration tasks.
Side note, just for fun I tried Claude and Gemini too.
They gave close to the same response as chatGPT.
Although with Gemini instead of writing /dev/sdb1 simply wrote UUIDdev/sdb1.
I don’t know if this would have triggered me to go a look for what the UUID meant in this case, but still not brilliant.
Claude did not have the noauto option and it recommend running mount -a which for Claude would have saved my ass.
./Lars