Source: <a href="http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=44177" title="found here">http://www.raspberrypi.org/forums/viewtopic.php?f=29&t=44177</a>
The SD-card on the raspberry is not quite robust. To avoid problems with it, it is possible to move the filesystem to a USB drive. Here are the instructions I used to do this.
Needed:
- SD card (4GB/class 10) is sufficient
- USB stick., I use the Kingston DataTraveler Micro, as it is very small.
First install the image on the SD-card as usual
Insert the USB disk in the Raspberry.
Power-up and log in.
First step: Reformat the USB disk to
Code:
sudo fdisk /dev/sda
Command (m for help): p
Disk /dev/sda: 8022 MB, 8022654976 bytes
94 heads, 14 sectors/track, 11906 cylinders, total 15669248 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: 0x00000000
Device Boot Start End Blocks Id System
/dev/sda1 32 15669247 7834608 b W95 FAT32
Command (m for help): d
Selected partition 1
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-15669247, default 2048):
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-15669247, default 15669247):
Using default value 15669247
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
Code:
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
490560 inodes, 1958652 blocks
97932 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=2009071616
60 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
Then: mount the partition:
Code:
sudo mkdir /mnt/sda1
sudo mount /dev/sda1 /mnt/sda1
Now you can see the disk:
Code:
df -h
Filesystem Size Used Avail Use% Mounted on
rootfs 1.8G 1.4G 247M 86% /
/dev/root 1.8G 1.4G 247M 86% /
devtmpfs 212M 0 212M 0% /dev
tmpfs 44M 228K 44M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 88M 0 88M 0% /run/shm
/dev/mmcblk0p1 56M 19M 38M 34% /boot
/dev/sda1 7.3G 145M 6.8G 3% /mnt/sda1 ## this is the new disk
If needed: install rsync
Code:
sudo apt-get install rsync
And copy all over to the USB disk: (this will take a long time!)
Code:
sudo rsync -axv / /mnt/sda1
Next step: update the boot-parameters to use the USB-stick
Code:
sudo cp /boot/cmdline.txt /boot/cmdline.orig
sudo vi /boot/cmdline.txt
Change root= to /dev/sda1
add rootwait rootdelay=5
It should look like:
Code:
dwc_otg.lpm_enable=0 console=ttyAMA0,115200 kgdboc=ttyAMA0,115200 console=tty1 root=/dev/sda1 rootfstype=ext4 elevator=deadline rootwait rootdelay=5
Also change fstab to have the correct disk:
Code:
proc /proc proc defaults 0 0
/dev/sda1 / ext4 defaults,noatime 0 1 #### Add this line
/dev/mmcblk0p1 /boot vfat defaults 0 2
#/dev/mmcblk0p2 / ext4 defaults,noatime 0 1 #### Comment out this line
# a swapfile is not a swap partition, so no using swapon|off from here on, use dphys-swapfile swap[on|off] for that
Now reboot
To verify: Check with df:
Code:
$ df -h
Filesystem Size Used Avail Use% Mounted on
rootfs <strong>7.4G 1.6G 5.5G 22% / #### Should be the size of the USB drive
/dev/root <strong>7.4G 1.6G 5.5G 22% / #### Should be the size of the USB drive
devtmpfs 235M 0 235M 0% /dev
tmpfs 49M 248K 49M 1% /run
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 98M 0 98M 0% /run/shm
/dev/mmcblk0p1 56M 19M 38M 34% /boot