How to change the filesystem from "/" and not die trying

Another excellent tutorial that found in the Tutorials section of our Forum, from the hand of Super me

Yesterday I discovered the hard way one of the "Features" file system Btrfs. It is that for reasons that I do not know of its operation, Btrfs tends to fill the disk more than what commands like dd or the disk fill meters of common file managers.

How to know how much space your filesystem is taking up with btrfs

Whoever has a filesystem with Btrfs You will be able to know how much additional space your data is occupying by typing in console (as root I believe):

btrfs filesystem show /

(Replace / with another mount point if you want to know the space occupied in another btrfs partition)

In a large partition this additional filling is not a big problem, since it is very little space compared to the total. But in my case, where / has 22GB (it occupies a ssd cache), my hard disk filled up with 8 GB free, breaking the rpm databases and thus disabling the package manager. So I was forced to format with another file system.

But I didn't want to reinstall. Clearly, the data from / home can be easily preserved, but one has many programs installed in / and many settings that also reside there, so I decided to just keep the installation but change the file system.

The reason I'm writing this is because I didn't find any documentation on how to proceed in these cases. I guess most people settle for reinstalling.

I had to spend about 7 hours searching and searching for information in English manuals that actually had to do with other things and intuitively putting pieces together; trial and error all the time, rebooting dozens of times to see that each thing I tried failed one after the other. When the process in reality would not have been so much of having had a manual dedicated to it.

Considerations to keep in mind to change the file system of "/"

First: I performed this procedure on Fedora. I guess it is the same for all distributions that mainly share having as a bootloader GRUB2.

Second: This process is difficult for the common user (those who read this and think it is bullshit know that you are not common users) People usually have better things to do than change the file system of the root partition. If you do not know how to follow this manual, you run the risk of losing your installation, and if you manage to carry it out, you will discover that the change in performance is not so spectacular (Well, for some it is, but you are not common users) I specifically did it out of necessity , although I must admit that I am one of those who put your computer to start a second faster.

Third: As this procedure is not for ordinary users, I will assume that the reader has some knowledge of GNU / Linux and that he will not be lazy to look for more information.

Procedure to change the file system of "/"

Whether you want to change the file system out of necessity or out of boredom, this is the procedure:

1.- It is obvious that for our new file system to work we have to have the tools to help us manage it, so this is the first thing we will do. The file system I chose by the way, was xfs, so I had to install "Xfsprogs" y "Xfsdump". You will install whatever you want depending on the file system you want to use.

2.- Boot from a livecd / usb and copy the entire contents of the root partition to another partition or disk. The method you choose does not matter, but the thing is to do it with root privileges, so as not to find files or directories with special permissions.

3.- The step where "/" is properly formatted with the file system that we prefer. There are many methods, choose the one you like the most.

4.- The copy we made of the root partition is restored to the newly formatted partition.

5.- It is the moment in which the user has to start doing his part. Formatting the partition modifies an identifier that the operating system uses to know which partition to mount. This is the \ It \ him UUID, and we need to know that code.

There are multiple methods, but for example, in "Gparted", we will know it by right clicking on the new partition "/" and clicking on "Information". We copy that code and that is when we are going to edit the / etc / fstab file:

UUID = 36f3ce91-5138-4293-8571-b5b43f6b4646 / xfs defaults, noatime, discard, nobarrier

This is an example showing the line that corresponds to my brand new root partition. The code that appears to the right of UUID = is what we will replace with our UUID.

Once we have done it, of course we have to indicate the new file system of our partition, xfs in my case or replace it with yours in the case of another file system. You also have to put the new mounting options: If you don't know what to put, put "Defaults"; noatime increases performance by decreasing writes, discard decreases writes to ssd disks, increasing their longevity.

6.- This is where the really fucking starts and that's where I got stuck. It's not really that difficult, but there is almost no documentation from this point on.

We need to rebuild the Grub menu for it to properly start the operating system. I would not know how to do it by hand, you can try as I did (changed UUIDs and such) but the normal thing will be that the start of the OS stops in a pleasant and hopeful "emergency shell"

Fortunately, grub2 owns the tool "Grub2-mkconfig" that automatically performs this task taking as reference the characteristics of the system where it is running. The problem is that, look where, the system where it is running is not the target system, and the latter is temporarily out of service.

