LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE
User Name
Password
SUSE / openSUSE This Forum is for the discussion of Suse Linux.

Notices


Reply
  Search this Thread
Old 12-09-2023, 07:45 AM   #1
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499
Blog Entries: 2

Rep: Reputation: 68
Question how to properly move the contents of /home on an ext4 to a btrfs home subvolume ?


Hi there !

I've installed opensuse TW years ago on my laptop. At that time it had a 120G SSD and a 1T HDD, with dual boot. As one can expect, there was no much room for user files for 2 systems in 120GB, so I split the installation between the 2 disks, telling to the installer to put home and swap on the slower HDD:

Code:
lsblk -e 7 -o +PARTLABEL -o +FSTYPE
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINTS            FSTYPE
sda      8:0    0 931.5G  0 disk                        
├─sda1   8:1    0 427.7G  0 part /var                   btrfs
│                                /usr/local             
│                                /tmp                   
│                                /srv                   
│                                /root                  
│                                /boot/grub2/i386-pc    
│                                /opt                   
│                                /mnt/btrfs             
│                                /boot/grub2/x86_64-efi 
│                                /                      
└─sda3   8:3    0  72.7G  0 part                        ntfs
sdb      8:16   0 698.6G  0 disk                        
├─sdb1   8:17   0  39.2M  0 part                        vfat
├─sdb3   8:19   0 343.4G  0 part                        ntfs
├─sdb4   8:20   0     1K  0 part                        
├─sdb5   8:21   0 341.3G  0 part /home                  ext4
└─sdb6   8:22   0  13.7G  0 part [SWAP]                 swap
Now, I got a new 1T SDD, and used dd to move the whole 120G disk content to the new 1T SSD disk. After that, I resized the root partition on new SSD and everything is working as intended. I fact, I am posting this from the laptop with the new disk already. There is around 400G unallocated space on sda.

The question is: How to create/move the /home ext4 from sdb5 to sda as btrfs ? The unknown for me is what is the proper way to create a home folder/subvolume in btrfs and get the UUID to add it to fstab.

thanks in advance,
 
Old 12-09-2023, 05:35 PM   #2
wpeckham
LQ Guru
 
Registered: Apr 2010
Location: Continental USA
Distribution: Debian, Ubuntu, RedHat, DSL, Puppy, CentOS, Knoppix, Mint-DE, Sparky, VSIDO, tinycore, Q4OS,Manjaro
Posts: 5,654

Rep: Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708Reputation: 2708
I would do it this way:
1. IF you can, log in as root. Using sudo will NOT be sufficient.
1.a IF AND ONLY IF you cannot log in as root, create a new user <username> with home folder in /usr/<username> rather than /home/<username> where <username> is replaced by your temp user. Give them sudo rights to become root. Then log off and log in as <username> and sudo su to become root and free up /home.

2. As root, unmount /home, rename it as /oldhome, fix up /etc/fstab to replace /home with /oldhome, and mount /oldhome
3. Create the subvolume /home.
4. update /etc/fstab to mount the new subvolume properly.
5. Reboot and make sure that everything mounts properly on startup. IF it is broken then you have this time to fix your /etc/fstab as the temp user and as root using sudo.
6. Once startup is verified, you need to move the old home data into the subvolume. There are a couple of possible ways: rsync or tar.
Tar:
Code:
#cd /oldhome
#tar -cf * | ( cd /home && tar -xf - )
rsync:
Code:
rsync -af /oldhome/* /home/
DISCLAIMER: these are untested -off the cuff from memory- commands. Run a small test with unimportant data first to make sure I got this right!

Expect either command to take time. How much will depend upon the volume data, your controller channels, speed of storage, and how much ram you have for buffers.

After the copy is done you can log out and log in as your normal user and make sure everything works properly from the new home. If it does that is great, if not you get this opportunity to troubleshoot wile your data is not scrubbed.

7. MUCH later, you can delete the data in /oldhome and unmount that filesystem so you can return that storage to available for other purposes.

The man pages document the command, but web pages like https://fedoramagazine.org/working-w...fs-subvolumes/ may help provide context, examples, and detail.

Last edited by wpeckham; 12-09-2023 at 06:07 PM.
 
Old 12-10-2023, 02:34 AM   #3
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
My main question is how to proper create a subvolume that will integrate seamlessly in the current structure of subvolumes on sda !I never created a subvolume on opensuse/TW.
 
Old 12-10-2023, 07:35 AM   #4
marozsas
Senior Member
 
Registered: Dec 2005
Location: Campinas/SP - Brazil
Distribution: SuSE, RHEL, Fedora, Ubuntu
Posts: 1,499

Original Poster
Blog Entries: 2

Rep: Reputation: 68
SOLVED

SOLVED.
For anyone interested:
attention: sda1 (the main btrfs) and sdb5 (current home on an slow HDD) are good for my system. Check the correct device names for yours.
  • boot in single user mode
Code:
# umount the current home
umount /home
# temporarily mount the btrfs on /mnt/btrfs
mkdir /mnt/btrfs
mount /dev/sda1 /mnt/btrfs -o subvol=/@
cd /mnt/btrfs
# create the new home subvolume
btrfs subvolume create home
# mount the old home somewhere
mkdir /mnt/old-home
mount /dev/sdb5 /mnt/old-home
cd /mnt/old-home
# copy the files from old disk for the new location
tar -cvf - user-folder-name-here | (cd /home; tar -xpf - )
# figure out which is the btrfs UUID.
# It is one UUID for the entire btrfs.
btrfs filesystem show
  • edit fstab and
    • comment the original /home entry from fstab
    • create a new entry for the new home subvolume. It is easier to duplicate any of other subvolume entries (e.g. /srv/, /opt/ /root) and change the mount point and subvolume part )
    • mine is:
      Code:
      UUID=3edcda06-f528-41df-a06b-3bdd4811d987  /home btrfs  subvol=/@/home
    • reboot
 
  


Reply

Tags
btrfs



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Mount a btrfs subvolume inside a subvolume? naps SUSE / openSUSE 3 03-29-2023 08:21 AM
btrfs root subvolume is inside the home subvolume and need to delete home subvol lemonade Slackware 3 10-29-2015 07:56 AM
Problems with /home mount on a btrfs subvolume - systemd exvor Gentoo 1 06-19-2015 11:19 AM
[SOLVED] Btrfs: Moving a large chuck of data from filesystem to subvolume vinbob Linux - Software 1 09-18-2014 04:42 AM
btrfs subvolume quota phil.d.g Linux - Software 0 08-29-2011 12:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > SUSE / openSUSE

All times are GMT -5. The time now is 01:41 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration