LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 09-05-2013, 11:57 AM   #1
henryyao
LQ Newbie
 
Registered: Jul 2013
Posts: 23

Rep: Reputation: 0
Linux can not save changes if power off and then on?


Hi, i'm facing a werid thing in my arm-linux system:

After i do some changes to the linux file, for example, modification to /etc/inittab, chmod +x to xxx.sh, using i2ctools to set RTC values...I can see the changes are taken effect. However, after that, If i power my device off and then power on, some files will return to the original status that were before the changes.

What's more werid is that instead of power off the device, if I reboot the device using shell command, then the changes will remain effective, files will not return to the original status that were before the changes.
 
Old 09-05-2013, 12:46 PM   #2
smallpond
Senior Member
 
Registered: Feb 2011
Location: Massachusetts, USA
Distribution: CentOS 6 (pre-systemd)
Posts: 2,609

Rep: Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702Reputation: 702
Are you issuing a sync command before powering off so the changed blocks in memory are written to disk?
 
1 members found this post helpful.
Old 09-05-2013, 01:31 PM   #3
henryyao
LQ Newbie
 
Registered: Jul 2013
Posts: 23

Original Poster
Rep: Reputation: 0
I dont know there is such thing as sync.
Thanks a lot for the tip.

I've checked the man sync. It says 'sync' writes any data buffered in memory out to disk. This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes.

But why simple commands such as 'chmod +x' will be treated as a delayed reads and writes? Would it be the problem of my slow CPU and something wrong with the data bus?


Quote:
Originally Posted by smallpond View Post
Are you issuing a sync command before powering off so the changed blocks in memory are written to disk?
 
Old 09-05-2013, 03:54 PM   #4
Doc CPU
Senior Member
 
Registered: Jun 2011
Location: Stuttgart, Germany
Distribution: Mint, Debian, Gentoo, Win 2k/XP
Posts: 1,099

Rep: Reputation: 343Reputation: 343Reputation: 343Reputation: 343
Hi there,

Quote:
Originally Posted by henryyao View Post
I've checked the man sync. It says 'sync' writes any data buffered in memory out to disk. This can include (but is not limited to) modified superblocks, modified inodes, and delayed reads and writes.

But why simple commands such as 'chmod +x' will be treated as a delayed reads and writes? Would it be the problem of my slow CPU and something wrong with the data bus?
the speed and power of your CPU has nothing to do with this. It is very common for modern operating systems (not only Linux) to postpone write operations in order to improve performance. Especially the meta-data stored in the directory is updated very often - just think of the time of last access to a file. It wouldn't be clever to write every such change to disk immediately.

And so most systems just prepare this write operation in a buffer in memory and hold it back for some seconds (or even minutes), while subsequent updates only affect the buffered data in memory. Some time later, when the system is idling, it actually writes the modified data to disk.

