SDCard Tuning

SDCard Tuning
speed up our SDCard

prerequisite: shell knowledge, linux pc with sdcard reader
reference: http://linux-howto-guide.blogspot.com/2009/10/increase-usb-flash-drive-write-speed.html
http://www.patriotmemory.com/forums/showthread.php?3696-HOWTO-Increase-write-speed-by-aligning-FAT32
http://www.olpcnews.com/forum/index.php?topic=4993.0


Quite hard to understand, but changing the partition alignment of the SDCard can highly improve the write speed of our sdcard. Basically we have to align the first partition to the erase block size of our sdcard. I suggest to read an reread the reference link.
To do that in our sdcard that contain our RaspberryPI Debian distro we have to:
backup our filesystem from linux:
cd /media/mymmcblk0p2/ (the partitition that’s contain debian fs)
tar -cvpzf /home/gibbio/RPI-TC_fs.tgz --exclude=./proc --exclude=./lost+found --exclude=./sys --exclude=./mnt --exclude=./media --exclude=./dev ./
cd /media/mymmcblk0p1/ (the partitition that’s contain boot kernel etc)
tar -cvpzf /home/gibbio/RPI-TC_boot.tgz ./
Now use printcsd.py to find the erase block size, most sd have 128K so we use 128K/Sector size = 256 sectors (mine have 64k so we have to use 64k/512b = 128 sector alignement)

sfdisk -f -H224 -S56 /dev/mmcblk0
Checking that no-one is using this disk right now ...
OK
Disk /dev/mmcblk0: 244448 cylinders, 224 heads, 56 sectors/track
Old situation:
Units = cylinders of 6422528 bytes, blocks of 1024 bytes, counting from 0
  Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1          0       -       0          0    0  Empty
/dev/mmcblk0p2          0       -       0          0    0  Empty
/dev/mmcblk0p3          0       -       0          0    0  Empty
/dev/mmcblk0p4          0       -       0          0    0  Empty
Input in the following format; absent fields get a default value.
<start> <size> <type [E,S,L,X,hex]> <bootable [-,*]> <c,h,s> <c,h,s>
Usually you only need to specify <start> and <size> (and perhaps <type>).
/dev/mmcblk0p1 :,8,c
/dev/mmcblk0p1          0+      7       8-      50175+   c  W95 FAT32 (LBA)
(enter enter)
/dev/mmcblk0p2 :
/dev/mmcblk0p2          8    1246    1239    7771008   83  Linux
/dev/mmcblk0p3 :
/dev/mmcblk0p3          0       -       0          0    0  Empty
/dev/mmcblk0p4 :
/dev/mmcblk0p4          0       -       0          0    0  Empty
New situation:
Units = cylinders of 6422528 bytes, blocks of 1024 bytes, counting from 0
  Device Boot Start     End   #cyls    #blocks   Id  System
/dev/mmcblk0p1          0+      7       8-     50175+   c  W95 FAT32 (LBA)
/dev/mmcblk0p2          8    1246    1239    7771008   83  Linux
/dev/mmcblk0p3          0       -       0          0    0  Empty
/dev/mmcblk0p4          0       -       0          0    0  Empty
Warning: no primary partition is marked bootable (active)
This does not matter for LILO, but the DOS MBR will not boot this disk.
Do you want to write this to disk? [ynq] y
Successfully wrote the new partition table
Re-reading the partition table ...
If you created or changed a DOS partition, /dev/foo7, say, then use dd(1)
to zero the first 512 bytes:  dd if=/dev/zero of=/dev/foo7 bs=512 count=1
(See fdisk(8).)

gibbio # fdisk -l...
Disk /dev/mmcblk0: 8010 MB, 8010072064 bytes
224 heads, 56 sectors/track, 1247 cylinders, total 15644672 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: 0x000ee283
       Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      100351       50175+   c  W95 FAT32 (LBA)
/dev/mmcblk0p2          100352    15642367     7771008   83  Linux

now create ext4 FS:
mke2fs -t ext4 -E stripe-width=32 -m 0 /dev/mmcblk0p2
make FAT32 partition via gparted
gibbio # fdisk /dev/mmcblk0
Command (m for help): p
Disk /dev/mmcblk0: 8010 MB, 8010072064 bytes
224 heads, 56 sectors/track, 1247 cylinders, total 15644672 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: 0x000ee283
       Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1               1      100351       50175+   c  W95 FAT32 (LBA)
/dev/mmcblk0p2          100352    15642367     7771008   83  Linux
Command (m for help): x
Expert command (m for help): p
Disk /dev/mmcblk0: 224 heads, 56 sectors, 1247 cylinders
Nr AF  Hd Sec  Cyl  Hd Sec  Cyl     Start      Size ID
1 00   0   2    0 223  56    7          1     100351 0c
2 00   0   1    8 223  56 1023     100352   15542016 83
3 00   0   0    0   0   0    0          0          0 00
4 00   0   0    0   0   0    0          0          0 00
Expert command (m for help): b
Partition number (1-4): 1
New beginning of data (1-100351, default 1): 128
Expert command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Now eject the sdcard, reinsert and make the restore from the tgz:
cd /media/mymmcblk0p2/
tar -xvpzf RPI-TC_fs.tgz -C ./
mkdir proc mnt sys boot dev
umount /media/mymmcblk0p2/
cd /media/mymmcblk0p1/
tar -xvpzf RPI-TC_boot.tgz -C ./
umount /media/mymmcblk0p1/

Eject the sdcard, plug into our Raspberry Pi and power on!

3 comments:

  1. Or just use gparted in Ubuntu for example it's much more easier ;-)

    ReplyDelete
  2. Or just use Windows, which is even easier, but thats not the point. The point is to know what are you doing and, most important, why. If you really understand this guide, you can use any partition software to do the same, in any distro, included gparted.

    ReplyDelete

Note: Only a member of this blog may post a comment.