LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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 06-07-2011, 06:26 AM   #1
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Rep: Reputation: 35
Question Copy root filesystem from RAM to flash?


Hello,

I boot up a Linux appliance entirely in RAM, ie. the image has a Linux kernel and an attached ext2 root filesystem.

Now that it's working, I would like to copy the root filesystem from RAM to a NAND flash memory.

Can I just mount the NAND, run "cp -a /* /mnt/nand", reboot with the kernel command line "root=/dev/mtdblock2 rw", and expect Linux to be happy... or is it more involved than this?

Thank you.
 
Old 06-08-2011, 02:24 AM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,624

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
edited
 
Old 06-08-2011, 08:07 AM   #3
Soadyheid
Senior Member
 
Registered: Aug 2010
Location: Near Edinburgh, Scotland
Distribution: Cinnamon Mint 20.1 (Laptop) and 20.2 (Desktop)
Posts: 1,672

Rep: Reputation: 486Reputation: 486Reputation: 486Reputation: 486Reputation: 486
You can't copy a "live" running OS be it Linux, Windows, Unix, OSx or whatever as there are dynamic files which would fail to be copied correctly. This is assuming you could actually get the OS to copy! It would try to copy the process which is copying itself and would probably disappear up its own a....h Well, you get my drift?
That's why you would normally use a live CD to copy a HDD resident OS to another HDD. The source data is stable in this case.

Play Bonny!
 
Old 06-08-2011, 03:09 PM   #4
jefro
Moderator
 
Registered: Mar 2008
Posts: 21,980

Rep: Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624Reputation: 3624
I posed this question about that on a gentoo live dvd. One suggestion was to rsync it and exclude a few folders.

Kind of wonder if it wouldn't be easier to use the original image.
 
Old 06-09-2011, 02:54 AM   #5
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
It might not be recommended, but the appliance comes with a shell script that does just this, ie. copy the whole directory tree from RAM to the NAND memory, excluding useless directories:

Code:
mount /dev/mtdblock2 /mnt

cp -a /etc /mnt
cp -a /bin /mnt
cp -a /lib /mnt
cp -a /tmp /mnt
cp -a /home /mnt
cp -a /root /mnt
cp -a /usr /mnt
cp -a /sbin /mnt
cp -a /var /mnt
cp -a /dev /mnt
mkdir /mnt/mnt
mkdir /mnt/proc
mkdir /mnt/sys

sync
cd /
umount /mnt
 
Old 06-09-2011, 03:35 AM   #6
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
"s /useless/troublesome/"
There are (potentially) issues with this, but done carefully is quite well understood.
 
Old 06-09-2011, 11:28 AM   #7
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by littlebigman View Post
It might not be recommended, but the appliance comes with a shell script that does just this, ie. copy the whole directory tree from RAM to the NAND memory, excluding useless directories:

Code:
mount /dev/mtdblock2 /mnt

cp -a /etc /mnt
cp -a /bin /mnt
cp -a /lib /mnt
cp -a /tmp /mnt
cp -a /home /mnt
cp -a /root /mnt
cp -a /usr /mnt
cp -a /sbin /mnt
cp -a /var /mnt
cp -a /dev /mnt
mkdir /mnt/mnt
mkdir /mnt/proc
mkdir /mnt/sys

sync
cd /
umount /mnt
a quicker way would be to copy this little script into a file and execute it
Code:
!#/bin/bash
for dirtocopy in {etc,bin,lib,tmp,home,root,usr,sbin,var,dev}
do
cp -a /$dirtocopy /mnt
done
for dirtocreate in {mnt,proc,sys}
do
mkdir /mnt/$dirtocreate
done
sync
cd /
umount /mnt

Last edited by frieza; 06-09-2011 at 11:29 AM.
 
Old 06-10-2011, 04:10 AM   #8
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
Thanks Frieza for the script.

Quote:
Originally Posted by syg00 View Post
There are (potentially) issues with this, but done carefully is quite well understood.
I'm curious about potential issues: Could you elaborate a bit?
 
Old 06-10-2011, 05:18 AM   #9
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 21,126

Rep: Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120Reputation: 4120
See post #3 - you need to stay away from the pseudo filesystems.
 
Old 06-14-2011, 04:55 AM   #10
littlebigman
Member
 
Registered: Aug 2008
Location: France
Posts: 658

Original Poster
Rep: Reputation: 35
Thanks for the tip. It's just a small root fs on an embedded Linux, but I'll update the root partition from Uboot + rootfs file.
 
  


Reply



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
Need to know how to copy a root file from non corrupted filesystem to another amsweitzer General 4 04-20-2011 10:42 PM
How do I copy /dev/* from filesystem to filesystem Ulysses_ Linux - Desktop 12 03-09-2011 09:53 PM
root filesystem on RAM bluepenguine Linux - General 3 06-10-2009 03:42 AM
mount root fs from compact flash into ram Mr.J Linux - Embedded & Single-board computer 0 07-31-2008 07:22 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:57 AM.

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
Open Source Consulting | Domain Registration