How to convert home partition from xfs to ext4

Hello,

I have a separate partition for my /home directory that I need to convert from xfs to ext4. I would like to be able to do this without having to reformat the disks on my machine. I have never done this before so I’m trying to determine the best plan of action.

I’ve found various ways online to mess around with partitions using the Yast ‘expert partitioner’ (opensuse specific - this seems like it’s useful for installing openSUSE), gparted, and a plethora of linux tools. I’m not sure what the pros/cons are of these or what my steps should be. From my short research into this problem, converting my /home partition will probably look like the following:

  1. Resize the xfs /home partition to make room for a new one
  2. Create an empty ext4 partition
  3. Move/copy contents of xfs /home to some temporary location (where?)
  4. Mount/unmount the xfs and ext4 partitions and adjust the /etc/fstab file accordingly
  5. Copy data from temp location to new /home directory

Can someone more experienced comment on this?

I do not quite understand what you mean with " without having to reformat the disks". The word formatting is often (by MS Windows oriented people) used for creating a file system (on a container like a partition). But when you want to use a new ext4 file system, you have to create (format) it, else there is nothing.

Formatting is in fact the writing of tracks/blocks on a virgin disk. This is normally done by the manufacturer. Those people that call file system creation “formatting”, often call this “low level formatting” to have a difference. :frowning: I doubt you mean this type of formatting.

And about your numbered list, IMHO this shows a bit of two ways to go.

I would say that you should have a piece of mass storage large enough to copy all of /home to. (In fact you should already have such a thing, because you make backups. Or not???)

All what follows is to be done from the console, nobody loged in in the GUI. Log in in the console with root. The idea is that no normal user is active and thus /home is not in use at all. The steps are then:

  1. copy all in /home to another device;
umount /home

and remove the entry from /etc/fstab;

  1. use YaST > System > Partitioner (using
yast

will give you the ncurses interface) create a ext4 file system on the partion (YaST also uses the word “formatting”, sorry) AND BE SURE YOU DO IT ON THE CORRECT PARTITION. In the same screens filling in that it should be mounted on /home and that it should be mounted now and on boot. YaST will then create the new entry in /etc/fstab for you;

  1. copy all back to /home;
  2. Done.

For the copy, you can use e.g. tar, but also cp has enough possibilities. Take care you use options that preserve ownership/permissions of the copied files. Want more advice? Please ask.

Thanks for reply,

Sorry for the ambiguous word choice - by ‘without having the reformat the disks’ I meant reinstall Tumbleweed and reformat the partitions as new, (i.e delete all data and do a fresh install). If I could shuffle my data around by using backups to achieve the same result that would save a bunch of time.

By ‘correct partition’ do you mean the current partition UUID or the associated /dev/sd*? I’m assuming the UUID gets replaced…

Also, should all the copying of data back to /home after remounting the new drive also be done as root or as my user? As far as my system is concerned, am I correct in thinking everything about my user remains the same (i.e UID, group permissions)?

I’d recommend what you described here but can be modified optionally as follows… If you can excuse my not describing in detail the overall steps as you’ve described…

When you say “create an empty ext4 partition” you should understand that is actually at least two separate steps…

  • Create a partition (there is no such thing as an ext4 partition)
  • Format the space within your new partition as EXT4

The mount/unmounting can be done by YaST partitioner.
In fact, it seems to me that you should be able to do everything you describe except copying data in the YaST module “Partitioner” in which case when you mount/unmount you simply point your /home to your new partition.

Although probably not necessary in your case because you’re not making changes to your root partition, my personal preference is to use Gparted Live to do my partitioning and formatting actions, then copy the data (don’t move so you always have the old partition to fall back if you make a mistake), then use the YaST Partitioner to re-point /home.

No matter how it’s done,
After you’ve successfully pointed /home to your EXT4 partition, you can remove the old XFS partition and expand your EXT4 partition if you wish (or leave as is for any possible future operations).

TSU

That is indeed possible.

The UUID is that of the file system, NOT of the partition (well associated because the file system is on that partition)! So use /dev/sdXN, (but the correct one, else you might destroy another file system).
When using YaST to create the ext4 and organise the mounting, you can specify there that you want it again mounted by UUID (I assume that will be the default), but it will be another UUID because it is another file system.

Of course all this all is only done as root. Your user(s) has/have no saying or any task in this.

The UIS/GID and permissions should be kept as they are when you use the correct way to copy.

I would use

cd /home
tar cvf <file-on-another-device>.tar *

and to copy back

cd /home
tar xvf <file-on-another-device>.tar

I hope you understand where my scenario differs from yours.

You first want to shrink your xfs and create the ext2 alongside it. Then, nevertheless that you have then source and destination available, you copy the contents to a third place, just to copy it then to the ext4.

So when you have a third place, why not my scenario. First copy to the third place. Then replace the xfs in situ with the ext4 and then copy back. No need for shrinking (always tricky IMHO) and after that possibly enlarging (at the front side?) of the new one.
BTW whenever you are asking about things like partitioning, always add at least an

fdisk -l

to your post. Then people are much more sure about what they are talking. I has to make several assumptions now. I hope they were correct. :wink:

Another hint. When you want to be very sure there is no GUI login from anybody during the action, boot in run level 3 (or change to run level 3 from the console).

Did not know you could shrink XFS :open_mouth:

I have no idea, but there is no need for it in this case.

According to the docs you can’t / couldn’t.

In addition:

  1. Backup /home to some external disk
  2. Use Yast to format /home to ext4, parition needs to be unmounted, so preferably in runlevel 3 ( add 3 to the linux boot parameters, just after ‘showopts’ )
  3. Restore the content of the /home backup
  4. Reboot
    and you should be fine

Do not, repeat do not, use any fs converters without having a backup of /home. Most of the times you’re going to need it anyway

Hi everyone,

Thanks for all the replies. I also learned that XFS is unshrinkable, so I ended up using the yast partitioner as root to delete the XFS partition and reformat the space as ext4.

Many thanks!