Force fsck at boot time on the root file system (prior to mounting file systems, without Single-User mode)
How to automatically force fsck disks after crash in `systemd`? - does not mean anything.
Setting fsck_y_enable="YES"
and background_fsck="NO"
in /etc/rc.conf
don't do anything.
My root file system is not clean and has a lot of errors (due to a power outage - unexpected shutdown, not because hard drive or hardware are bad).
fsck
shows errors:
root@host2:/usr/home/alex # fsck
** /dev/mirror/gm0p2 (NO WRITE)
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=8268305 OWNER=root MODE=140777
SIZE=0 MTIME=Jun 6 21:58 2014
CLEAR? no
[skipped 100+ lines]
I don't have physical or KVM access to the server.
This is gmirror
ed drive
FreeBSD host2.domain.tld 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013 root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0p2 / ufs rw 1 1
/dev/mirror/gm0p3 none swap sw 0 0
freebsd fsck
add a comment |
How to automatically force fsck disks after crash in `systemd`? - does not mean anything.
Setting fsck_y_enable="YES"
and background_fsck="NO"
in /etc/rc.conf
don't do anything.
My root file system is not clean and has a lot of errors (due to a power outage - unexpected shutdown, not because hard drive or hardware are bad).
fsck
shows errors:
root@host2:/usr/home/alex # fsck
** /dev/mirror/gm0p2 (NO WRITE)
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=8268305 OWNER=root MODE=140777
SIZE=0 MTIME=Jun 6 21:58 2014
CLEAR? no
[skipped 100+ lines]
I don't have physical or KVM access to the server.
This is gmirror
ed drive
FreeBSD host2.domain.tld 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013 root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0p2 / ufs rw 1 1
/dev/mirror/gm0p3 none swap sw 0 0
freebsd fsck
Hm, what is yourfstab
? I heard creating a (presumably blank)forcefsck
file in/
(root) might work. Might give it a try.
– Seth
Jun 7 '14 at 4:37
1
touch /forcefsck
didn't do it.
– Alex G
Jun 7 '14 at 17:35
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43
add a comment |
How to automatically force fsck disks after crash in `systemd`? - does not mean anything.
Setting fsck_y_enable="YES"
and background_fsck="NO"
in /etc/rc.conf
don't do anything.
My root file system is not clean and has a lot of errors (due to a power outage - unexpected shutdown, not because hard drive or hardware are bad).
fsck
shows errors:
root@host2:/usr/home/alex # fsck
** /dev/mirror/gm0p2 (NO WRITE)
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=8268305 OWNER=root MODE=140777
SIZE=0 MTIME=Jun 6 21:58 2014
CLEAR? no
[skipped 100+ lines]
I don't have physical or KVM access to the server.
This is gmirror
ed drive
FreeBSD host2.domain.tld 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013 root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0p2 / ufs rw 1 1
/dev/mirror/gm0p3 none swap sw 0 0
freebsd fsck
How to automatically force fsck disks after crash in `systemd`? - does not mean anything.
Setting fsck_y_enable="YES"
and background_fsck="NO"
in /etc/rc.conf
don't do anything.
My root file system is not clean and has a lot of errors (due to a power outage - unexpected shutdown, not because hard drive or hardware are bad).
fsck
shows errors:
root@host2:/usr/home/alex # fsck
** /dev/mirror/gm0p2 (NO WRITE)
** Last Mounted on /
** Root file system
** Phase 1 - Check Blocks and Sizes
** Phase 2 - Check Pathnames
** Phase 3 - Check Connectivity
** Phase 4 - Check Reference Counts
UNREF FILE I=8268305 OWNER=root MODE=140777
SIZE=0 MTIME=Jun 6 21:58 2014
CLEAR? no
[skipped 100+ lines]
I don't have physical or KVM access to the server.
This is gmirror
ed drive
FreeBSD host2.domain.tld 9.2-RELEASE FreeBSD 9.2-RELEASE #0 r255898: Thu Sep 26 22:50:31 UTC 2013 root@bake.isc.freebsd.org:/usr/obj/usr/src/sys/GENERIC amd64
# Device Mountpoint FStype Options Dump Pass#
/dev/mirror/gm0p2 / ufs rw 1 1
/dev/mirror/gm0p3 none swap sw 0 0
freebsd fsck
freebsd fsck
edited Dec 19 '18 at 0:25
Rui F Ribeiro
39k1479129
39k1479129
asked Jun 7 '14 at 3:06
Alex G
1781514
1781514
Hm, what is yourfstab
? I heard creating a (presumably blank)forcefsck
file in/
(root) might work. Might give it a try.
– Seth
Jun 7 '14 at 4:37
1
touch /forcefsck
didn't do it.
– Alex G
Jun 7 '14 at 17:35
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43
add a comment |
Hm, what is yourfstab
? I heard creating a (presumably blank)forcefsck
file in/
(root) might work. Might give it a try.
– Seth
Jun 7 '14 at 4:37
1
touch /forcefsck
didn't do it.
– Alex G
Jun 7 '14 at 17:35
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43
Hm, what is your
fstab
? I heard creating a (presumably blank) forcefsck
file in /
(root) might work. Might give it a try.– Seth
Jun 7 '14 at 4:37
Hm, what is your
fstab
? I heard creating a (presumably blank) forcefsck
file in /
(root) might work. Might give it a try.– Seth
Jun 7 '14 at 4:37
1
1
touch /forcefsck
didn't do it.– Alex G
Jun 7 '14 at 17:35
touch /forcefsck
didn't do it.– Alex G
Jun 7 '14 at 17:35
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43
add a comment |
3 Answers
3
active
oldest
votes
FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /
), do fsck manually (fsck -y /
) and then reboot the machine.
add a comment |
If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early
something like fsck -fy /
added to that file will force it to do a scan and answer 'yes' to all prompts.
Do not forget to remove it from rc.early
when you are done, else it will run on every startup
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
add a comment |
As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root
to run /sbin/fsck -fy /
.
Here is the current script, modified to include that command commented out; uncomment to perform the fsck.
#!/bin/sh
#
# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $
#
# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
{
# root normally must be read/write, but if this is a BOOTP NFS
# diskless boot it does not have to be.
#
case ${root_rw_mount} in
[Nn][Oo] | '')
;;
*)
# Uncomment the below line to run fsck on root during boot:
#/sbin/fsck -fy /
if ! mount -uw /; then
echo 'Mounting root filesystem rw failed, startup aborted'
stop_boot true
fi
;;
esac
umount -a >/dev/null 2>&1
# If we booted a special kernel remove the record
# so we will boot the default kernel next time.
if [ -x /sbin/nextboot ]; then
/sbin/nextboot -D > /dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"
That's a little hacky, but working. But it should be/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f134952%2fforce-fsck-at-boot-time-on-the-root-file-system-prior-to-mounting-file-systems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /
), do fsck manually (fsck -y /
) and then reboot the machine.
add a comment |
FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /
), do fsck manually (fsck -y /
) and then reboot the machine.
add a comment |
FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /
), do fsck manually (fsck -y /
) and then reboot the machine.
FreeBSD has properly working forced unmount, so you don't really need to do this at boot. Just log in (remotely), remount rootfs as read-only (mount -fur /
), do fsck manually (fsck -y /
) and then reboot the machine.
answered Aug 1 '17 at 15:15
Edward Tomasz Napierala
1,0281410
1,0281410
add a comment |
add a comment |
If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early
something like fsck -fy /
added to that file will force it to do a scan and answer 'yes' to all prompts.
Do not forget to remove it from rc.early
when you are done, else it will run on every startup
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
add a comment |
If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early
something like fsck -fy /
added to that file will force it to do a scan and answer 'yes' to all prompts.
Do not forget to remove it from rc.early
when you are done, else it will run on every startup
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
add a comment |
If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early
something like fsck -fy /
added to that file will force it to do a scan and answer 'yes' to all prompts.
Do not forget to remove it from rc.early
when you are done, else it will run on every startup
If you need a command to be run early in the boot process (still in single user mode) add them to the shell script /etc/rc.early
something like fsck -fy /
added to that file will force it to do a scan and answer 'yes' to all prompts.
Do not forget to remove it from rc.early
when you are done, else it will run on every startup
answered Jun 15 '14 at 15:57
Allan Jude
67436
67436
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
add a comment |
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
1
1
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
Support for /etc/rc.early is now deprecated
– Alex G
Jun 15 '14 at 21:08
add a comment |
As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root
to run /sbin/fsck -fy /
.
Here is the current script, modified to include that command commented out; uncomment to perform the fsck.
#!/bin/sh
#
# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $
#
# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
{
# root normally must be read/write, but if this is a BOOTP NFS
# diskless boot it does not have to be.
#
case ${root_rw_mount} in
[Nn][Oo] | '')
;;
*)
# Uncomment the below line to run fsck on root during boot:
#/sbin/fsck -fy /
if ! mount -uw /; then
echo 'Mounting root filesystem rw failed, startup aborted'
stop_boot true
fi
;;
esac
umount -a >/dev/null 2>&1
# If we booted a special kernel remove the record
# so we will boot the default kernel next time.
if [ -x /sbin/nextboot ]; then
/sbin/nextboot -D > /dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"
That's a little hacky, but working. But it should be/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
add a comment |
As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root
to run /sbin/fsck -fy /
.
Here is the current script, modified to include that command commented out; uncomment to perform the fsck.
#!/bin/sh
#
# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $
#
# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
{
# root normally must be read/write, but if this is a BOOTP NFS
# diskless boot it does not have to be.
#
case ${root_rw_mount} in
[Nn][Oo] | '')
;;
*)
# Uncomment the below line to run fsck on root during boot:
#/sbin/fsck -fy /
if ! mount -uw /; then
echo 'Mounting root filesystem rw failed, startup aborted'
stop_boot true
fi
;;
esac
umount -a >/dev/null 2>&1
# If we booted a special kernel remove the record
# so we will boot the default kernel next time.
if [ -x /sbin/nextboot ]; then
/sbin/nextboot -D > /dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"
That's a little hacky, but working. But it should be/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
add a comment |
As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root
to run /sbin/fsck -fy /
.
Here is the current script, modified to include that command commented out; uncomment to perform the fsck.
#!/bin/sh
#
# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $
#
# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
{
# root normally must be read/write, but if this is a BOOTP NFS
# diskless boot it does not have to be.
#
case ${root_rw_mount} in
[Nn][Oo] | '')
;;
*)
# Uncomment the below line to run fsck on root during boot:
#/sbin/fsck -fy /
if ! mount -uw /; then
echo 'Mounting root filesystem rw failed, startup aborted'
stop_boot true
fi
;;
esac
umount -a >/dev/null 2>&1
# If we booted a special kernel remove the record
# so we will boot the default kernel next time.
if [ -x /sbin/nextboot ]; then
/sbin/nextboot -D > /dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"
As of FreeBSD 10.3, you can achieve this by temporarily modifying /etc/rc.d/root
to run /sbin/fsck -fy /
.
Here is the current script, modified to include that command commented out; uncomment to perform the fsck.
#!/bin/sh
#
# $FreeBSD: stable/10/etc/rc.d/root 177062 2008-03-11 17:21:14Z delphij $
#
# PROVIDE: root
# REQUIRE: fsck
# KEYWORD: nojail
. /etc/rc.subr
name="root"
start_cmd="root_start"
stop_cmd=":"
root_start()
{
# root normally must be read/write, but if this is a BOOTP NFS
# diskless boot it does not have to be.
#
case ${root_rw_mount} in
[Nn][Oo] | '')
;;
*)
# Uncomment the below line to run fsck on root during boot:
#/sbin/fsck -fy /
if ! mount -uw /; then
echo 'Mounting root filesystem rw failed, startup aborted'
stop_boot true
fi
;;
esac
umount -a >/dev/null 2>&1
# If we booted a special kernel remove the record
# so we will boot the default kernel next time.
if [ -x /sbin/nextboot ]; then
/sbin/nextboot -D > /dev/null 2>&1
fi
}
load_rc_config $name
run_rc_command "$1"
edited Sep 27 '17 at 16:56
answered Apr 20 '16 at 20:52
antiduh
277110
277110
That's a little hacky, but working. But it should be/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
add a comment |
That's a little hacky, but working. But it should be/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
That's a little hacky, but working. But it should be
/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
That's a little hacky, but working. But it should be
/sbin/fsck -fy /
– Jimmy Koerting
Sep 27 '17 at 15:31
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
@JimmyKoerting - thanks; fixed.
– antiduh
Sep 27 '17 at 16:56
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f134952%2fforce-fsck-at-boot-time-on-the-root-file-system-prior-to-mounting-file-systems%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hm, what is your
fstab
? I heard creating a (presumably blank)forcefsck
file in/
(root) might work. Might give it a try.– Seth
Jun 7 '14 at 4:37
1
touch /forcefsck
didn't do it.– Alex G
Jun 7 '14 at 17:35
Are you using "initramfs" ?
– SHW
Mar 21 '16 at 6:43