Sunday, July 15, 2012

Using USB storage on Raspberry Pi

Assuming the USB storage is on /dev/sda

To mount a USB stick / disk and make it writable for the default login pi

/usr/bin/sudo /bin/mount -t vfat -o uid=pi,gid=pi /dev/sda /mnt/usb/


To create a 512M file on the USB storage and use it as swap:

# create an empty swapfile
/bin/dd if=/dev/zero of=/mnt/usb/swapfile bs=1M count=512
# create a loop device
/usr/bin/sudo /sbin/losetup /dev/loop0 /mnt/usb/swapfile
# setup swap area
/usr/bin/sudo /sbin/mkswap /dev/loop0
# enable the swap
/usr/bin/sudo /sbin/swapon /dev/loop0


To remove the swap:

# disable swap
/usr/bin/sudo /sbin/swapoff /dev/loop0
# delete loop
/usr/bin/sudo /sbin/losetup -d /dev/loop0


Umount the USB storage:

/usr/bin/sudo /bin/umount /mnt/usb/