Wednesday, December 24, 2014

pcDuino3 Nano - Adding a SATA Disk - System Setup

This is another in the series documenting my setup of a new home server with the Linksprite pcDuino3 Nano.  A listing for the entire series can be found here.  More information on the pcDuino3 Nano can be found at Linksprite’s website and the pcDuino website.

Now that I have the corrupted nand root file system resolved the next step was to configure the system with the root file system on the SATA drive.

I booted the system without the sd card as I Once the system booted the first thing I did was to check to make sure that the system could see the drive.  There are a number of ways to do this.  I used the lsblk command:

root@ubuntu:~# lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0 931.5G  0 disk
nand     93:0    0   3.6G  0 disk
├─nanda  93:1    0    32M  0 part
├─nandb  93:2    0    16M  0 part
├─nandc  93:3    0    16M  0 part
└─nandd  93:4    0   3.5G  0 part /

The lsblk command reports two block devices.  These are sda which is the SATA disk I just connected to the system and the onboard NAND storage.  You can tell that the system is running from the root file system nandd by looking at the mount point.

1) Format the drive.  This is done using fdisk,  In my case I was looking to have one partition that consisted of the entire drive.

root@ubuntu:~# fdisk /dev/sda

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help): n
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p): p
Partition number (1-4, default 1): <cr>
Using default value 1
First sector (2048-1953525167, default 2048):
<cr>
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-1953525167, default 1953525167):
Using default value 1953525167

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 83

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

If you run the lsblk command again you will see the changes.

root@ubuntu:~# lsblk
NAME    MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda       8:0    0 931.5G  0 disk
└─sda1    8:1    0 931.5G  0 part
nand     93:0    0   3.6G  0 disk
├─nanda  93:1    0    32M  0 part
├─nandb  93:2    0    16M  0 part
├─nandc  93:3    0    16M  0 part
└─nandd  93:4    0   3.5G  0 part /

We now have a partition sda1.

2) Copy the root file system to the SATA disk.  Insert the sd card and run lsblk and you now have three block devices.  We will be copying the root file system which is on the second partition of the sd card on /dev/mmcblkl0p2.

root@ubuntu:~# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk
└─sda1        8:1    0 931.5G  0 part
nand         93:0    0   3.6G  0 disk
├─nanda      93:1    0    32M  0 part
├─nandb      93:2    0    16M  0 part
├─nandc      93:3    0    16M  0 part
└─nandd      93:4    0   3.5G  0 part /
mmcblk0     179:0    0   7.4G  0 disk
├─mmcblk0p1 179:1    0    16M  0 part /media/CDE1-5BFE
└─mmcblk0p2 179:2    0   7.4G  0 part /media/7f1334b8-5b94-49a2-aa48-e0d31f19ef9

root@ubuntu:~# dd if=/dev/mmcblk0p2 of=/dev/sda1
3592+0 records in
3592+0 records out
3766484992 bytes (3.8 GB) copied, 345.299 s, 10.9 MB/s

3) When the dd command completes there are several additional steps to do with the SATA disk.

Labeling the disk is optional.  If you wish to label the disk you will use the e2label command.

The next step is to generate a new uuid for the SATA disk.  As the data on the SATA disk is just a copy of the sd card it will have the same uuid.  The system will work this way but as uuid’s are supposed to be unique on a system it isn’t good.  The new uuid is set on the drive using the tune2fs command.

root@ubuntu:~# e2label /dev/sda1 System
root@ubuntu:~# tune2fs /dev/sda1 -U `cat /proc/sys/kernel/random/uuid`

4) Set the system to load the root file system form the SATA disk.  This is done by updating uEnv.txt on the sd card.  Using lsblk you will see that the boot partition is mounted on /mediaCDE1-5BFE so using a text editorthe file is updated.

root@ubuntu:~# lsblk
NAME        MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda           8:0    0 931.5G  0 disk
└─sda1        8:1    0 931.5G  0 part
nand         93:0    0   3.6G  0 disk
├─nanda      93:1    0    32M  0 part
├─nandb      93:2    0    16M  0 part
├─nandc      93:3    0    16M  0 part
└─nandd      93:4    0   3.5G  0 part /
mmcblk0     179:0    0   7.4G  0 disk
├─mmcblk0p1 179:1    0    16M  0 part /media/CDE1-5BFE
└─mmcblk0p2 179:2    0   7.4G  0 part /media/7f1334b8-5b94-49a2-aa48-e0d31f19ef9

root$ubuntu:~#: nano /media/CDE1-5BFE/uEnv.txt

The line that needs to be changed is the one that starts with mmc_root.

/dev/mmcblk0p2 –> /dev/sda1

baudrate=115200
boot_nand=fatload mmc 0 0x43000000 script.bin && fatload mmc 0 0x48000000 ${kernel} && bootm 0x48000000
bootcmd=if run loadbootenv; then env import -t ${scriptaddr} ${filesize};fi;run setargs boot_mmc;
bootdelay=3
bootenv=uEnv.txt
console=ttyS0,115200
filesize=4096
kernel=uImage
loadbootenv=fatload mmc 0 $scriptaddr ${bootenv}
loglevel=8
scriptaddr=0x44000000
mmc_root=/dev/mmcblk0p2
recovery_key_value_max=0x13
recovery_key_value_min=0x10
setargs=setenv bootargs console=${console} console=tty1 root=${mmc_root} loglevel=${loglevel} ${panicarg} ${extraargs}

5) Reboot the system and you should boot into the root file system on your SATA drive.

No comments: