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

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](https://www.cubieforums.com/index.php?topic=875.0) 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`