Should go without saying this will void any warranty you have (But since my re-seller told me it only lasted 6 months I had nothing to lose)
The first thing you need is a broken Ubiquiti UniFi Security Gateway (USG). I encounter errors a few weeks back with the device not provisioning and rebooting occasionally. After further inspection through SSH it seemed to be in read only mode, and I concluded the flash had died.
After some googling I found out it is just a USB stick inside, and it can be replaced, but I can not find any decent guides on how to do so. So here we go.
Some information about the process:
Next thing is just a set of screwdrivers, you only really need a small Philips head for all screws.
The last thing you need is a blank USB drive of at-least 4g, mind is a Kingston DataTraveler 100 G3 (Because it was cheap on Amazon). As shown later on, this wasn't a great choise because of its size.
There are two ways to get this device ready, 1st you can clone the drive you take out of the USG (If it is not fully dead), or setup a new one. I am going to setup up a new drive from scratch.
To prepare this drive you need to download the base firmware image for the USG which can be found here - https://dl.ubnt-ut.com/cmb/USG-4_2_0-shipped.img.bz2
(If you are concerned about downloading the firmware form the internet, and its a fair worry. This file is provided from a UBNT employee here - https://community.ubnt.com/t5/UniFi-Routing-Switching/Dead-USG/m-p/2106454
sha1sum 80485aa3c770d61d16360afdab57fba820660ce8 USG-4_2_0-shipped.img.bz2
Once you have downloaded and extracted you can write the .img to the usb drive in many ways such as DD, but the easiest way is to use something like https://duct.me/etcher
Next step is to remove the little rubber feet on the bottom of the USG, these hide the screws. They are in each corner of the device, and pull of pretty easily. Once this is done you can go ahead and remove all four screws.
Once these have been removed, it is actually the other side (Top of the USG) that comes off, so flip the device over and remove the cover. (If this is the first time you have removed it, it was a little touch so I used a flat head screwdriver to loosen it).
Once inside, this is what the USG should look like. On the right hand side you can see the USB connector and drive plugged in. This is what we are going to remove, once again it is a little tight so do be careful.
Another shot showing the inside of the USG at an angle.
The top USB is the original taken form the USG, the bottom is the new one. I had to take it out of its original plastic casing as the USB connector is flush against the board of the USG so there is no room for bigger USBs.
The new USB in place, you can see how little room there is either side of the drive once the case goes back on.
Now just reassemble the device in the reverse to this post. First boot will take a while as it sorts it self out, then it will be just like a factory reset USG, it will however be out of date and require a few firmware upgrades. So go about the adoption process as you normally would.