Bobcares

Recover from File System Corruption Using FreeBSD’s Single-User Mode

by | Jan 18, 2021

Wondering how to recover from File System Corruption Using FreeBSD’s Single-User Mode? We can help you.

Here at Bobcares, we have seen several such FreeBSD related queries as part of our Server Management Services for web hosts and online service providers.

Today, we’ll take a look at the steps we can take to boot the FreeBSD droplet into single-user mode and how to use the tools to recover a damaged filesystem.

 

Important Considerations

In any circumstance, the best way to prevent data loss is through good backups. So implementing an offsite backup solution and thoroughly testing it on a regular basis is the best way to guarantee the integrity of the important data.

The recovery options like fsck are often useful. But there is no guarantee that it will work correctly every time. The fsck operation can occasionally cause data corruption on active disks. Problems can still occur in cases of severe damage though, so we consider these last-resort methods for data recovery.

 

Booting to Single User Mode

We run the below command to boot the droplet into single-user mode.

sudo nextboot -o "-s" -k kernel

This will instruct the droplet to enter single-user mode on the next reboot rather than attempting to load the full system. Once we are ready we use the reboot command to reboot the droplet.

sudo reboot

After rebooting the droplet, it will no longer be accessible over the network via ssh.

So, we would need to access the droplet via the console in the control panel. Once the reboot completes, we see the below line:

Enter full pathname of shell or RETURN for /bin/sh:

Then we press Enter to start a shell session.

 

Alternate Method for File System Corruption

If the droplet is not accessible via ssh we can still boot the droplet to single-user mode using this alternate method.

First, in the control panel, we click on the power cycle button to reboot the droplet.

Immediately after this, we open the droplet’s console. After a few seconds we see a screen as shown below:

file system corruption

At this menu, we select item 2 and press enter to continue.

 

Performing a File System check

Now we have our droplet in single-user mode. First, we must know the device that we are checking. We run the below command to display the filesystems currently configured.

cat /etc/fstab

Here is the output that we receive.

file system corruption

Here, the first item in the list shows a ufs filesystem. We were looking for this itself. Now, we run the below command to perform a filesystem check on this disk.

fsck -yf /dev/gpt/rootfs

 

Checking the Results

Once the filesystem check is complete, we reboot the droplet to leave single-user mode and restart the dropet in normal (Multi-User) mode. For that, we run the below command.

reboot

We connect to the droplet using an SSH client. If the droplet responds to the ssh connection and it was not before then this is a good sign.

Our Techs suggest trying these suggestions if you run into any specific problems that alerted you to the possibility of corruption.

Check the /lost+found directory. This is where fsck puts partially recovered files.

Sometimes, fsck recovers file data, but it cannot find a reference to the file on the filesystem. Basically, it is a file without a name. If fsck faces this situation, then it places these files in the /lost+found directory so that you can manually try to figure out what the file is.

After running the fsck, check if anything has been placed in that directory. Also, the lost+found directory is only available to the root user. So, first change the root account with a sudo su command:

sudo su
cd /lost+found
ls

If there are files in this directory, you can see and identify them. Often, these are files that you had deleted anyways, but were still being used when the system crashed. It is worth checking them though to be sure.

[Need any further assistance with FreeBSD queries? – We are here to help you.]

 

Conclusion

Today, we discussed the suggestions our Support Engineers provided to recover from File System Corruption Using FreeBSD’s Single-User Mode.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

_reb2bgeo - The visitor's geographical location

_reb2bloaded - Whether or not the script loaded for the visitor

_reb2bref - The referring URL for the visit

_reb2bsessionID - The visitor's RB2B session ID

_reb2buid - The visitor's RB2B user ID

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid
_reb2bgeo, _reb2bloaded, _reb2bref, _reb2bsessionID, _reb2buid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF