In today's tutorial, I am going to explain how you can move the Root partition of our Linux distribution to another partition (whether on the same hard drive or not). This need came to me in the middle of last year, when I was still using Chakra, and since then it is a process that I have used on more than one occasion with satisfactory results and zero problems.
If the steps are followed to the letter, it is a 100% safe, relatively fast and totally reversible operation. We will only need a Live CD of any distro that we have out there (one of Ubuntu, for example, will serve our purpose), and correctly identify which is the source and destination partition.
For such information, we can turn to GParted or the KDE Partition Editor. When we execute them, we will see a window similar to the one in the screenshot below. There, we must look for our original root partition and look at what disk it belongs to (sda, sdb, sdc ...), what number it has (sda2, sdb1, sdj5, etc.) and what is its UUID (an alphanumeric code that you will find in the section of "advanced information"). Obviously, if we are going to move a partition we will need a destination, so we have to previously create a hole in the hard disk to carry out the move, and write down the corresponding data.
Before continuing, I want to state that in this tutorial I only refer to Grub2; if you use another bootloader some steps or commands may vary - in fact, it is much easier with Grub Legacy-. So, with the information from before written down on a piece of paper, we get to work:
1) We start the computer with the Live CD and we wait for the desktop to load.
2) In a terminal we put the following two commands:
sudo mkdir / mnt / old
sudo mkdir / mnt / new
sudo mount / dev / sdaX / mnt / old (where sdaX is the original root partition).
sudo mount / dev / sdbX / mnt / new (where sdbX is the new root partition).
sudo cp -rav / mnt / old / * / mnt / new
sudo cp -rav /mnt/old/.* / mnt / new
sudo umount / mnt / old
sudo mount -o bind / dev / mnt / new / dev
sudo mount -t proc none / mnt / new / proc
sudo chroot / mnt / new / bin / bash
sudo grub-install / dev / sdb (where sdb is the hard drive where we have the new root partition, and we don't have to put a number on it or anything like that).
sudo kate /boot/grub/grub.cfg
- Where you put (hdX, Y), we change the figures of X and Y according to the following:
X: indicates the hard disk number. If the disk is sda, X is equal to 0. If the disk is sdb, X is equal to 1. If the disk is sdc, X is equal to 2, and so on.
Y: indicates the partition number. 1,2,3… Example: second partition of the first disk (hd0,2); second partition of the third disk (hd2,2)… Do you get the idea?
- The second field to modify is the UUID (the code of numbers and letters so long), which still points to the old partition. We change it to the UUID of the new partition (remember that you can check this in GParted, for example). Check the data well!
- The third modification, and one of the most important, is related to the small red rectangle that is under the UUID, and that it says in the image "sdb2". This is where you have to indicate the new partition of your root which, logically, has to correspond to (hdX, Y). Examples: (hd0,1) -> sda1 // (hd2,3) -> sdc3
Keep in mind that these changes, in principle, must be repeated depending on the number of entries of our operating system present in Grub. I have three Chakra entries, therefore I have to change that data 3 times. However, I advise you to change only the first entry and, once you see that everything starts correctly, proceed to modify the rest, from your real operating system.
sudo kate / etc / fstab
9) We can now restart and check that everything is in order. If the operating system works well, we can proceed to replace the data that we left unchanged in the remaining entries of the grub.cfg file, as well as delete the old root partition -if that is our desire-.
That's all for today.
This was looking for XD. thanks
It is a very safe procedure, I have used it many times years ago, and the good thing is that the new / partition will not contain file fragmentation ...
Although not long ago I tried to change the root partition with the variant of also changing the file system (from reiserfs to ext3), but it was impossible for me to do it due to more attempts and turns than I gave, somehow at system startup the detection failed de / due to the fact that it was looking for a reiserfs system / partition when the new one was formatted with ext3. Entering maintenance mode and mounting manually / as ext3 the system worked correctly, but the next start it failed again for the same reason. There was no editing of grub or fstab that worked ... always looking for a / partition with reiserfs, can't find the solution ...
That looks like there was some file pointing to the reiserfs partition. Perhaps an inconspicuous line from the bootloader or something like that, otherwise ext3 should have loaded correctly.
If that's what I thought ... and spent hours looking for something but found nothing ... not even searching the Internet.
Anyway, I cannot assure you that in the past I have done the procedure without problems, it is that 6 or 7 years have passed since I used to do it almost for pleasure ... the last time I tried to do it with Debian Lenny, probably the biggest difference is the kernel, before maybe you used a distro with linux 2.4.x.
Anyway, if you go to find the solution, I hope you share it ...
Good tip, ... if I had known before.
Greetings.
Yes, very good tip, it looks a lot like the procedure to change the disk / home, but I didn't know what it could do with root.
Very good info although I may not use it, it is good to know the flies. 🙂
Yes, with / home it is much easier, because you do not have to reinstall Grub or modify its configuration file. Copying everything you need and editing the fstab is enough.
Well of course we are talking about / home, it is obvious that / root requires more attention.
It's not like / Home, which is generally almost just cut and paste or, failing that, copy and paste.
very good manual, friend, thank you very much, I would like to know if the pdf version or any other can be downloaded from somewhere, greetings
Here you go, fresh from the oven;):
https://sites.google.com/site/rsvnna/baul/Mover%20Root.pdf
thanks friend, this very well
Thanks a lot! I was looking for something similar and what had occurred to me was to make images of the partitions and then restore them but of course, more things were missing such as mount points etc. So it suits me like a glove!
Very good info, it is always useful to have these things on hand just in case. Thanks a lot.
If you are using Grub2, wouldn't it be grub2-install?
Be careful when you make these manuals that you put anyone in a mess as long as you don't put the commands right.
In Arch the old version of grub was renamed to grub-legacy and grub 2 was left as grub only so it is correct but in the same way it is advisable to read the documentation of your distribution before making an important move like this to be sure of the names of packages
and thanks to the author I was looking for the detailed process and this served me well
The couple of commands more than point 5 have not worked for me, better this:
sudo su
mkdir / media / kk (where the root of the installed system is mounted)
mount -t ext4 -o rw / dev / sda / media / kk
mount –bind / proc / media / kk / proc
mount –bind / dev / media / kk / dev
mount –bind / sys / media / kk / sys
chroot / media / kk
update-grub
grub-install / dev / sda (or sdb,…)
Thank you very much it helped me a lot, as an alternative after copying everything to the new partition you can move the grub installation with the boot-repair tool, thus avoiding having to do steps 5 onwards
sudo add-apt-repository ppa: yannubuntu / boot-repair
sudo apt-get update
sudo apt-get install boot-repair
the graphifa application is executed and advanced options are activated; grub location and the new partition is chosen for the grub installation.