Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi
I'm new to Linux, and took on something that seemed like a simple task, but became very difficult in practice.
I have a NAS (Zyxel NSA325v2), which runs a light version of linux, BusyBox v1.17.2. Latest firmware offered by Zyxel is installed on the NAS. I'm logged in through SSH as root.
The task is to have the NAS execute a custom python script every 15 minutes using crontab. The problem I'm facing is that the custom crontab entry isn't persistent -- it vanishes when the NAS reboots.
The crontab where I put my custom entry resides in /var/spool/cron/crontabs/root. It has eight default entries that are persistent.
I have been able to track a file that writes some of these default entries: /ram_bin/etc/init.d/rcS2
I tried to mimic those default entries and added my custom entry in that file, but faced an issue when saving the changes: "Read-only filesystem". After googling I found that "more /etc/fstab" and "mount -l" give info about the mounts taking place in boot and the currently mounted filesystems, respectively. Scroll down for outputs of those commands.
So indeed the /ram_bin is read-only. Further googling revealed that "mount -o remount,rw" can help, but I wasn't able to find correct syntax that would do the trick.
So, my actual question is: Should I continue to try make the filesystem read-write to be able to modify rcS2 file, or is there an alternative solution to my actual problem -- getting the crontab entry persistent? Please help.
/ # mount -l
rootfs on / type rootfs (rw)
/proc on /proc type proc (rw,relatime)
/sys on /sys type sysfs (rw,relatime)
none on /proc/bus/usb type usbfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,mode=600)
/dev/mtdblock6 on /zyxel/mnt/nand type yaffs2 (ro,relatime)
/dev/sda1 on /zyxel/mnt/sysdisk type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /ram_bin type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /usr type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /lib/security type ext2 (ro,relatime,errors=continue)
/dev/loop0 on /lib/modules type ext2 (ro,relatime,errors=continue)
/dev/ram0 on /tmp/tmpfs type tmpfs (rw,relatime,size=5120k)
/dev/ram0 on /usr/local/etc type tmpfs (rw,relatime,size=5120k)
/dev/ram0 on /usr/local/var type tmpfs (rw,relatime,size=5120k)
/dev/mtdblock4 on /etc/zyxel type yaffs2 (rw,relatime)
/dev/md0 on /i-data/d3b34c71 type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/zy-pkgs type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /etc/zyxel/zy-pkgs type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/apache/htdocs/adv,/pkg type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/md0 on /usr/local/apache/web_framework/data/cache type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
/dev/mtdblock4 on /usr/local/apache/web_framework/data/config type yaffs2 (rw,relatime)
/dev/md0 on /usr/local/apache/htdocs/adv,/res/imdb_poster type ext4 (rw,noatime,barrier=0,data=writeback,usrquota)
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
I think you have more or less answered your own question, and clearly have done some very good research on it - which is very refreshing to see, well done.
The "Read-only filesystem" message means that even with "root" permissions, you cannot change/modify any files on that filesystem. So yes I'd agree that you need to mount the filesystem as read-write - if possible. I will admit that I don't have much experience with Busybox or NAS devices, so my help might be limited there.
The other thing is that as far as cron jobs are concerned, to my understanding, you would need to drop the cron job in one of the /etc/cron.X folders - change "cron.X" to "cron.daily", "cron.hourly", or whatever applies to you.
So, what you propose is to
1. add my cron job to /etc/cron.quarter_hourly, and
2. make the /dev/loop0 mount in /ram_bin read-write
I have follow-up questions on both:
1. What exactly is the "cron job"? Is that a file containing the crontab entry, or the target of the cron job i.e. the python script, or is it something else? Currently there are no folders named cron.X in /etc/ so it seems to me that is not the solution since there are eight default crontab entries.
2. I have tried various forms of "mount -o remount,rw" but none seem to do the trick. I've tried to give it the mount point /ram_bin and the mounted device /dev/loop0 as arguments but nothing seems to happen. What is the correct syntax and does it matter what the current folder is when executing the command?
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Quote:
Originally Posted by dr-artsi
Thanks for a quick response! Greatly appreciated!
So, what you propose is to
1. add my cron job to /etc/cron.quarter_hourly, and
2. make the /dev/loop0 mount in /ram_bin read-write
I have follow-up questions on both:
1. What exactly is the "cron job"? Is that a file containing the crontab entry, or the target of the cron job i.e. the python script, or is it something else? Currently there are no folders named cron.X in /etc/ so it seems to me that is not the solution since there are eight default crontab entries.
2. I have tried various forms of "mount -o remount,rw" but none seem to do the trick. I've tried to give it the mount point /ram_bin and the mounted device /dev/loop0 as arguments but nothing seems to happen. What is the correct syntax and does it matter what the current folder is when executing the command?
I'm not sure the "/etc/cron.quarter_hourly" is valid.
Yes, you should make the "root filesystem" read-write if possible, as you will not otherwise have permission to modify fstab. Depending on the device and/or system running on it, it may not be possible - once again, I don't have a NAS device to play with myself.
A cron job is basically a shell script that cron/anacron runs at particular intervals.
Have a look at the example fstab I gave you in my post above. You should mount via UUID's instead of the device node.
I'm not sure the "/etc/cron.quarter_hourly" is valid.
Yes, you should make the "root filesystem" read-write if possible, as you will not otherwise have permission to modify fstab. Depending on the device and/or system running on it, it may not be possible - once again, I don't have a NAS device to play with myself.
A cron job is basically a shell script that cron/anacron runs at particular intervals.
Have a look at the example fstab I gave you in my post above. You should mount via UUID's instead of the device node.
I don't know how to find the correct UUID's. Also the root filesystem seems to be read-write already. It's some other filesystems mounted on various folders that are read-only. I am able to modify /etc/fstab, but the changes I make aren't persistent.
I think I now have my answer on the filesystems: it's not possible to make /ram_bin read-write, scroll down to the last command.
Here are a few commands and corresponding outputs that I tried:
mount -o remount,rw
-outputs a long help text about mount
-no changes occured in the list given by "mount -l"
mount -o remount,rw -t ext2 /dev/ram0 /
-gives no output
-no changes occured in the list given by "mount -l"
mount -o remount,rw -t ext2 /dev/loop0 /
-gives no output
-no changes occured in the list given by "mount -l"
mount -o remount,rw -t ext2 /dev/loop0 /ram_bin
mount: block device /dev/loop0 is write-protected, mounting read-only
Distribution: Currently: OpenMandriva. Previously: openSUSE, PCLinuxOS, CentOS, among others over the years.
Posts: 3,881
Rep:
Quote:
Originally Posted by dr-artsi
I don't know how to find the correct UUID's. Also the root filesystem seems to be read-write already. It's some other filesystems mounted on various folders that are read-only. I am able to modify /etc/fstab, but the changes I make aren't persistent.
Try running the following command on the NAS system;
Code:
lsblk -f
Quote:
I think I now have my answer on the filesystems: it's not possible to make /ram_bin read-write, scroll down to the last command.
It looks like you're correct.
Quote:
Here are a few commands and corresponding outputs that I tried:
mount -o remount,rw
I'm not sure that would work, given you haven't specified which filesystem it should be mounting.
Quote:
...
mount -o remount,rw -t ext2 /dev/loop0 /ram_bin
mount: block device /dev/loop0 is write-protected, mounting read-only
If that's your NAS device, then that says it all - highlighted in bold.
But I'm still convinced there is a way to make it persistent. The NAS has a built-in user interface that opens with a web browser, and it is possible to make persistent changes there -- for example the SSH connection was not possible by default. A new package had to be installed through that browser interface. Also, all those modifications to the NAS settings are persistent --> There has to be some script or file or whatever somewhere that holds these changes that are made during run-time and then read during booting. That file is the place where I should add some magic line that puts in the crontab entry.
I will post an update here if I ever find that mystery-file.
Are you using crontab, or directly editing the files?
My crontab entry is somethong like this:
*/15 * * * * python /path/to/file/script.py
And that entry is in the root's crontab file. It works and does everything it should, except for the persistency. Note that the script resides on the mounted 750GB hard drive, not on the NAS itself.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.