How to mount root file system on RAM?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to mount root file system on RAM?

3,384 Views
wangvictor
Contributor III

Hi community,

I'm using i.MX6 sabreSD for my platform and build the kernel with Yocto Project.

I'm thinking to mount root filesystem on RAM and start it.

Why I trying to do that because If I modify the content of root filesystem I do not want the original root be changed.

That means I need my root file system not changed even I modify the root.

So I just think of that I can start system on RAM and will loded the root on RAM everytime when I reboot the system.

Can I do that ?

If can how can I get this done?

0 Kudos
12 Replies

1,469 Views
rcornall
Contributor I

You can mount the filesystem as unionfs or overlayfs. 

This way any writes you do will be written to "layer" on top of the read-only in a seperate read-write layer.

Some info here:

linux - Mount a filesystem read-only, and redirect writes to RAM? - Unix & Linux Stack Exchange 

You can mount --bind / to /ro

After creating a tmpfs /rw

Your command would look something like:
`mount -t unionfs -o dirs=/rw=rw:/ro=ro unionfs /union`

/union  now contains both ro and rw, with writes going to the seperate tmpfs layer, and your read-only stays intact.

Then just `mount --move /union /` so its located at root.

0 Kudos

1,469 Views
wangvictor
Contributor III

I had worked on overlayfs for a long time.

I tried to install overlayroot package in Ubuntu 16.04.

However it worked fine on X86 based platform but not worked on ARM based platform.

I was stuck and had no clue to solve it that's why I try to did it with the other way.  

0 Kudos

1,469 Views
b36401
NXP TechSupport
NXP TechSupport

You can move all significant parts of rootfs into RAM this way:

