Erased /etc/rc.conf how to recover it?

BeastieBoy

Member

Reaction score: 1
Messages: 80

It's all in the title. Is there a way to regenerate my /etc/rc.conf file? The FreeBSD box is still running, I just can reboot it anymore :(
 
OP
B

BeastieBoy

Member

Reaction score: 1
Messages: 80

Well by copying and editing /etc/defaults/rc.conf I could remember some stuff like enable_sshd="YES" and hostname.

Is there somewhere a blueprint of a default FreeBSD Release 8 file? My box is only a few days old, so /etc/rc.conf should be (exactly?) the same as a mint one. I didn't add manually anything to that file yet.
 

fwaggle

Member

Reaction score: 6
Messages: 62

A default rc.conf is basically empty for all intents and purposes - the stuff from /etc/defaults/rc.conf is imported first, and then things are overridden by /etc/rc.conf. Put your sshd_enable in there, and your ifconfig details for your network interfaces and your system should boot fine, I think.
 
OP
B

BeastieBoy

Member

Reaction score: 1
Messages: 80

No mine had some stuff regarding network, but I don't remember exactly what.

Now I have:
Code:
hostname
firewall_enable
ifconfig_lo0
named_enable
sshd_enable
timed_enable
ipv6_enable
sendmail_enable
But I know I'm missing stuff.
 

zeiz

Aspiring Daemon

Reaction score: 57
Messages: 691

Code:
hostname="yourhost.YOURDOMAIN" 
ifconfig_lo0="DHCP"
sshd_enable="YES"
You can find yourhost.YOURDOMAIN by running uname -a
 

sk8harddiefast

Daemon

Reaction score: 201
Messages: 2,157

my rc.conf so change it to yours.
Code:
hostname="bsdserver.bsd" [B]Change it to yours as zeiz said[/B]
ifconfig_re0="192.168.1.4 netmask 255.255.255.0" [B]re0 is my module because i have realtek chipset. Change re0 to yours[/B]
ipv6_enable="YES"
font8x8="NO" [B]if yes that change the font on console[/B]
defaultrouter="192.168.1.1" [B]Change it to your routers ip[/B]
moused_enable="YES"
hald_enable="YES"
linux_enable="YES" [B]if you choosed linux compatibility say yes. Otherwise say no here[/B]
dbus_enable="YES"
 

Parad1se

New Member


Messages: 9

I have had my share of empty files in FreeBSD.. (before i started typing 'sync' every chance i get) ;)

Your root partition is standard (512MB)?
If so.. you can dump the disk to files on another partition. (you can script.. use DD to make files of 1MB a piece)

then you can use grep "sshd_enable" in those files to find the one where you data is in.
Then open the file in some editor and cut out all that's not from the rc.conf file.



I have even used this method to get files of a server that was already formatted and reinstalled. :)
 

kisscool-fr

Active Member

Reaction score: 23
Messages: 206

Don't know if you can restore the file as it was just before the deletion but the basics should be :

Code:
keymap="..."
hostname="..."
defaultrouter="..."
ifconfig_if0="..."
...

sshd_enable="YES"

Then you have to remember what is running on it.

Take a look in /usr/local/etc/rc.d directory if you installed something new and to the output of the ps command.
 

fronclynne

Daemon

Reaction score: 178
Messages: 1,296

See what [cmd=""]ifconfig[/cmd] says to get an idea about your network settings, use top(1) in verbose mode or try lots of ps(1) flags to poke around ([red]-aux[/red] is pretty comprehensive) and see what daemons are running. I have a few optional daemons like nfsd, sshd, ntpd, mountd, & powerd here, yours may vary.

Good luck. Once every few days I create a bzipped tar of /etc/, so I don't have to worry about accidental deletions like that. It takes up all of about 300k (/usr/local/bin/7z gets it down to 258k, which is hardly worth the hassle). Just backing up the user-modified files is left as an exercise for the reader.
 

Hakaba

Active Member

Reaction score: 108
Messages: 208

I just made this mistake...
And to avoid future issue like this, I will use GIT right now... (maybe a good default idea for FreeBSD 14 ?)
Thanks for all your suggests to retrieve my /etc/rc.conf
 

fcorbelli

Member

Reaction score: 31
Messages: 93

See what [cmd=""]ifconfig[/cmd] says to get an idea about your network settings, use top(1) in verbose mode or try lots of ps(1) flags to poke around ([red]-aux[/red] is pretty comprehensive) and see what daemons are running. I have a few optional daemons like nfsd, sshd, ntpd, mountd, & powerd here, yours may vary.

Good luck. Once every few days I create a bzipped tar of /etc/, so I don't have to worry about accidental deletions like that. It takes up all of about 300k (/usr/local/bin/7z gets it down to 258k, which is hardly worth the hassle). Just backing up the user-modified files is left as an exercise for the reader.
You can make 1-hours backup (forever) in not much more than 300KB with zpaq/zpaqfranz
Even of a full /usr too
 

mer

Member

Reaction score: 23
Messages: 46

