Solved swapon: /dev/md0: Read-only file system

After the source-upgrade to 10.1 (from 10-STABLE a couple of months old), swapfile is no longer activated with the mentioned startup error.

/etc/fstab:
Code:
/dev/ad0s1a  /  ufs  rw,acls  1  1
md  none  swap  sw,file=/var/swap 0  0

Code:
[CMD]$ mount[/CMD]
/dev/ad0s1a on / (ufs, local, journaled soft-updates, acls)
devfs on /dev (devfs, local, multilabel)

Code:
[CMD]$ ls -l /dev/md*[/CMD]
crw-r-----  1 root  operator  0x93 Nov 17 01:44 /dev/md0
crw-------  1 root  wheel  0x4f Nov 16 21:44 /dev/mdctl


When run on a booted system:
Code:
[CMD]$ sudo swapon -a[/CMD]
swapon: /var/swap: Device already in use
 
Simply executing this command sequence on a freshly booted system correctly attaches the swap file:
Code:
[CMD]$ swapinfo [/CMD]
Device  1K-blocks  Used  Avail Capacity
[CMD]$ sudo mdconfig -l[/CMD]
md0
[CMD]$ sudo mdconfig -d -u 0[/CMD]
[CMD]$ sudo mdconfig -l[/CMD]
[CMD]$ sudo mdconfig -a -t vnode -f /var/swap [/CMD]
md0
[CMD]$ sudo swapon /dev/md0[/CMD]
[CMD]$ swapinfo [/CMD]
Device  1K-blocks  Used  Avail Capacity
/dev/md0  98304  0  98304  0%
[CMD]$[/CMD]
 
Remounting / without "acls " didn't help (and probably shouldn't have helped).
No source updates (via releng/10.1) fixing the issue, so it seems I'm the only one having it?
Attempting to manually mount /dev/md0 fails. The only way to do that is to recreate md0 from scratch as described in the above post.

Code:
[CMD]$ sudo mdconfig -l[/CMD]
md0
[CMD]$ sudo swapon /dev/md0[/CMD]
swapon: /dev/md0: Read-only file system
[CMD]$ sudo swapon -a[/CMD]
swapon: /var/swap: Device already in use
 
What are the permissions and ownership on /var/swap? What system settings have been changed from the default in /etc/rc.conf or /boot/loader.conf?
 
What are the permissions and ownership on /var/swap? What system settings have been changed from the default in /etc/rc.conf or /boot/loader.conf?
Code:
drwxr-xr-x  29 root  wheel  512 Nov 20 22:21 /var
-r--------  1 root  wheel  100663296 Nov 15 23:12 /var/swap

/boot/loader.conf
Code:
sysvshm_load="YES"
sysvmsg_load="YES"
sysvsem_load="YES"

vfs.unmapped_buf_allowed=0
# Beginning of the block added by the VMware software - DO NOT EDIT
vmxnet_load="YES"
# End of the block added by the VMware software
# Beginning of the block added by the VMware software - DO NOT EDIT
vmxnet3_load="YES"

(since this works under VMware,
Code:
vfs.unmapped_buf_allowed
is needed to work around spurious segmentation fault errors pertinent to running under VMware. In any case, this same configuration worked with 10-STABLE a few months old)

/etc/rc.conf
Code:
hostname="nigar.localnet"
defaultrouter="192.168.1.1"
ifconfig_le0_name="if0"

ifconfig_if0="inet 192.168.1.4/24"
ifconfig_em0="inet 192.168.2.2/24"

keyrate="fast"
font8x16="swiss-8x16"
font8x8="swiss-8x8"

sshd_enable="YES"
sshd_flags="-u0"

enable_quotas="YES"

ntpd_sync_on_start="YES"
ntpd_enable="YES"

sendmail_submit_enable="NO"   # Start a localhost-only MTA for mail submission

nfs_server_enable="YES"     # This host is an NFS server (or NO).
mountd_enable="YES"
rpcbind_enable="YES"     # Run the portmapper service (YES/NO).

syslogd_flags="-ss -c -vv -l 0600:/var/spool/postfix/var/run/log"   # Flags to syslogd (if enabled).


firewall_enable="YES"     # Set to YES to enable firewall functionality
firewall_script="/etc/rc.firewall" # Which script to run to set up the firewall
firewall_type="open"     # Firewall type (see /etc/rc.firewall)
firewall_quiet="NO"     # Set to YES to suppress rule display
firewall_logging="NO"     # Set to YES to enable events logging
firewall_flags=""     # Flags passed to ipfw when type is a file


gateway_enable="YES"     # Set to YES if this host will be a gateway.

accounting_enable="NO"   # Turn on process accounting (or NO).

watchdogd_enable="YES"   # Start the software watchdog daemon


ppp_enable="NO"     # Start user-ppp (or NO).


auditd_enable="YES"   # Run the audit daemon.

zfs_enable="YES"
(same working configuration)
 
I might also ask; is the fstab(5) you cited above, the entire fstab(5)? If not, could you post it, in it's entirety?

--Chris

Sure, I simply omitted irrelevant (in my opinion) lines besides / and swap:

Code:
# Device  Mountpoint  FStype  Options  Dump  Pass#
/dev/ad0s1a  /  ufs  rw,acls  1  1
/dev/cd0  /cdrom  cd9660  ro,noauto  0  0
/dev/gvinum/mydata  /mnt  ufs  rw,late,noauto  0  0
/dev/da0s1a  /usr/ports  ufs  rw  0  2
/dev/da1s1a  /usr/obj  ufs  rw,async  0  2

md  none  swap  sw,file=/var/swap 0  0

I hope their ordering hasn't become significant lately?
 