mkdir /media/etc
mount tmpfs -t tmpfs /media/etc
cp -a /etc/* /media/etc
mount -o bind /media/etc /etc

Have a great day,
Victor

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos

1,469 Views
wangvictor
Contributor III

I do not want original file system be changed.

If I try to mount like you said.

It will change the old rootfs. 

0 Kudos

1,469 Views
witekewert-b463
NXP Employee
NXP Employee

Hello Victor,

You need to generate an initrd image to be loaded by u-boot and passed to the kernel.

First, make sure the image recipe you are building in Yocto has the following setting:

IMAGE_FSTYPES = "ext3 tar.gz cpio.gz.u-boot"
IMAGE_CLASSES = "image_types_uboot"

This will generate a partition image, an archive with all the files, and a compressed initrd with u-boot header. Place the cpio.gz.u-boot file on the first partition of the SD card, load it the same way u-boot loads the kernel (fatload), only use a different load address so you do not overwrite the kernel or devicetree.

Use bootz to boot the image:

bootz $loadaddr $your_initrd_address $fdt_addr

Finally, adjust your bootargs/mmcargs so that the kernel knows the root filesystem is in RAM, not on the SD card:

root=/dev/ram0

0 Kudos

1,469 Views
shivanipatel
Senior Contributor II

Hi wangvictor

You can mount rootfs over the network. First, you need to git commit your original rootfs then use the rootfs over the network by using Network File System (NFS) server. 

Please follow 1.2 section of below mentioned link to setup the NFS server.

https://community.nxp.com/docs/DOC-340583

To save time you can jump back to your original rootfs using git reset <commit_id> command.

Regards,

Shivani Patel

0 Kudos

1,469 Views
wangvictor
Contributor III

shivanipatel

Here is new update.

Previously problem I had solve it.

I need to set ethaddr for addition.

But now I got new error.

Kernel seems fine in beginning but show error in the end when it try to mount rootfs from my server.

Here was error log below.

[ 68.484025] winmate victor do_mount_root
[ 68.487980] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 73.503927] winmate victor moun_nfs_root
[ 133.604018] winmate victor do_mount_root
[ 133.607974] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 143.623947] winmate victor moun_nfs_root
[ 150.224012] random: nonblocking pool is initialized

[ 203.683975] winmate victor do_mount_root
[ 203.687926] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 223.703900] winmate victor moun_nfs_root
[ 283.843981] winmate victor do_mount_root
[ 283.847934] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 313.863901] winmate victor moun_nfs_root
[ 373.923974] winmate victor do_mount_root
[ 373.927928] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 403.943900] winmate victor moun_nfs_root
[ 464.163975] winmate victor do_mount_root
[ 464.167929] winmate victor do_mount_root name=192.168.120.115:/mnt/rai115/victor/imx-boot/imx6q-sabre/nfs, fs=nfs
[ 464.178293] VFS: Unable to mount root fs via NFS, trying floppy.
[ 464.184353] winmate victor mount_root CONFIG_BLOCK
[ 464.189306] winmate victor mount_block_root
[ 464.194083] winmate victor do_mount_root
[ 464.198030] winmate victor do_mount_root name=/dev/root, fs=ext3
[ 464.204148] VFS: Cannot open root device "nfs" or unknown-block(2,0): error -6
[ 464.211387] Please append a correct "root=" boot option; here are the available partitions:
[ 464.219847] 0100 65536 ram0 (driver?)
[ 464.224729] 0101 65536 ram1 (driver?)
[ 464.229496] 0102 65536 ram2 (driver?)
[ 464.234239] 0103 65536 ram3 (driver?)
[ 464.238899] 0104 65536 ram4 (driver?)
[ 464.243555] 0105 65536 ram5 (driver?)
[ 464.248475] 0106 65536 ram6 (driver?)
[ 464.253391] 0107 65536 ram7 (driver?)
[ 464.258049] 0108 65536 ram8 (driver?)
[ 464.262698] 0109 65536 ram9 (driver?)
[ 464.267351] 010a 65536 ram10 (driver?)
[ 464.272073] 010b 65536 ram11 (driver?)
[ 464.276810] 010c 65536 ram12 (driver?)
[ 464.281532] 010d 65536 ram13 (driver?)
[ 464.286266] 010e 65536 ram14 (driver?)
[ 464.290987] 010f 65536 ram15 (driver?)
[ 464.295731] 0800 8192 sda driver: sd
[ 464.300366] b300 7761920 mmcblk2 driver: mmcblk
[ 464.305710] b308 15288320 mmcblk3 driver: mmcblk
[ 464.311043] b309 12288 mmcblk3p1 f737a026-01
[ 464.316383] b30a 15271936 mmcblk3p2 f737a026-02
[ 464.321714] b320 128 mmcblk3rpmb (driver?)
[ 464.326997] b318 4096 mmcblk3boot1 (driver?)
[ 464.332326] b310 4096 mmcblk3boot0 (driver?)
[ 464.337673] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)
[ 464.345946] CPU1: stopping
[ 464.348664] CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.1.15-1.2.0+gbecce8c #107
[ 464.356061] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[ 464.362618] [<800168c4>] (unwind_backtrace) from [<80012728>] (show_stack+0x10/0x14)
[ 464.370373] [<80012728>] (show_stack) from [<8089c32c>] (dump_stack+0x84/0xc4)
[ 464.377603] [<8089c32c>] (dump_stack) from [<800157cc>] (handle_IPI+0x178/0x18c)
[ 464.385007] [<800157cc>] (handle_IPI) from [<80009480>] (gic_handle_irq+0x58/0x5c)
[ 464.392583] [<80009480>] (gic_handle_irq) from [<80013200>] (__irq_svc+0x40/0x74)
[ 464.400068] Exception stack(0xa8093f50 to 0xa8093f98)
[ 464.405123] 3f40: a8093f98 fffffff7 1cf273dc 0000006c
[ 464.413304] 3f60: ab72de90 00000000 1bc15f99 0000006c 1cf273dc 0000006c 00000001 00000000
[ 464.421486] 3f80: 00000017 a8093f98 a6aaaaab 8061044c 20000113 ffffffff
[ 464.428116] [<80013200>] (__irq_svc) from [<8061044c>] (cpuidle_enter_state+0xd8/0x20c)
[ 464.436133] [<8061044c>] (cpuidle_enter_state) from [<80065104>] (cpu_startup_entry+0x1fc/0x320)
[ 464.444925] [<80065104>] (cpu_startup_entry) from [<1000952c>] (0x1000952c)
[ 464.451896] ---[ end Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(2,0)

Besides, I think it used too much time to mount rootfs.

Any suggestion?

Thanks in Advanced!

0 Kudos

1,469 Views
shivanipatel
Senior Contributor II

wangvictor

Change your Board IP address in the /etc/exports in the server side.

e.g. : /mnt/raid115/victor/imx-boot/imx6q-sabre/nfs 192.168.*(rw,sync,no_root_squash,no_subtree_check)

Regards,

Shivani Patel

0 Kudos

1,469 Views
shivanipatel
Senior Contributor II

victor Wang

Please provide your U-Boot environment parameters using the printenv command.

e.g.

U-Boot > printenv

This command will list out all the U-Boot environment parameters.

Regards,

Shivani Patel

0 Kudos

1,469 Views
wangvictor
Contributor III

shivanipatel

I had tried the web that you gave me.

But when I run boot command after all the settings.

It showed below error.

Booting from net ...
*** ERROR: `ethaddr' not set
*** ERROR: `ethaddr' not set
Bad Linux ARM zImage magic!

Any suggestion? 

0 Kudos

1,469 Views
shivanipatel
Senior Contributor II

victor Wang

You can set fake MAC address through ethaddr environment.

e.g.

U-boot > setenv ethaddr 00:01:02:03:04:05

U-boot > saveenv

Regards,

Shivani Patel

0 Kudos

1,469 Views
wangvictor
Contributor III

Thanks for the tip.

I am new in NFS.

Could you give me some document for me to study how does NFS work.

Would it be changed anything on website rootfs while I modify any of file in local machine?

0 Kudos