Step 1: Theory
- SD or USB ? Which specifications ? Let's gor for SD class 4, even though...
Jamesh tests on an alpha board show that SD performance is bad compared to USB (thread here: http://www.raspberrypi.org/for.....38;t=499.0
Even though the conclusion is that USB sticks are faster the SD cards, we'll still choose the sdcard: things may get better in the final Pi; adapting SD tweaks for Flash is fairly trivial (everything that works for SD also applies for USB); we need the USB ports for other things; SD cards are more protected (inside the Pi); and finally since everything connected to the USB or Ethernet competes for bandwidth, better segregate as much as we can away from the USB interface.
SD cards are available in different "classes" of speed. There seem to be compatibility issues with faster cards, so going for slowpoke class 4 cards seems the best choice at the moment. All tweaks work regardless of class/speed anyway.
- Choosing the right format and filesystem: ext4 > ext2, avoid others.
There are a number of flash-optimized formats and filesystems, but these are targetted at straight flash ram that has no controller. SD cards and USB sticks always include a controller, and are designed for use with regular formats/filesystems. In the Linux world, we can safely use the mainstays: ext 2/3/4 or the upcoming btrfs. I could not find much info on the still-somewhat-new btrfs for flash, and ext3 is really an intermediate step between 2 and 4, so we can rule those 2 out. The main advantage of ext2 over ext4 is that it does not offer journalling at all. ext4 can turn off journalling, and offers a number of small extras over ext2, let's choose ext4, though ext2 would be OK, too.
- how bad are FAT and NTFS ? Pretty bad, avoid if possible
It would be nice to use FAT (FAT32, exFAT) or NTFS as much as possible on the Pi, especially since while Linux can read/write those, Windows can't really access ext partitions. Alas, these are non-native formats for Linux, inherently less speedy and reliable. Plus, optimizing them on Linux for flash use is undocumented, so we have to avoid them. The recommendation for easy data exchange with Windows is to have a separate USB stick, or at least a separate partition, and copy data to/from that as needed.
I've had very limited success with the ext2fsd ext driver for Windows (http://www.ubuntugeek.com/how-.....ows-7.html
) use carefully and with backups ^^
Step 2: Prepare a Boot SD
IMPORTANT: You need working Pi boot files in a separate location to copy onto the SD once it has been formatted.
Small logistics problem here: we need to format the SD card, but can't format the one we're running the Pi from. Solutions
- use another Linux PC
- boot the Pi off a USB stick (if that's possible) so the SD card can be messed with
- connect an SD card reader to you Pi and use a second SD card.
- swap or no swap ?
Since the Pi doesn't have much RAM, I'm going to assume a swap partition is needed. Probably 128, 256 or 512 MB, it really depends of what software you're running and your usage patterns. Let's go for 256 MB.
- Create partitions aligned on Flash blocks
TBD: tool to confirm flash block size. Assuming 128K.
Issue: hard to describe precisely without a real Pi (drive letters, fdisk options)
unfinalized odds and ends:
- Format partitions with journalling disabled
This cannot be done on the system drive, so let's do it while we're booting off another drive, at the same time we're formatting it:
sudo mkfs.ext4 -O ^has_journal -L PiBoot /dev/sdx1
sudo fsck.ext4 -f /dev/sdx1
Step 3: Optimize your boot SD
At this point, copy the boot files to the SD, put it in the internal SD slot, disconnect all other mass storage for safety, and reboot.
- Disable superfluous writes access time
by default, inux keeps track of the last time a file has been read, which genererates a disk write for every file read. We want to disable that for all drives:
Open the hard drive config file with
sudo nano /etc/fstab
Add the noatime (no access time), no diratime (same for directories instead of files) and data=writeback options after the defaults parameters for each drive, except swap. Modified line should read something like:
/dev/sda2 / ext4 defaults,data=writeback,noatime,nodiratime 0 0
Do that for each drive, save, and remount your drives with
mount -o remount /
NOTE: the data=writeback option means than when you save/update a file, the OS will take a few seconds to update the directory to point to the new file. If your computer crashes/stops in the mean time, you'll lose your changes.
- Change the disk scheduler http://www.redhat.com/magazine.....chedulers/
add block/sda/queue/scheduler = noop to your /etc/sysfs.conf (requires the sysutils package) or elevator=noop to the kernel boot parameters in your /etc/default/grub
-Reduce swappiness http://community.linuxmint.com.....l/view/293
Reduce swappiness to make the operating system avoid the use of the swap area and prefer to use the memory modules instead. Open your /etc/sysctl.conf file with the gedit text editor, make a new line at the bottom of the file and add this:
- disable/relocate to RAM transient logs and variables
NOTE: This eats up a lot of RAM. It s not recommended for the Model A, nor for the model B if your apps use up a lot of RAM. It is best for a "server" model B with no X11.
Avoid logical volumes: hard to control alignment.