So, to make sure every change is actually saved to disk, you either have to wait some time while the system is idle (but you don't know how long actually), or you have to force that by issuing a sync command. A controlled shutdown or restart implicitely does a sync.

[X] Doc CPU
 
Old 09-05-2013, 04:35 PM   #5
michaelk
Moderator
 
Registered: Aug 2002
Posts: 14,931

Rep: Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520Reputation: 1520
Can you provide some details on your ARM device? What is its make / model.
 
Old 09-05-2013, 09:29 PM   #6
henryyao
LQ Newbie
 
Registered: Jul 2013
Posts: 23

Original Poster
Rep: Reputation: 0
Its a tao3530-OMAP3530 chip.

What's superising me is that i'm using i2cset to set RTC time, and even this is buffered, need to use sync command.


Quote:
Originally Posted by michaelk View Post
Can you provide some details on your ARM device? What is its make / model.
 
Old 09-05-2013, 10:04 PM   #7
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
The best way to prevent problems is to shut the system down before removing power.

It doesn't matter HOW many "sync" commands you give... some buffers will not be written. Think about it - there are log file buffers that get updated... using the sync command itself causes a buffer to be updated... after the system call is given...

All sync does is MINIMIZE the damage, it doesn't remove all of it.
 
1 members found this post helpful.
Old 09-05-2013, 11:34 PM   #8
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
are we certain that /etc/inittab is not in ram?

a simple
Code:
df -h
will confirm
 
Old 09-06-2013, 09:06 AM   #9
henryyao
LQ Newbie
 
Registered: Jul 2013
Posts: 23

Original Poster
Rep: Reputation: 0
Very good point.

Quote:
Originally Posted by jpollard View Post
The best way to prevent problems is to shut the system down before removing power.

It doesn't matter HOW many "sync" commands you give... some buffers will not be written. Think about it - there are log file buffers that get updated... using the sync command itself causes a buffer to be updated... after the system call is given...

All sync does is MINIMIZE the damage, it doesn't remove all of it.
[COLOR="Silver"]

Last edited by henryyao; 09-06-2013 at 09:07 AM.
 
Old 09-06-2013, 09:07 AM   #10
henryyao
LQ Newbie
 
Registered: Jul 2013
Posts: 23

Original Poster
Rep: Reputation: 0
---------- Post added 09-06-13 at 09:06 AM ----------

[/COLOR]How to confirm that? I'm having the following output of df -h

root@devkit:~/tests# df -h
Filesystem Size Used Available Use% Mounted on
ubi0:rootfs 460.5M 337.7M 118.0M 74% /
none 115.5M 92.0K 115.4M 0% /dev
tmpfs 115.5M 72.0K 115.4M 0% /var/volatile
tmpfs 115.5M 0 115.5M 0% /dev/shm
tmpfs 115.5M 0 115.5M 0% /media/ram
/dev/mmcblk0p1 70.4M 2.9M 67.5M 4% /media/mmcblk0p1
/dev/mmcblk0p2 3.6G 2.2G 1.2G 65% /media/mmcblk0p2
/dev/mmcblk0p2 3.6G 2.2G 1.2G 65% /mnt


Quote:
Originally Posted by Firerat View Post
are we certain that /etc/inittab is not in ram?

a simple
Code:
df -h
will confirm
 
Old 09-06-2013, 09:38 AM   #11
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian Jessie / sid
Posts: 1,471

Rep: Reputation: 444Reputation: 444Reputation: 444Reputation: 444Reputation: 444
sorry, I should have posted this extended version first time round

Code:
df -T -h /etc/inittab
but it looks like it is not in ram

I did a little reading on ubi0

http://www.linux-mtd.infradead.org/faq/ubifs.html

looks like sync, and some time is what you need
 
Old 09-06-2013, 02:48 PM   #12
rm2629
LQ Newbie
 
Registered: May 2013
Location: USA
Distribution: Android, Mint, Ubuntu
Posts: 12

Rep: Reputation: 4
Another thing if you're writing application programs would be to fork() a child, have the child perform the file action, wait in the parent for the child to complete. Like this:

Code:
pid_t pid;
int w_status;
char *args[5] = {
    "cp",
    "-f",
    "filename1",
    "filename2"
    NULL
};
char *newenv[] = { NULL };

pid = fork();
if(pid < 0)
{
    // error condition - log as appropriate, you can use errno as well here
}
else if(pid == 0)
{
    // This is the child process, execute your actions
    if(execve("/bin/cp", args, newenv) == -1)
    {
        // Error condition - log
    }
}

// else condition - else no needed, this is the parent
waitpid(pid, &w_status, 0);
This will wait for the copy to be completed. Because the child process has to exit once it is done, it will resolve the file handles with the file system I.e. sync just the new file.

I find it faster than a full file system sync call. Again, for programming practice versus the shell.

Correct shutdowns are helpful. But on things like an ARM, it's likely embedded and therefore can be shut down by someone pulling the battery. Hence in a lot of cases, it's best to protect files as much as you can.

Last edited by rm2629; 09-06-2013 at 02:52 PM. Reason: mistyped reply first time
 
Old 09-07-2013, 02:44 AM   #13
jpollard
Senior Member
 
Registered: Dec 2012
Location: Washington DC area
Distribution: Fedora, CentOS, Slackware
Posts: 4,602

Rep: Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241Reputation: 1241
Waiting for a copy to complete does NOT guarantee that the blocks are on disk. All it means is that the process has completed transferring the buffers to the system.

NOT that the buffers are on disk.

That is why it is faster than a sync system call. It doesn't wait for the buffers to be flushed to disk.
It would be like turning off a printer before the last page has ejected... Sure, it has been printed... but has it been fixed...

Most embedded systems don't have a disk... so there is nothing to flush.

Last edited by jpollard; 09-07-2013 at 02:48 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Enable Power Save on My Linux Laptop to Prevent Lost of Data lennysokol Linux - Laptop and Netbook 4 06-01-2005 02:11 AM
Enabling power save/power management/cpu freq scaling features for a Debian system zero79 Debian 0 12-19-2004 02:17 PM


All times are GMT -5. The time now is 10:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration