I'm writing in C for a while so I was reading Jim Larson's C style guide which prosthelytizes on the One True Bracket Style among other things. Good lord I had no idea indenting styles had names.
I am fine with 1TBS, but but I can't take tab=8 spaces. It is awful. Sorry.
27 September 2013
23 September 2013
Upgrading Embedded Systems Using Rsync
Rsync-based Upgrades
Rsync is a marvelous if somewhat intimidating file-synchronization tool. I've been using it with good results to upgrade embedded linux devices in the field. (We have a backup kernel and root filesystem partition, so this is not a crazy as it sounds.)
Rsync is one of those programs that can do some many things that it is sometimes easier to modify an example what you want to do rather than trying to figure it out from the man page. So here are two examples.
Say we have a directory newroot that contains an image of the root file system we want to apply to a remote system:
newroot/
bin/
etc/
alsa/
asound.conf
pcm/
myApp.conf
(...)
opt/
myApp
(...)
Upgrade Root Filesystem Using Rsync
If we want to replace an entire root filesystem we can do it like this:
rsync -RlptzvPDe "ssh -i ~/.ssh/id.rsa" --checksum --delete --stats --exclude="sudo" --exclude="sudoedit" --exclude="shadow" --exclude="gshadow" newroot/bin newroot/etc newroot/lib newroot/sbin newroot/opt newroot/usr newroot/var/lib newroot/www newroot/boot root@192.168.187.1:/
switches controlling what to copy: (r)ecursive and recreate (l)inks
switches controlling metadata: (p)ermissions (t)ime but not (D)evices (g)roup (o)wner (as we want ssh user to own everything)
other required switches: (z)compress (e)xecute-via-ssh --checksum (slower but safer)
other useless switches: (P)rogress (v)erbose --stats
Specifying the root source directories (/bin, /etc...) avoids problems associated with the special directories like /proc and /dev.
Note I am using the not-particularly-safe --delete option. That is one reason why syncing special directories would be unwise.
The excludes are there to prevent attempts to overwrite a couple of other files associated with authentication.
Upgrade Multiple Files Using Rsync
Say you just need to send a couple of files. Rsync is very fast even when asked to duplicate the entire root filesystem, but sometimes the root filesystem built by the cross-compiling toolchain defers constructing the startup script order until first boot. Upgrading everything restores the system to first boot configuration, with the result that a checkconfig script might run to reconstruct the various scripts in /etc/rcS.d. That is unnecessary if none of that is actually changing.Here's how to upgrade a few selected files (myApp and myApp.conf) using rsync:
rsync -RlptzvPDe "ssh -i ~/.ssh/id.rsa" --checksum --stats newroot/./etc/myApp.conf newroot/./opt/myApp root@192.168.187.1:/
Here we've used (R)elative paths instead of (r)ecursive. Identifying the part of the relative path you want to transfer with a "." is a trick from the rsync manual; it means "copy relative path starting here." Since the target is / we end up upgrading files in /etc and /opt on the remote.
One issue: it seems rsync cannot upgrade itself via rsync!
Hello Splefty World
It's been about 15 years since I first had a web page on the Internet and seven since I last updated my pathetic blosxom-based blog. I'm restarting it mostly to post some notes on computer stuff so I can find it later by Googling myself. Don't expect any scintillating reading.
Subscribe to:
Posts (Atom)