So we need to do chroot and mount a series of special partitions to run this tool, without which it will not work. The procedure to do this is poorly explained in almost all places (which does not mean that they do not know how to do it, but that they think that we are computer supercracks)

Luckily here: http://askubuntu.com/questions/28099/ho … ll-kernels I found a hilarious explanation about the subject, which I go on to summarize and translate:

  1. Mount / and / dev:
mount / dev / sda1 / mnt mount --bind / dev / mnt / dev

Where "sda1" is replaced by the one corresponding to the root partition, if it is not "sda1"

  1. Mount / boot and / boot / efi, the latter if we had an EFI partition.
mount / dev / sda2 / mnt / boot

Where "sda2" is replaced by the one corresponding to the boot partition, if it is not "sda2"

The efi assembly does not come in the link above, it is my thing but in this case I needed it. If you don't have an EFI partition, ignore this.

mount / dev / sda3 / mnt / boot / efi

Where "sda3" is replaced by the one corresponding to the boot partition, if it is not "sda3"

  1. Chroot and some other things, that actually the only thing I know about those things is that they are necessary:
chroot / mnt mount -t proc none / proc mount -t sysfs none / sys mount -t devpts none / dev / pts export HOME = / root export LC_ALL = C

This is my addition, it may be needed for one thing later:

mount -t tmpfs tmpfs / run

7.- grub2-mkconfig

Well, it's almost the star moment. We have to look for a file called "grub.cfg" inside the boot partition. In my case its path is /boot/efi/EFI/fedora/grub.cfg

When we have found it, we run in the chroot environment:

grub2-mkconfig -o /path/a/grub.cfg

And we finally have the grub menu ready.

This point according to its author should not be taken into account. Jump straight to point 9

8.- Regenerate the initramfs.

This step I think is necessary, but I am not strictly sure. However, it is enough to reinstall the kernel that we want or to execute:

dracut --force / path / to / file / initramfs / that / we / want / to replace

for example:

dracut --force /boot/initramfs-3.15.9-200.fc20.x86_64.img

Of course, all this within the chroot environment. (and if not, return to the exit box, er ... to the «emergency shell»)

PS: I forgot what to do to access the Internet in the chroot environment, in case you want to reinstall the kernel. The link above explains very well: You have to open a new terminal and copy these files:

cp / mnt / etc / hosts /mnt/etc/hosts.old cp / etc / hosts / mnt / etc / hosts cp /etc/resolv.conf /mnt/etc/resolv.conf

9.- Get internet access:

You just have to copy the following files, graphically or via console, in the latter case outside the chroot environment. It can be done from another terminal or by exiting the chroot environment, and then re-entering.

cp / mnt / etc / hosts /mnt/etc/hosts.old cp / etc / hosts / mnt / etc / hosts cp /etc/resolv.conf /mnt/etc/resolv.conf

10.- Reinstall the kernel:

We reinstall the kernel within the chroot environment with our package manager

11.- RESET AAR:: DD

This point should be the end for "normal" distributions, for distributions with SELinux, as is my case, the thing took a little longer.

Even though the startup went to the end and I tried to start the graphical system, it did not, and when I tried to log in as a user or as root it would say "permission denied".

I read something about it and according to one person the problem could be selinux, and he suggested putting selinux = 0 at the end of a boot line in grub.cfg, like this:

