Recently, I moved an Arch Linux installation to another drive that was smaller than the original drive.
The original drive used only one partition which simplified things. If you have a boot partition separate from the root partition, here's an answer that might help you.
The steps were:
- Back up the data.
- Create a partition containing an ext4 filesystem on the target drive.
- Copy all data from the source partition to the target partition.
- Install GRUB as the bootloader on the target drive.
A hint before we start: To determine the paths of my connected devices (e.g.
/dev/sdb) and generally keep an eye on the state of devices as well as partitions, I use
watch combined with
watch lsblk -o tran,name,model,fstype,label,mountpoints,fssize,fsavail,fsused,fsuse%
It updates every two seconds and produces output like this:
TRAN NAME MODEL FSTYPE LABEL MOUNTPOINTS FSSIZE FSAVAIL FSUSED FSUSE%
sata sda SanDisk SSD PLUS 1000GB
├─sda1 ext4 VM partition /sda1 108G 50G 53.4G 49%
└─sda3 ext4 / 808G 561.3G 205.7G 25%
usb sdb SABRENT
└─sdb1 ext4 new_daedalus /run/media/me/new_daedalus 29.2G 25.3G 2.4G 8%
sata sr0 MATSHITADVD-RAM UJ8A2
Since we're going to copy the contents of one partition to another, it's a good idea to get rid of cruft that takes up lots of space: Check the source partition with
ncdu for directories that contain the most data and delete or move them if possible.
Another thing: I use SATA to USB adapters such as these to connect source and target drives to my computer.
Assuming you've backed up your data and your target drive is at
/dev/sdb, let's go into detail:
Create a partition containing an ext4 filesystem on the target drive:
Copy all data from the source partition to the target partition:
- The following assumes both your old and new partition are mounted:
sudo rsync -a --hard-links --delete --progress --human-readable --stats /run/media/me/old_partition/ /run/media/me/new_partition/
- I used
rsync here. You could also use good old
cp to achieve the same:
sudo cp --recursive -a /run/media/me/old_partition/* /run/media/me/new_partition/
Install GRUB as the bootloader on the target drive:
- Add the virtual file systems to your new partition which are needed to run
sudo mount --bind /dev /run/media/me/new_partition/dev; sudo mount --bind /proc /run/media/me/new_partition/proc
- Make the root of your new partition the current root:
sudo chroot /run/media/me/new_partition/
- Install GRUB on the target drive (see this for more on what happens here):
grub-install /dev/sdb; grub-mkconfig -o /boot/grub/grub.cfg
chroot with Ctrl+d or
- Unmount virtual file systems and the partition itself:
sudo umount --recursive /run/media/me/new_partition
That's it, you should now be able to use your Linux install on
new_partition residing on the drive