Skip to navigation

Set up Raspbian on a SATA hard disk

Installing Linux on a SATA hard disk will allow Linux to run faster, and increase the amount of storage on your system.  I powered my SATA disk using a separate power supply (I don't have a cable that matches the Banana Pi's SATA power socket). 

Set up Raspbian on an SD card as described in this post on /set-up-linux.html setting up Linux on a Banana Pi, but don't install updates.  Connect your disk to the Banana Pi's SATA socket, but don't power up the disk.  

Open a terminal and run this command to display new messages in one of Linux's log files:

tail -f /var/log/messages

Power up the SATA disk, and look for the new drive in the messages in the terminal.  If the drive is auto-mounted when you connect it, unmount it.

Partition the disk

Use this command to start the fdisk partitioning tool:

sudo fdisk /dev/sda

Type 'p' to list all the partitions on the disk:

Command (m for help): p

Disk /dev/sda: 100.0 GB, 100030242816 bytes
255 heads, 63 sectors/track, 12161 cylinders, total 195371568 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x99b699b6

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1              63       96389       48163+  de  Dell Utility
/dev/sda2   *       96390   102494699    51199155    7  HPFS/NTFS/exFAT
/dev/sda3       102494700   195366464    46435882+   5  Extended
/dev/sda5       102494763   183639014    40572126   83  Linux
/dev/sda6       183639078   195366464     5863693+  82  Linux swap / Solaris

Remove existing partitions

I'm going to delete all of these partitions, and replace them with one partition that fills the entire disk.  Press 'd' to delete a partition, and then enter the number of the partition to be deleted:

Command (m for help): d
Partition number (1-6): 1

Command (m for help): d
Partition number (1-6): 2

Command (m for help): d
Partition number (1-6): 3

Write the changes to the disk

None of the changes made so far have been written to the disk.  We can do this by typing 'w' at the prompt:

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

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

Fdisk will automatically quit.  Restart fdisk so that you can create a partition, and type 'n' to create a new partition.  When prompted for the type, press 'p' for primary, and enter '1' for the partition number.  Just press return to use the default values when prompted to enter the first and last sectors.

sudo fdisk /dev/sda

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): 1
First sector (2048-195371567, default 2048): 
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-195371567, default 195371567): 
Using default value 195371567

Type 'w' to write the changes to the disk again.  

Format the partition

Next, format the new partition with the ext4 filesystem:

sudo mke2fs -t ext4 -L rootfs /dev/sda1
mke2fs 1.42.5 (29-Jul-2012)
Filesystem label=rootfs
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
6111232 inodes, 24421190 blocks
1221059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
746 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks: 
    32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
    4096000, 7962624, 11239424, 20480000, 23887872

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done   

Copy the data

Mount the partition, and use rsync to copy the contents of the SD card's root directory to the SATA disk.

sudo mount /dev/sda1 /media
sudo rsync -ax / /media

Adjust boot parameters to use the new disk

The last step is to edit a file on the SD card's boot partition which contains boot parameters.  The file is /boot/uEnv.txt (on the Raspberry Pi the equivalent file is /boot/cmdline.txt).  It contains a variable called 'root', and it needs to be adjusted to point to the new partition, /dev/sda1:

sudo nano /boot/uEnv.txt

The file should look like this once you've made the changes:

bootargs=console=ttyS0,115200 console=tty0 disp.screen0_output_mode=EDID:1280x720p50 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait
aload_script=fatload mmc 0 0x43000000 bananapi/script.bin;
aload_kernel=fatload mmc 0 0x48000000 bananapi/uImage; bootm 0x48000000;
uenvcmd=run aload_script aload_kernel

Finally, restart your server.  When it starts up again, it should use the hard disk as the root file system.  

Share this page:

comments powered by Disqus