For my Raspberry Pi on my workbench I have a large SD card with NOOBS installed. This gives me the ability to switch between different operating systems without any trouble. But I recently finished a project and had to move the OS from the NOOBS SD to a permanent home on a smaller SD card. Basically, I needed to move the OS created by NOOBS to a new SD card. I did find some instructions in the forums but there are a few extra steps for Arch Linux to make the process smooth. BTW – all these commands need to be run as a superuser.
1. To start, trim out any extra packages you may have installed but do not need. This can be a pain so I focused on the biggest packages. Ironically, I had to installed the expac package (pacman -S expac) to list the packages by size. This command with list all packages with no dependencies and their sizes. It excludes the packages in the base and base-devel groups.
expac -HM "%011m\t%-20n\t%10d" $( comm -23 <(pacman -Qqen|sort) <(pacman -Qqg base base-devel|sort) ) | sort -n
2. Pacman keeps a copy of every package downloaded in a cache. If your Arch Linux Raspberry Pi was installed a while ago, the pacman cache may be getting large with older versions. When your install is stable, you can erase the old, no-longer needed packages from the cache with this command:
pacman -Sc
On my system, these two steps freed almost 1GB.
3. I put the new, smaller SD card in a card-reader in the USB port. It needs to be formatted with two partitions. The first needs to be the same size as the boot partition and the second should be the rest of the disk. Find the NOOBS boot partition in the /boot/cmdline.txt file (root=/dev/mmcblk0p5 in my case) and then get the size in sectors with the fdisk command. Create the sectors on the new card and exit fdisk. For reference, my boot partition had 204801 sectors. Your new SD card should now have two partitions (/dev/sda1 & /dev/sda2 for me).
4. Copy the existing boot sector to the new card with dd. This make a byte for byte copy include the file system.
dd if=/dev/mmcblk0p(whatever /boot is) of=/dev/sda1 (the first partition on the new card)
5. I am assuming that the second partition is a different size from the original so a different copy method is required. Create a file system on the second partition.
mkfs -t ext4 /dev/sda2
6. Mount the new partition so it can be used. Assumes the /mnt/sda2 directory exists. Create if required.
mount -t ext4 /dev/sda2 /mnt/sda2
7. Use rsync to copy the main filesystem to the new partition
rsync -ax --progress / /mnt/sda2
8. Update fstab on the new partition and change /boot to point to /dev/mmcblk0p1
nano /mnt/sda2/etc/fstab
9. Unmount
umount /mnt/sda2
10. Mount the new boot partition. Assumes the /mnt/sda1 directory exists. Create if required.
mount -t vfat /dev/sda1 /mnt/sda1
11. Update cmdline.txt change root= to root=/dev/mmcblk0p2
nano /mnt/sda1/cmdline.txt
12. Unmount
umount /mnt/sda1
13. Remove card from card reader, power down the Pi, remove the NOOBS card, insert the new card and reboot. The systems should start right up into the Arch OS.