menuentry 'Fedora, with Linux 3.15.9-200.fc20.x86_64' --class fedora --class gnu-linux --class gnu --class os --unrestricted $ menuentry_id_option 'gnulinux-3.15.9-200..fc20 .x86_64-advanced-36f3ce91-5138-4293-8571-b5b43f6b4646 '{load_video set gfxpayload = keep insmod gzio insmod part_gpt insmod ext2 set root =' hd1, gpt2 'if [x $ feature_platform_search_hint = xy]; then search --no-floppy --fs-uuid --set = root --hint-bios = hd1, gpt2 --hint-efi = hd1, gpt2 --hint-baremetal = ahci1, gpt2 1cd04509-ab7c-4074- 8bab-e170c29fe08e else search --no-floppy --fs-uuid --set = root 1cd04509-ab7c-4074-8bab-e170c29fe08e fi linuxefi /vmlinuz-3.15.9-200.fc20.x86_64 root = UUID = 36f3ce91-5138 -4293-8571-b5b43f6b4646 ro rd.md = 0 rd.lvm = 0 rd.dm = 0 vconsole.keymap = en rd.luks = 0 vconsole.font = latarcyrheb-sun16 rhgb quiet selinux = 0 initrdefi /initramfs-3.15.9. 200-20.fc86.x64_XNUMX.img

Look at the penultimate line to the far right.

I did not do it directly, if not I simply edited the boot entry in the grub menu itself, so that it was a temporary modification, I think it was done by pressing «c» or «e», in the grub menu you can do it. places.

Well, we do that and restart, or continue with the boot.

12.- The light at the end of the tunnel.

If we could not directly in the previous step, it is in this penultimate step where we can access our usual desktop. A toast to our great feat, but yes SELinux Has screwed up, we're not done yet

We have to re-edit the grub.cfg to remove the "selinux = 0" or simply reboot normally if what we have done has been to edit the entry in the grub menu. The fact is that we reboot with SELinux activated.

Then at the end of the start something comes out that has to relabel the policy of SELinux targeted, we leave it alone and when finished it will restart.

We will see that our system will start, showing our usual desktop, with SELinux activated, our file system changed and all our fully functional programs.

This is the end of the manual, I hope it helps you big_smile

UPDATE: When I did this for the first time I had no idea and I did the step of regenerating the initramfs and then I reinstalled the kernel and it was all very messy and in the end it worked almost without knowing why, and I gave both options equally as good, however regenerate the initramfs does not work and I have crossed it out. The only thing that works is to reinstall the kernel (I suspect that the kernel and kernel-core packages in Fedora) and thus I have modified the manual.

And I also want to add that to change the format of the file system of the / home partition the same steps are necessary, I don't know if selinux is necessary, but if it doesn't work with selinux it is temporarily removed and that's it.

Featured image taken from here..


21 comments, leave yours

Leave a Comment

Your email address will not be published. Required fields are marked with *

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   anonymous said

    It seems to me that btrfs is a couple of years away from maturing and that when it fails there are tools to recover from the scare without losing data ... ext4 is still the post.
    Regarding handling with chroot, in the gentoo guides you have very well explained:
    https://wiki.gentoo.org/wiki/Handbook:AMD64/Installation/Base/es

    I also use dracut to generate the initramfs since I need the mdadm module for grub2 without which grub2 cannot find the / dev / md0 partition of the / boot.

    They had given me a new 120G SSD disk, but I am reluctant to use it, it is very new and not very mature technology, I do not want to go about reinstalling the system every time a cell in the SSD is corrupted.

    I have installed from scratch in raid 1 on two disks of 1T each, back in April 2012 ... my gentoocyte is about to turn 3 ... hehe

    # genlop -t gentoo-sources | head -n3
    * sys-kernel / gentoo-sources
    Wed Apr 11 23:39:02 2012 >>> sys-kernel / gentoo-sources-3.3.1

    This is the procedure I use to create the initial ram disk, add the bootsplash graphic theme to it
    and regenerate the grub2 inputs.

    # mount / boot
    # dracut –hostonly »3.19.3-gentoo –force
    # splash_geninitramfs –verbose –res 1920 × 1080 –append /boot/initramfs-3.19.3-gentoo.img emerge-world
    # grub-mkconfig -o /boot/grub/grub.cfg

    Thanks for sharing your experience on btrfs.

  2.   Ivan Barra said

    What a friend Elav, great blog entry and thanks to comrade "SuperYO" from the forum. The truth is that something similar has never happened to me, not at all, but it never hurts to have a mega tutorial like this.

    Personally, I do not find BTRFS immature at all, XFS I have not used it, I know that CentOS 7 brings it, but until today, I have not had to mount a new server with it, so at the moment I do not see it as funny to look at it. In OpenSUSE I use BTRFS, but it has not given me any problems at all, not even on SSD disks. What if it has cost me a world to be able to do is an SSD-Cache disk in Unix, it really has been a tremendous problem, the Intel documentation I find it very unclear and complex. in fact I have a topic open in the forum and in other places, but apparently nobody has come across the topic or else, they just leave the SSD-cache disks that laptops bring for something else, suddenly they put them as SWAP so as not to alter system speed, who knows one.

    Perhaps an entry regarding the existing File System types in Unix would be spectacular, putting the advantages of each one, I don't know, another would also be good with respect to SELinux, since so much is said about security, but I read a tutorial in Internet and everywhere they put "SELinux = Disabled", only in "free scope" they give tips on how to allow programs through it.

    Now, I do not go on anymore.

    Thanks for the input and Greetings.

  3.   sinnermann said

    Thanks for the tip, man, but all the characteristics of btrfs have it zfs that to use it in linux the module must be raised in the kernel, but in freebsd it comes by default and does not give a single problem, I recommend it, since btrfs still it has a lot of 'stuff', so to speak.

  4.   Azazel said

    Is it me or notice elav with a very Spanish accent today.

    1.    giskard said

      I noticed it too. Who will know the reason for that.

    2.    elav said

      Hahahaha .. is that the article is not mine .. do not tell me you did not read the first paragraph hahaha.

      1.    Azazel said

        Now that you mention it ... No. I don't even notice.

  5.   Super yo said

    Hi. If you see the forum entry you will see that point 8 is crossed out because it is not valid, what you have to do is reinstall the kernel and I put it that way when I edited it 😛

    What happens is that when I did this for the first time I didn't really know what I was doing and I tried everything so I got confused 😛

  6.   Super yo said

    And I continue, what happens is that my previous comment has not been posted yet 😛

    That is why if nothing can be crossed out on the web, it would be to delete point 8 to confuse the staff. Anyway, the worst thing that can happen by regenerating the initramfs is what I got: absolutely nothing happens, neither good nor bad, which is not that serious either, but it is a useless step.

    1.    Hugo said

      Good article that you have shared, through your experience I have learned some new things 😉
      I bet anything that the sense of victory you felt in achieving your goal far outweighed the setbacks. 😉

  7.   Mario dannan said

    Open source is very feminine: it is not for the eager.
    If one dedicates attention, passion and patience to deepen its charms, it gives us the best of itself.

  8.   weyland yutani said

    What a good post the colleague superYO has scored. This is nice.

  9.   jamin samuel said

    Why XFS instead of ext4 ??

    : )

    1.    brutal said

      Ext4 is getting old when they say ... and to write large data better xfs.

      About the author of the post I never saw the jurnal btrfs fill the / partition
      I wonder is that I think it is because you winters the pc I think, because it has never happened to me! with the distros that I use with a samsung pro ssd and that never happened to me.

      1.    Super yo said

        It is not something that is noticeable on medium or large partitions, but on a 20GB BTRFS partition you can actually fill the root partition with almost half the free space actually.

        And it wasn't the only problem he had. In terms of reading, the disk was more or less correct but the installations and updates were very slow for an ssd disk and a normal hard disk, which was a major annoyance.

        I blame the hybrid unit that I have in the laptop, because in the other places where I have Fedora installed with btrfs I have no problem and it works fast and well, except on my main computer that has a hybrid unit as I have said. Now with both partitions with XFS this computer behaves much better.

  10.   wake up said

    Since when is that 10 minutes with DesdeLinux?, I barely realize it's there o_o

    1.    elav said

      A while ago 😀

  11.   Tiles said

    I think it will be weird, but I was researching this for a long time, I was so lazy that I did not want to cheer myself up. Thanks for the info, I want to pass my / home to xfs and the / to btfrs

  12.   monk said

    Thanks for the article, very interesting.

    Criticism out of content:
    I have mentioned it in other posts and I think that in a blog like this, collaborative, where all kinds of people participate, they should not allow themselves to put images like the one you have put in the header of the post. Not because a girl in a bikini comes out, but because it is used (probably unintentionally) in a sexist way.

    Nobody is criticizing that a girl or a girl in bikini comes out, even naked. If it makes sense, and someone wants to do a post about bodies and the internet, or sexuality and the internet or something like that ... I think it's great.

  13.   Jorge said

    It looks good, but ... Why do you have to reinstall the kernel? I do not understand.

  14.   zjaume said

    The truth is that after having installed Arch a couple of times I already had an idea of ​​where the shots would go, I have been with the new pc with Arch for 1 month and an ssd formatted with ext4, I am thinking of moving to btrfs but It doesn't convince me either because after seeing some performance tests in Phoronix it is not very clear that the performance is better and even so with the arch Wiki I have already fiddled with everything I could to optimize performance