How install Ubuntu into a CubieBoard and expand the NAND partition to 4GB

If you have a Cubieboard2, please jump to this post.

I have a CubieBoard 1 with a A10 CPU.

Install Ubuntu into the NAND

You can install a distro into a microSD card or into the internal NAND memory. For the best performance install Ubuntu into the NAND, you'll have 4GB and you can attach an external hard disk or the integrated microSD too.
You can install an Ubuntu image into the NAND with the LiveSuit app. I installed Lubuntu Server with LiveSuit app for Windows (My Cubie didn't enter in the FEL Mode with LiveSuit for Linux).

Resize the NAND partitions

Current layout

The system has a really strange partitions:
$ sudo sfdisk -s
/dev/nand:    3989504
/dev/nanda:     65536
/dev/nandb:      2048
/dev/nandc:   1048576
/dev/nandd:    524288
/dev/nande:   2348032


$ sudo df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nandc     1009M  495M  469M  52% /
none            405M     0  405M   0% /tmp
/dev/nandd      497M  295M  178M  63% /lib
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none             81M  236K   81M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            405M     0  405M   0% /run/shm
none            100M     0  100M   0% /run/user

I'm losing 2GB in the nande partition :O
I'd like to have nandc (/), nandd (/lib) & nande together. We have to do this from a distro running from the microSD card. I'll use Cubian (Debian) because it has preinstalled the tool for that.

Run Cubian from SD card

Install Cubian from its great wiki and connect to Cubian by SSH. There is a solved problem. You have to use the port 36000, user cubie, password cubie:
ssh -p 36000 cubie@The_Cubian_IP

Make a backup into your SD:
sudo su -
dd if=/dev/nand conv=sync,noerror bs=64K | gzip -c -9 > /nand.ddimg.gz

Discover your current NAND partition (as root):
root@Cubian:~# nand-part
check partition table copy 0: OK
check partition table copy 1: OK
check partition table copy 2: OK
check partition table copy 3: OK
partition  0: name =   bootloader, partition start =     2048, partition size =   131072
partition  1: name =          env, partition start =   133120, partition size =      4096
partition  2: name =       rootfs, partition start =   137216, partition size =  2097152
partition  3: name =         libs, partition start =  2234368, partition size =  1048576
partition  4: name =        UDISK, partition start =  3282944, partition size =  4696064
5 partitions

Well, well... we're in the hard step.
The Ubuntu system is using the partition 3 as /lib, we have to backup it, because it will be erased (as root too):
mkdir /lib_aux ; mkdir /media/lib
mount /dev/nandd /media/lib
cp -rp /media/lib/* /lib_aux/
umount /media/lib

We'll join the partition 2, 3 and 4 with this command (as root too):
nand-part /dev/nand "env 4096" "rootfs 7841792"
fsck -f /dev/nandc
resize2fs /dev/nandc 


The explanation is this (follow the colours): you will run the command: nand-part over the NAND memory: /dev/nand. And you'll set your new layout. You'll omit the first boot size partition (131072) because nand-part will autoreserve that partition:
  "env 4096" Same label/size for avoid changes in the Ubuntu boot.
  "rootfs 7841792" This is the final partition for Ubuntu (~4GB): 2097152 + 1048576 + 4696064. This will preserve your Ubuntu system from the "rootfs" partition, but it'll delete the contents of "libs" and "DISK".

Now, restore your /lib in Ubuntu (as root too):
mkdir /media/ubuntu

mount /dev/nandc /media/ubuntu
rm -r /media/ubuntu/lib
mkdir /media/ubuntu/lib
cp -rp /lib_aux/* /media/ubuntu/lib
vi /etc/mtab # Remove inside the file the line with /lib string
umount /media/ubuntu

Reboot your Ubuntu

The resize is done :D Poweroff and extract your microSD. Ubuntu will boot with all the space in the NAND:
# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/nandc      3.7G  856M  2.7G  24% /
none            405M     0  405M   0% /tmp
none            4.0K     0  4.0K   0% /sys/fs/cgroup
none             81M  216K   81M   1% /run
none            5.0M     0  5.0M   0% /run/lock
none            405M     0  405M   0% /run/shm
none            100M     0  100M   0% /run/user

14 comments:

  1. This is exactly what i was looking for!!

    Will it work for A20 Cubieboard ?

    ReplyDelete
    Replies
    1. Hi! Try this for Cubieboard2 ;) http://thinkonbytes.blogspot.com.es/2014/09/lubuntu-1404-for-cubieboard-2-nand-dd-installation-fast-easy.html

      Delete
  2. @Hélder Yes, It's universal for NAND memories. You have to change the numbers for your situation in the command:
    nand-part /dev/nand "env 4096" "rootfs 7841792"

    ReplyDelete
  3. Marcos.. please, do you think this could be possible with a TTL cable ? and unmount de nandc partition resize and mount again???
    Thanks!

    ReplyDelete
  4. @Erwin: I'm sorry, but I don't know about the TTL cable :O
    You have to do the resize with the partition umount.

    ReplyDelete
  5. Hi, I just tried resizing, and when i powered off the cubieboard and restarted it without the SD card, my original lubuntu would load...?

    ReplyDelete
  6. If you did it right, yes, it has to start! ;) Be careful with your partition table numbers! (See the post colours).

    ReplyDelete
  7. is it possible to do this without connecting thru SSH?

    ReplyDelete
  8. @Nancy: Yes, of course. Connect a HDMI monitor and a keyboard/mouse :)

    ReplyDelete
  9. sorry to be so annoying--- but when I take out the sdcard and reboot it, it stays on the starting screen and lubuntu does not run...
    It says switch_root: can't execute '/sbin/init': No such file or directory
    Kernel panic - not syncing: Attempted to kill init! exitcode=0x00000100

    Thank you for youre help!!

    ReplyDelete
  10. I think you did a wrong partition :O I think you have to reinstall into the NAND.

    ReplyDelete
  11. can anyone plz tel me how to install ubuntu in an 8gb micro sd card? i tried all d videos n links. any easy explanation with videos? I want to work on cubietruck using ubuntu. urgent plz n i am new to ubuntu. Thank u on advance.

    ReplyDelete
  12. Pq al descargar la imagen de Ubuntu e instalarla no se instala Ubuntu si no Linaro, o Lubuntu... qué es Linaro? Una versión de linux ligera que puede adoptar software especifico para ubuntu?

    Es posible instalar Ubuntu 12.04 Desktop (como lo conozco en mi portátil) en una CubieBoard2??

    ReplyDelete
  13. @Albert: Unity (Ubuntu) en un ordenador tan limitado como la Cubie no tendría un buen rendimiento y por eso es mucho mejor usar Lubuntu, que es exactamente Ubuntu con programas preinstalados y un entorno más ligero.

    En todo caso, si quieres hacer la prueba, supongo con instalando el paquete "ubuntu-desktop" instales Unity.

    Linaro creo que es la versión de Ubuntu para los procesadores ARM (la Cubie no lleva un Intel).

    ReplyDelete