Difference between revisions of "Create a FLASH partition to store user's HOME"

From ArmadeusWiki
Jump to: navigation, search
(Linux)
(cleanup)
Line 1: Line 1:
If you ever did some hacking/devt on your APF board and used ''/root/'' to download or install your experiments, I'm sure you got frustrated when it come the time where you had to reflash the whole rootfs. Indeed, by default, ''/root/'' is located in the same partition as the rootfs image and so everything you did will be overwritten. Well you can always backup your data on a SD/microSD or through NFS before doing the rootfs flashing but I think, like me, you are little bit lazy.
+
If you ever did some hacking/devt on your APF board and used ''/root/'' to download or install your experiments, I'm sure you got frustrated when it comes the time where you had to reflash the whole rootfs. Indeed, by default, ''/root/'' is located in the same partition as the rootfs image and so everything you did will be overwritten. Well, you can always backup your data on a SD/microSD or through NFS before doing the rootfs flashing, but I think that, like me, you are little bit lazy ;-).
  
So in this small tutorial I will explain you how to setup the FLASH to store your personnal data on a separated partition and so avoid the backup process when updating your rootfs.
+
So in this small tutorial I will explain you how to modify the FLASH setup to store your personnal data on a separated partition and so avoid the backup process when updating your rootfs.
  
 
==Declare partition in U-Boot==
 
==Declare partition in U-Boot==
===apf27===
+
{{Warning|You may loose the content of your current rootfs partition if going further. So be sure to have backuped your data before.}}
 +
===APF27===
 
* Check your NAND FLASH size:
 
* Check your NAND FLASH size:
 
<pre class="apf">
 
<pre class="apf">
Line 16: Line 17:
 
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
 
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
 
</pre>
 
</pre>
* I have the default APF27 partitionning scheme. Now I will reduce rootfs size to 200 MBytes and so have the remaining (50 MBytes) for my "user" partition:
+
* I have the default APF27 partitionning scheme. Now I will reduce rootfs size to 200 MBytes (0x0C800000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
 
<pre class="apf">
 
<pre class="apf">
 
BIOS> setenv mtdparts mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
 
BIOS> setenv mtdparts mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
Line 33: Line 34:
 
</pre>
 
</pre>
  
===apf9328===
+
===APF9328===
 
TBDL
 
TBDL
  
Line 63: Line 64:
 
<pre class="apf">
 
<pre class="apf">
 
# cp -r /root/* /tmp/nand/
 
# cp -r /root/* /tmp/nand/
# cp -r /root/.* /tmp/nand/
+
# cp -r /root/.[ab]* /tmp/nand/
 
</pre>
 
</pre>
 
* Makes it automatically mounted at every boot by adding it to ''/etc/fstab'':
 
* Makes it automatically mounted at every boot by adding it to ''/etc/fstab'':
Line 75: Line 76:
 
* Now you're done. Reboot and enjoy ! ;-)
 
* Now you're done. Reboot and enjoy ! ;-)
 
<pre class="apf">
 
<pre class="apf">
 +
# reboot
 +
...
 
# df -h
 
# df -h
 
Filesystem                Size      Used Available Use% Mounted on
 
Filesystem                Size      Used Available Use% Mounted on
Line 84: Line 87:
 
# ls /root/
 
# ls /root/
 
</pre>
 
</pre>
* Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat ''/etc/fstab'' step above !
+
* Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat the ''/etc/fstab'' modification step above !

Revision as of 12:29, 30 December 2009

If you ever did some hacking/devt on your APF board and used /root/ to download or install your experiments, I'm sure you got frustrated when it comes the time where you had to reflash the whole rootfs. Indeed, by default, /root/ is located in the same partition as the rootfs image and so everything you did will be overwritten. Well, you can always backup your data on a SD/microSD or through NFS before doing the rootfs flashing, but I think that, like me, you are little bit lazy ;-).

So in this small tutorial I will explain you how to modify the FLASH setup to store your personnal data on a separated partition and so avoid the backup process when updating your rootfs.

Declare partition in U-Boot

Warning Warning: You may loose the content of your current rootfs partition if going further. So be sure to have backuped your data before.

APF27

  • Check your NAND FLASH size:
BIOS> nand info

Device 0: NAND 256MiB 1,8V 16-bit, sector size 128 KiB
  • So here I have 256MBytes. Then check current partitionning:
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),-(rootfs)
  • I have the default APF27 partitionning scheme. Now I will reduce rootfs size to 200 MBytes (0x0C800000 in hexa) and so have the remaining (50 MBytes) for my "user" partition:
BIOS> setenv mtdparts mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
BIOS> printenv mtdparts
mtdparts=mtdparts=mxc_nand.0:640k(U-boot)ro,384k(U-boot_env),512k(firmware),5M(kernel),200M(rootfs),-(user)
BIOS> setenv rootfs_len 0x0C800000
  • Erase the created partition (which now starts at (rootfs_offset + rootfs_len) = 0x0CE80000:
BIOS> nand erase 0x0CE80000
  • Save your changes and boot Linux:
BIOS> saveenv
BIOS> boot

APF9328

TBDL

Linux

  • In Linux boot message you should see you newly created partition detected:
6 cmdlinepart partitions found on MTD device mxc_nand.0                                                                                                                             
Creating 6 MTD partitions on "mxc_nand.0":                                                                                                                                          
0x000000000000-0x0000000a0000 : "U-boot"                                                                                                                                            
0x0000000a0000-0x000000100000 : "U-boot_env"                                                                                                                                        
0x000000100000-0x000000180000 : "firmware"                                                                                                                                          
0x000000180000-0x000000680000 : "kernel"                                                                                                                                            
0x000000680000-0x00000ce80000 : "rootfs"                                                                                                                                            
0x00000ce80000-0x000010000000 : "user"
  • Check a device node was created for your new partition (/dev/mtdblock5):
# ls /dev/mtdblock*
/dev/mtdblock0  /dev/mtdblock2  /dev/mtdblock4
/dev/mtdblock1  /dev/mtdblock3  /dev/mtdblock5
  • I will use JFFS2 as filesystem for the partition but as soon as UBIFS will be stable enough it will be usable too. So create a temporary mount point and mount the partition. It will be automatically formatted to JFSS2:
# mkdir /tmp/nand
# mount -t jffs2 /dev/mtdblock5 /tmp/nand
# ls /tmp/nand/
  • Move your user data to the partition:
# cp -r /root/* /tmp/nand/
# cp -r /root/.[ab]* /tmp/nand/
  • Makes it automatically mounted at every boot by adding it to /etc/fstab:
# vi /etc/fstab
...
sysfs           /sys           sysfs    defaults          0      0        
usbfs           /proc/bus/usb  usbfs    defaults          0      0
/dev/mtdblock5  /root          jffs2    defaults          0      0   <<-----------------
  • Now you're done. Reboot and enjoy ! ;-)
# reboot
...
# df -h
Filesystem                Size      Used Available Use% Mounted on
rootfs                  200.0M     17.8M    182.2M   9% /
/dev/root               200.0M     17.8M    182.2M   9% /
none                     64.0k         0     64.0k   0% /dev
tmpfs                    61.2M     44.0k     61.1M   0% /tmp
>>> /dev/mtdblock5           49.5M      4.0M     45.5M   8% /root <<<
# ls /root/
  • Of course if you reflash your rootfs, even if you keep your personnal data, you will have to repeat the /etc/fstab modification step above !