Sure, I simply omitted irrelevant (in my opinion) lines besides / & swap:
Sure. I just wanted to see if their might be a conflicting entry. But I don't see any. :)
rihad said:
Code:
# Device  Mountpoint  FStype  Options  Dump  Pass#
/dev/ad0s1a  /  ufs  rw,acls  1  1
/dev/cd0  /cdrom  cd9660  ro,noauto  0  0
/dev/gvinum/mydata  /mnt  ufs  rw,late,noauto  0  0
/dev/da0s1a  /usr/ports  ufs  rw  0  2
/dev/da1s1a  /usr/obj  ufs  rw,async  0  2

md  none  swap  sw,file=/var/swap 0  0
rihad said:
I hope their ordering hasn't become significant lately?
Generally speaking; no. :)

--Chris
 
My swapfile has write permission for the owner (0600).

# chmod u+w /var/swap && reboot

Nah, same thing. To be able to use a file as swap (through MD backed by a vnode) mode bits didn't matter when it worked. It seems to be more of a user level access restriction (against strings /var/swap and such)
 
For fun, try adding a nonzero unit number to the md in /etc/fstab. That is the only other difference I see.
 
Guys, does swapfile (via /etc/fstab) really work in 10.1-RELEASE as expected?
I could install a pristine fresh binary release on another VM just to confirm.
Another thing different is my kernel configuration, which is basically GENERIC, really:

Code:
include GENERIC
ident  MY
nomakeoption  DEBUG
nomakeoption  WITH_CTF

nocpu  I486_CPU
nocpu  I586_CPU

nooptions  INET6  # IPv6 communications protocols

My /etc/make.conf
Code:
KERNCONF=MY
CPUTYPE=core2
NO_INET6=  true  # do not build IPv6 related programs and libraries
NO_PROFILE=  true  # Avoid compiling profiled libraries
PPP_NO_SUID=  # build with normal permissions

NO_PORTSUPDATE=yo  # portsnap(8) takes care of this
SVN_UPDATE=yup
SVN=/usr/bin/svnlite

WITHOUT_X11=yo
 
I'm using it with no problems:
Code:
md99       none     swap   sw,file=/usr/swap/swap   0   0
Code:
ls -lh
-rw-------  1 root  wheel  4.0G Nov 20 16:02 /usr/swap/swap
 
rihad.
OK last I looked (just built an 11-CURRENT last week). md(4) was included in GENERIC.
Code:
options    MD_ROOT       # MD is a potential root device
But it wouldn't hurt to check. I also notice you mount(8) swap on /var. But have no /var entry in fstab(5). While strictly speaking, there's no requirement to mount(8) /var separately. I always do.
using a gpt gpart(8) partition/slice:
Code:
/dev/gpt/gvar   /var     ufs   rw   2   2
or by way of an MBR partition/slice:
Code:
/dev/ada0p4   /var     ufs   rw   2   2
I always mount /tmp on tmpfs(5). But I see you don't. What would happen if you attempt to mount(8) SWAP in temp?
eg;
Code:
md    none    swap    sw,file=/tmp/swap    0    0
but at the same time, why don't you also modify your root mount to the following:
Code:
/dev/ad0s1a    /    ufs    rw    1    1
imposes less restriction. So in other words, simply change those lines (in single user mode). Then bounce the box. No harm will come of it. But it might help pin things down, as to what's causing your issue.

HTH

--Chris
 
I just grabbed a fresh install suited for VMs (http://ftp.freebsd.org/pub/FreeBSD/...i386/Latest/FreeBSD-10.1-RELEASE-i386.vmdk.xz)
which comes configured to use /dev/gpt/swapfs in /etc/fstab ( top showing 1024M swap). I commented that line, and added the working md line to it, added the swap file:
# dd if=/dev/zero of=/var/swap bs=1m count=64
# chmod 600 /var/swap
and rebooted. It didn't work with the same
Code:
swapon: /dev/md0: Read-only file system
error.
Something weird is going on.
 
Chris_H, GENERIC does come with
Code:
options MD_ROOT
It all works once I recreate the md0 file and enable swap on it. Only I have to do it manually. It's no problem to write a simple script and drop it in /usr/local/etc/rc.d/*, just wondering if this error is by design :)

Considering that the FreeBSD startup machinery also does everything "manually" (simple script-based toolbox approach akin to what I wrote to correct it), this looks like a bug.
 
This is all very curious. To the best of my knowledge. Your attempts should work as intended. If I get a chance later today. I'll grab a couple spares, and attempt a fresh install using md(4) as SWAP, and report my findings here.
Point being; it is not intended to fail "by design". :)

All the best.

--Chris
 
Adding "late" to the fstab(5) entry did the trick.
Code:
md  none  swap  sw,file=/var/swap,late 0  0
It's now being taken care of by /etc/rc.d/swaplate, which, according to rcorder, comes much later than /etc/rc.d/swap, at which time the root filesystem (on which /var resides in my case) has already been mounted read-write by /etc/rc.d/root. No more "read-only file system" errors by swapon...

Looks like the fstab(5) manpage needs to be updated to reflect the change in requirements.
 
What change? It works here. /etc/rc.d/swaplate was committed in June of 2013, so that is not new either.

Please show the uname output from your system.
 
Code:
FreeBSD nigar 10.1-RELEASE FreeBSD 10.1-RELEASE #9 r274626: Mon Nov 17 20:39:52 AZT 2014  root@nigar:/usr/obj/usr/src/sys/MY  i386

It's basically GENERIC, I brought up the configuration in post #13.
 
wblock@, do you also keep the swap file on the root filesystem? If not, this might be the difference, as it is the only filesystem which seems to be mounted read only first.
 
My / and /usr are separate filesystems, and the swapfile is on /usr. My system is amd64, 10.1-STABLE r274909 from yesterday.
 
Back
Top