If you have space for an empty partition, this is fairly simple -- but first, to clarify, run
sudo fdisk /dev/mmcblk0
Then hit p (to print the partition table). You'll get a table like this:
Disk /dev/mmcblk0: 7.4 GiB, 7892631552 bytes, 15415296 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
Disklabel type: dos
Disk identifier: 0x00092fac
Device Boot Start End Sectors Size Id Type
/dev/mmcblk0p1 8192 122879 114688 56M c W95 FAT32 (LBA)
/dev/mmcblk0p2 122880 15415295 15292416 7.3G 83 Linux
This is an 8GB card which does not have any such extra space. You can determine this by comparing the
15415296 sectors with the
End of the last partition, which is 15415295. There are no more free sectors.
However, if you installed Raspbian from an image and never resized the root partition, you would have ~6GB of extra space at the end. In this case, you could add a new partition with n; you want a new primary partition. There is a bit of a gotcha here with pi SD cards, because there's actually 3-4 MB of empty space at the front of the card, and fdisk will assume you want to use that when it asks you for the "First sector" of the new partition ("default 2048" = before the first partition). Don't use that default. Instead, use the "End" sector of the last partition plus one. You can then make the partition as big as you want.
By default the new partition should have type 0x83, "Linux". That's what you want.
Do NOT try and use
fdisk to shrink the current root partition (/dev/mmcblk0p2) if you do not have enough room.
Remember to use w to actually commit the changes, then exit.
sudo mkfs.ext4 /dev/mmcblk0p3
I won't bother indicating
sudo from now on but assume all commands must be run root.
Once that's done, you can copy the contents of a new filesystem in. Raspbian style images (I'll get to Arch below) contain two filesystem partitions, you'd want the second one (if you were installing Raspbian), and there's a clue about how to find that here; related is step #4 here.
There is a possible complication because you need to download the image file onto the pi, so you will need sufficient storage to do so. If you installed Raspbian, have not resized, and all you have is the SD card, you won't have room in the root partition for the image; hopefully the new one is big enough to hold it with ~1GB to spare, because you have to copy out into that.
The Arch case is a lucky one because their image is only ~230 MB. Arch's installation page for the pi also reveals they use one partition in their image, and have you create two and copy things into them. You don't have to do that all that in this case, since you already have a first partition with most of the bits in. So, instead of creating a temporary mount directory and copying into there, just mount the new partition and use it directly:
mount /dev/mmcblk0p3 /mnt/arch
Easiest way to go is to download the image straight into
/mnt/arch. Move it there if you did not. Now:
tar -xzf ArchLinuxARM-rpi-latest.tar.gz
This should put you in
/mnt/arch/boot. Make sure with
rename kernel.img arch.kernel
mv arch.kernel /boot/
That last command deletes everything left over, which you already have in
/boot (note the absolute path,
/boot is not
Before you do the next couple steps, make sure you have Arch's
sshd set up so you can get back in after reboot. It should run by default and it is up to you to determine how to get in. You could simply
cp /etc/ssh/sshd_config /mnt/arch/etc/ssh/sshd_config, and any
~/.ssh directories as appropriate.1 That will probably ensure everything works the same way it did with Raspbian. Moving on...
/boot/config.txt. Find the
kernel= line; if it doesn't exist, create it:
dwc_otg.lpm_enable=0 console=tty1 root=/dev/mmcblk0p2 rootfstype=ext4 rootwait
Yours may be more or less elaborate than this, but it will have the
root= field. Change that to
/dev/mmcblk0p3, i.e., the Arch partition.
reboot & exit
Wait a minute, then cross your fingers and try to ssh to the pi again.
1. This doesn't cover passwords; according to the Arch wiki the default root password is 'root'. Note there is no pre-existing user
pi account on Arch.