# Mistakenly /etc folder was deleted, system can't reboot!!!



## jr.santhoshkumar (Feb 6, 2019)

I tried to copy the content of /etc to other folder, by mistake it was deleted.
Without knowledge I gave reboot command.
System is not booting. It is stoping in
mountroot>

Please help me to boot my system.
Thanks in advance


----------



## SirDice (Feb 6, 2019)

Did you move (rename) the directory instead of copying or did you actually delete it? If you moved/renamed it you can probably restore it back to its original name if you boot from one of the install mediums and use the shell.


----------



## sidetone (Feb 6, 2019)

Many /etc/ files can be copied from the FreeBSD install CD. Then, you'll have to adjust /etc/fstab for it to mount. Continue customizing your /etc/ files.


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> Did you move (rename) the directory instead of copying or did you actually delete it? If you moved/renamed it you can probably restore it back to its original name if you boot from one of the install mediums and use the shell.


I deleted /etc
If I try to do any modification in /
It is telling like read only file system


----------



## jr.santhoshkumar (Feb 6, 2019)

sidetone said:


> Many /etc/ files can be copied from the FreeBSD install CD. Then, you'll have to adjust /etc/fstab for it to mount. Continue customizing your /etc/ files.


I copied /etc folder to my memstick and
I tried to copy /etc to /  in FreeBSD
But it is telling like, file system is mounted in read only mode
I tired to change the mode read write, but it is asking for the file /etc/fstab.
Unfortunately everything was deleted.


----------



## SirDice (Feb 6, 2019)

I actually think you deleted a lot more than just /etc. Without a valid /etc/ the system would still boot the kernel and then get stuck in single user mode. The mountroot prompt shows you're stuck in loader(8) which happens _before_ the kernel is loaded.


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> I actually think you deleted a lot more than just /etc. Without a valid /etc/ the system would still boot the kernel and then get stuck in single user mode, the mountroot prompt shows you're stuck in loader(8).


For clear understanding, I attach a image
Please do the needful


----------



## SirDice (Feb 6, 2019)

It looks like you have a lot more issues than just a missing /etc. Your root filesystem is /dev/ada0s3a not ada0s3 (that's a slice). As the filesystem is also dirty you'll need to fsck(8) it first. Then `mount -u /dev/ada0s3a /` should mount it read/write. You can't use `mount -u /` because that depends on /etc/fstab (which is missing).

You do have backups, right?


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> It looks like you have a lot more issues than just a missing /etc. Your root filesystem is /dev/ada0s3a not ada0s3 (that's a slice). As the filesystem is also dirty you'll need to fsck(8) it first. Then `mount -u /dev/ada0s3a /` should mount it read/write. You can't use `mount -u /` because that depends on /etc/fstab (which is missing).


After executing that command,
the output is R/W mount of / denied. Filesystem is not clean


----------



## sidetone (Feb 6, 2019)

SirDice said:


> I actually think you deleted a lot more than just /etc. Without a valid /etc/ the system would still boot the kernel and then get stuck in single user mode. The mountroot prompt shows you're stuck in loader(8) which happens _before_ the kernel is loaded.


Mine did that when I switched connectors of physical harddrives around. /boot/ stayed the same, but now I realize that the error in this thread is not yet based on /etc/. /etc/ is part of the problem, but the error wasn't at that point yet.

It didn't necessarily have to do with altering the /boot/ directory. If it had to do with switching hard drive cables, labeling partitions for mounting is useful for future use http://www.wonkity.com/~wblock/docs/html/labels.html.


----------



## jr.santhoshkumar (Feb 6, 2019)

sidetone said:


> Mine did that when I switched connectors of physical harddrives around. /boot/ stayed the same, but now I realize that this error is not yet based on /etc/. /etc/ is part of the problem, but the error wasn't at that point yet.


Are you telling, this error is not only because of the /etc folder got deleted ?


----------



## SirDice (Feb 6, 2019)

jr.santhoshkumar said:


> After executing that command,
> the output is R/W mount of / denied. Filesystem is not clean


I'm just going to quote myself.


SirDice said:


> As the filesystem is also dirty you'll need to fsck(8) it first.


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> I'm just going to quote myself.


It is asking /etc/fstab file


----------



## sidetone (Feb 6, 2019)

jr.santhoshkumar said:


> Are you telling, this error is not only because of the /etc folder got deleted ?


The specific error with the `mountroot>` prompt is either because /boot/ got altered or deleted as SirDice said, or because hardware connectors were switched.

`fsck /dev/ada0s3a`


----------



## SirDice (Feb 6, 2019)

jr.santhoshkumar said:


> It is asking for /etc/fstab file


You really, really need to be able to handle situations like this yourself.

`fsck -y /dev/ada0s3a`


----------



## jr.santhoshkumar (Feb 6, 2019)

sidetone said:


> The specific error with the `mountroot>` prompt is either because /boot/ got altered or deleted as SirDice said, or because hardware connectors were switched.


I am sure that I didn't touch /boot/ folder
I think it is because of deletion of /etc folder
whether there is a way to add that /etc folder to / , so that it can boot normally.


----------



## SirDice (Feb 6, 2019)

jr.santhoshkumar said:


> whether there is a way to add that /etc folder to / , so that it can boot normally.


There are around 2370 files in 34 (sub)directories in /etc/. Only creating the /etc directory isn't going to help much.


----------



## sidetone (Feb 6, 2019)

jr.santhoshkumar said:


> I am sure that I didn't touch /boot/ folder
> I think it is because of deletion of /etc folder
> whether there is a way to add that /etc folder to / , so that it can boot normally.


Check your /boot/ directory to be sure. Also, it could have possibly been just from lacking /etc/fstab. Above, I said to copy the /etc/ directory from the FreeBSD install CD, then to manually modify the files, especially /etc/fstab, so it will boot.


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> There are around 2370 files in 34 (sub)directories in /etc/. Only creating the /etc directory isn't going to help much.


Adding /etc folder, it mean copying the /etc folder from the source code


----------



## jr.santhoshkumar (Feb 6, 2019)

SirDice said:


> You really, really need to be able to handle situations like this yourself.
> 
> `fsck -y /dev/ada0s3a`


I am sorry for that, now it is mounting properly.
Then what I need to do next for proper booting of my system?


----------



## SirDice (Feb 6, 2019)

You can try copying it from the install media. Remove /etc/rc.local though, that actually starts the installer. Then modify /etc/fstab and /etc/rc.conf for your system. Hopefully that's enough to restore some basic functionality.


----------



## olli@ (Feb 6, 2019)

The easiest and fastest way to recover from that situation is to boot FreeBSD from a USB stick, and then restore the /etc directory from your backup.


----------



## jr.santhoshkumar (Feb 8, 2019)

olli@ said:


> The easiest and fastest way to recover from that situation is to boot FreeBSD from a USB stick, and then restore the /etc directory from your backup.


I tried this method
I am using 12.0 stable version, so it is showing error like it is not matching with latest version
Because of that I have reinstalled again.
Thank you for spending your time for help me


----------



## jr.santhoshkumar (Feb 8, 2019)

SirDice said:


> You can try copying it from the install media. Remove /etc/rc.local though, that actually starts the installer. Then modify /etc/fstab and /etc/rc.conf for your system. Hopefully that's enough to restore some basic functionality.


Sir, I tried many methods but i end up with some error at last
So, I reinstalled again new memstickimage
Thank you SirDice


----------