If you are using ZFS, snapshots are your friend.
So are Boot Environments. Especially Boot Environments.
A practice that has helped me for a long time is:
After a fresh install and verify everything is running correctly, create a new boot environment, to preserve the current working one.
Before an upgrade of a running system, create a boot environment to preserve the current working one and then do the upgrade. I tend to upgrade into the "default" BE. Others will create a new BE, chroot into it and then upgrade (I think vermaden has a page showing this).
Why do this? You can use the command bectl or beadm to actually temp mount a BE and go look at it. You can modify it, look at it, copy files from it; it's your instantly available backup.

Now, what may help you:
don't reboot yet :)
run the command "service -e" to get a list of enabled services. By comparing them to /etc/defaults/rc.conf you get an idea of what you explicitly enabled (if it is disabled by default).

A fresh install typically doesn't have much more than
hostname="whatever your host is called" You can use the hostname command to figure this out
ifconfig_em0="DHCP" This is correct if you are using DHCP, the trailing part is the interface, ifconfig helps to figure that out
#ifconfig_em0="inet 192.168.250.37 netmask 255.255.255.0" This and the following are how you do static IPV4 and route
#defaultrouter="192.168.250.50" Command netstat -rn can tell you this
sshd_enable="YES" Obvious what this does
moused_enable="YES" Enables the mouse on console so you can cut and paste
ntpd_enable="YES" Obviously enables NTP
# Set dumpdev to "AUTO" to enable crash dumps, "NO" to disable
dumpdev="AUTO"
zfs_enable="YES" You need this if you are using ZFS
kld_list="/boot/modules/i915kms.ko" This is how you load drm-kmod stuff
syslogd_flags=" -b 127.0.0.1" This forces syslog to only listen on local host
 

vermaden

Son of Beastie

Reaction score: 1,572
Messages: 2,996

  • Thanks
Reactions: mer

Hakaba

Active Member

Reaction score: 108
Messages: 208

Another tip is bsdconfig -> C -> 2 to see all available options.
 

gotnull

New Member

Reaction score: 3
Messages: 9

@fcorbelli
First time I hear of this tool "zpaq", it looks like interesting.
I checked its git repo but the last commit was in 2016 would you say that it is not maintained anymore ?
 

fcorbelli

Member

Reaction score: 31
Messages: 93

@fcorbelli
First time I hear of this tool "zpaq", it looks like interesting.
I checked its git repo but the last commit was in 2016 would you say that it is not maintained anymore ?
There is a BSD port with a lot of other things, zpaqfranz, my fork.
You can find on github (not the last version)

In a nutshell: it's like a sort of 7z or rar with snapshots

Very quick and very dirty
Code:
mkdir /tmp/testme
cd /tmp/testme
wget http://www.francocorbelli.it/zpaqfranz/ports-51.10.tar.gz
tar -xvf ports-51.10.tar.gz
make install clean
 

jmos

Active Member

Reaction score: 116
Messages: 159

Instead of any tool, GIT or trying to find out the deleted values I would recommend to use a simple backup.
 

mer

Member

Reaction score: 23
Messages: 46

Instead of any tool, GIT or trying to find out the deleted values I would recommend to use a simple backup.
That is a reasonable thought, but I think the OP basically has/had a running system and deleted rc.conf so no backups, no save of local modifications.

I'd guess that going forward the OP "won't do that"
 

Trihexagonal

Daemon

Reaction score: 1,703
Messages: 2,277

I would open a text editor and make one. Either from the desktop or Single User Mode using ee.
It's not that big a deal to fix any more than if you failed to quote a line while editing it and got that message on reboot.

I keep a copy of /etc on USB stick to update all my system files after a rebuild. Here's the /etc/rc.conf from the machine I'm using now:

Code:
hostname="bakemono"
ifconfig_em0="DHCP"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
powerd_enable="YES"
powerd_flags="-a hiadaptive -b adaptive"
dumpdev="NO"
sendmail_enable="NO"
syslogd_flags="-c -ss"
microcode_update_enable="YES"
hald_enable="YES"
dbus_enable="YES"
linux_enable="YES"
avahi_daemon_enable="YES"
fsck_enable="YES"
swapexd_enable="YES"
clean_tmp_X="YES"
clear_tmp_enable="YES"
devd_enable="YES"
devfs_system_ruleset="devfsrules_common"
tcp_drop_synfin="YES"
pf_enable="YES"
pf_rules="/etc/pf.conf"
pf_flags=""
pflog_enable="YES"
pflog_logfile="/var/log/pflog"
pflog_flags=""
ssh_enable="NO"
 

Hakaba

Active Member

Reaction score: 108
Messages: 208

Instead of any tool, GIT or trying to find out the deleted values I would recommend to use a simple backup.
You are right. I decide to reinstall FreeBSD 13 from scratch on my personal laptop and this happened before I made the first backup. I have a backup of the previous install but without last changes (trying to enable 2 screen on this laptop !). I lost nothing with this bad experience...
My servers are still in FreeBSD 12 and have backup.
 
Top