LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (http://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Copy root filesystem from RAM to flash? (http://www.linuxquestions.org/questions/linux-newbie-8/copy-root-filesystem-from-ram-to-flash-884966/)

littlebigman 06-07-2011 06:26 AM

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.

John VV 06-08-2011 02:24 AM

edited

Soadyheid 06-08-2011 08:07 AM

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! :hattip:

jefro 06-08-2011 03:09 PM

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.

littlebigman 06-09-2011 02:54 AM

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


syg00 06-09-2011 03:35 AM

"s /useless/troublesome/"
There are (potentially) issues with this, but done carefully is quite well understood.

frieza 06-09-2011 11:28 AM

Quote:

Originally Posted by littlebigman (Post 4380679)
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

;)

littlebigman 06-10-2011 04:10 AM

Thanks Frieza for the script.

Quote:

Originally Posted by syg00 (Post 4380723)
There are (potentially) issues with this, but done carefully is quite well understood.

I'm curious about potential issues: Could you elaborate a bit?

syg00 06-10-2011 05:18 AM

See post #3 - you need to stay away from the pseudo filesystems.

littlebigman 06-14-2011 04:55 AM

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.


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