Moving the filesystem root to a different partition and booting from it
My primary drive is partitioned basically like so (only roughly to scale):
/ /home junk
v v v
|xx############################################*************xxx
^ ^
/boot/efi swap
Motivation
The "junk" space is in fact separately partitioned and formatted - it's left over from a failed attempt to set up dual boot with Windows, but I no longer have any interest in that. I don't care about anything written on these partitions and would be happy to wipe and reformat them and reuse the space.
The problem is that the partition where /
is mounted is far too small for my needs. When I initially set up Linux, I followed old advice with unrealistic expectations about the "system" partition size (and allocated a larger swap partition than I really need). Essentially: I want to be able to install more apps, run the distro's OS update rather than reinstalling for new versions, and not worry so much about maintenance tasks like apt
cache cleanup or journalctl
vacuuming.
So I want the OS to be on a larger partition, and fortunately I have tons of room to work with. But I don't want to move or otherwise disrupt the /home
partition for this, first off because it's hundreds of GB and second because I don't want to risk needing to reach for a backup for all my commonly used data.
I've come up with a plan where I won't have to touch the /home
partition at all. I might expand it into the "junk" space in the future, but I definitely don't want to move it. I might also try using that space to install separate Linux distros side by side - haven't decided yet.
My current plan is to:
- Back up everything anyway
- From a live boot, use Gparted to, in order:
- scrub the junk partitions
- expand the current swap partition to the size I want, and format it as
ext4
- copy and paste the
/
partition to the former swap partition
- Set up the system so that it (will|can) boot from the new
/
- Reboot from the new partition
- Use Gparted again to wipe the old
/
partition and designate it as swap space, and start using it
My primary question is about the boot setup step. How can I reconfigure the system so that it will boot assuming that /
is mounted on the new partition, and ignoring the contents of the old partition?
Aside from that, I want to make sure that I'm managing the swap space in a valid way. I don't want to erase the old partition until I've confirmed I can boot from the new one, of course. Will Linux complain if I try to boot the system without either a swap partition or a swap file, even if there's plenty of RAM for basic tasks? (I.e. will I need to create a temporary swap file?) I know I can swapon
the new swap partition for that boot once everything else is working, but how do I make it permanent? Finally, with my current plan, can I avoid the need to start with a live boot, if I swapoff
first?
If it matters, the OS is Linux Mint 20.3 (Ubuntu 20.04) running Cinnamon.
1 answer
Disclaimer: I'm not a Mint (or Ubuntu) user.
Using your distro's live image:
- Do your partition stuff
- Mount the new root to the live system at
/mnt
[1] - Mount your other partitions to the new root as they should be
- Chroot into
/mnt
- Check your
/etc/fstab
, there should be an entry about mounting your root. Update it to mount the new root partition.[2] - Update your initramfs image(s), perhaps with
update-initramfs
? - Run your distro's boot configuration scripts. Perhaps it's
update-grub
for you? There are some moving parts in this step. MBR/EFI? Which bootloader? -
exit
the chroot - Unmount everything with
umount --all
- Reboot and see if it works
- If it didn't, study the linux boot process in more detail. There are good articles on Wikipedia and ArchWiki.
Swap
Yeah it's probably best to decommission the current swap before everything. Your system will work fine without it too.
Personally I'd recommend just dropping the swap partition, and making a new swapfile when the other stuff is done. Swapfiles are just more flexible.
0 comment threads