User:Bfsok/Migrating from OpenSUSE

From Gentoo Wiki
Jump to:navigation Jump to:search

These are some miscellaneous installation notes for migrating my laptop and workstation from OpenSUSE to Gentoo (while specifically preserving my home directory and retaining btrfs as my filesystem of choice). This should not be considered a guide; these are supplemental notes to refer to alongside the official handbook.

Choosing the installation medium

For my purposes, a bootable USB stick prepared according to the LiveUSB guide is sufficient. I prefer using the "LiveGUI" image (so I can open the handbook in a browser on the same screen alongside my terminal session) but the minimal, command-line only image should work just fine as well. Once this is done, boot the target machine using said freshly baked USB stick.

Preparing the disks

The current layout

Let's have a look at how OpenSUSE originally configured the disks. My storage medium is an NVMe SSD, so I happen to know that it's at /dev/nvme0n1. If your configuration is different, replace this as appropriate (or just leave it off entirely and let lsblk show you all block devices).

livecd ~ #lsblk --tree --output name,type,fstype,path /dev/nvme0n1
nvme0n1                                     disk              /dev/nvme0n1
├─nvme0n1p1                                 part  vfat        /dev/nvme0n1p1
└─nvme0n1p2                                 part  crypto_LUKS /dev/nvme0n1p2

As we can see, the SSD has two partitions: the first is the boot partition and the second is a LUKS encrypted LVM volume group. Let's decrypt that partition using dm-crypt:

root #cryptsetup luksOpen /dev/nvme0n1p2 cr_nvme
Enter passphrase for /dev/nvme0n1p2:

Once it decrypts, run the lsblk command again:

livecd ~ #lsblk --tree --output name,type,fstype,path /dev/nvme0n1
nvme0n1                                     disk              /dev/nvme0n1
├─nvme0n1p1                                 part  vfat        /dev/nvme0n1p1
└─nvme0n1p2                                 part  crypto_LUKS /dev/nvme0n1p2
  └─cr_nvme                                 crypt LVM2_member /dev/mapper/cr_nvme
    ├─system-root                           lvm   btrfs       /dev/mapper/system-root
    └─system-swap                           lvm   swap        /dev/mapper/system-swap

The volume group itself contains two volumes: system-root and system-swap.

OpenSUSE originally configured system-root with several Btrfs subvolumes, organized under a "root" subvolume located at /@. Let's mount it to have a look:

root #mkdir /mnt/gentoo
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@ /dev/mapper/system-root /mnt/gentoo
root #cd /mnt/gentoo
root /mnt/gentoo #ls -a1
.
..
.snapshots
boot
etc
home
opt
root
srv
tmp
usr
var
Note
We mounted the subvolume at /@, so this isn't what would normally be mounted at /. That can actually be found under /root.

The subvolumes

The following command will list the btrfs subvolumes:

root /mnt/gentoo #btrfs subvolume list .
ID 256 gen 32 top level 5 path @
ID 257 gen 3125674 top level 256 path var
ID 258 gen 3125672 top level 256 path usr/local
ID 259 gen 3125674 top level 256 path tmp
ID 260 gen 3113448 top level 256 path srv
ID 261 gen 3124693 top level 256 path root
ID 262 gen 3125672 top level 256 path opt
ID 263 gen 3125674 top level 256 path home
ID 264 gen 3115921 top level 256 path boot/grub2/x86_64-efi
ID 265 gen 3080461 top level 256 path boot/grub2/i386-pc
ID 266 gen 3124282 top level 256 path .snapshots
ID 267 gen 3125674 top level 266 path .snapshots/1/snapshot

root is the subvolume currently mounted by OpenSUSE as /. The others are then mounted at /var, /srv, /home, and so on.

The goal is to install Gentoo while preserving the existing /home. I also don't want to destroy any data from the existing install, just in case I want to grab anything out of it later on. I decided to create the following new subvolume layout for the new install:

Subvolume Full path Mount point
gentoo /@/gentoo /
home (use existing subvolume) /@/home /home
data/opt /@/data/opt /opt
data/srv /@/data/srv /srv
data/usr_local /@/data/usr_local /usr/local
data/var_db_pkg /@/data/var_db_pkg /var/db/pkg
data/var_db_repos /@/data/var_db_repos /var/db/repos
data/var_mail /@/data/var_mail /var/spool/mail
ephemeral/tmp /@/ephemeral/tmp /tmp
ephemeral/var_cache /@/ephemeral/var_cache /var/cache
ephemeral/var_log /@/ephemeral/var_log /var/log
ephemeral/var_tmp /@/ephemeral/var_tmp /var/tmp
snapshots /@/snapshots /.snapshots
Note
Q: Why mount to /var/spool/mail and not /var/mail? A: Because there is a mail related package I encountered during installation that wants to symlink /var/mail to /var/spool/mail and will fail if it isn't able to. This avoids that issue.

This is accomplished with the following commands (make sure the current directory is /mnt/gentoo:

root /mnt/gentoo #btrfs subvolume create gentoo
Create subvolume './gentoo'
root /mnt/gentoo #mkdir data
root /mnt/gentoo #btrfs subvolume create data/opt
Create subvolume 'data/opt'
root /mnt/gentoo #btrfs subvolume create data/srv
Create subvolume 'data/srv'
root /mnt/gentoo #btrfs subvolume create data/usr_local
Create subvolume 'data/usr_local'
root /mnt/gentoo #btrfs subvolume create data/var_db_pkg
Create subvolume 'data/var_db_pkg'
root /mnt/gentoo #btrfs subvolume create data/var_db_repos
Create subvolume 'data/var_db_repos'
root /mnt/gentoo #btrfs subvolume create data/var_mail
Create subvolume 'data/var_mail'
root /mnt/gentoo #mkdir ephemeral
root /mnt/gentoo #btrfs subvolume create ephemeral/tmp
Create subvolume 'ephemeral/tmp'
root /mnt/gentoo #btrfs subvolume create ephemeral/var_cache
Create subvolume 'ephemeral/var_cache'
root /mnt/gentoo #btrfs subvolume create ephemeral/var_log
Create subvolume 'ephemeral/var_log'
root /mnt/gentoo #btrfs subvolume create ephemeral/var_tmp
Create subvolume 'ephemeral/var_tmp'
root /mnt/gentoo #btrfs subvolume create snapshots
Create subvolume './snapshots'

Mounting up

Time to mount our new root:

root #umount /mnt/gentoo
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/gentoo /dev/mapper/system-root /mnt/gentoo

Mount the subvolumes:

root #mkdir -p /mnt/gentoo/{home,opt,srv,usr/local,var/db/pkg,var/db/repos,var/spool/mail,tmp,var/cache,var/log,var/tmp,.snapshots}
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/home /dev/mapper/system-root /mnt/gentoo/home
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/opt /dev/mapper/system-root /mnt/gentoo/opt
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/srv /dev/mapper/system-root /mnt/gentoo/srv
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/usr_local /dev/mapper/system-root /mnt/gentoo/usr/local
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/var_db_pkg /dev/mapper/system-root /mnt/gentoo/var/db/pkg
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/var_db_repos /dev/mapper/system-root /mnt/gentoo/var/db/repos
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/data/var_mail /dev/mapper/system-root /mnt/gentoo/var/spool/mail
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/ephemeral/tmp /dev/mapper/system-root /mnt/gentoo/tmp
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/ephemeral/var_cache /dev/mapper/system-root /mnt/gentoo/var/cache
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/ephemeral/var_log /dev/mapper/system-root /mnt/gentoo/var/log
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/ephemeral/var_tmp /dev/mapper/system-root /mnt/gentoo/var/tmp
root #mount -o defaults,noatime,compress=zstd,commit=120,subvol=/@/snapshots /dev/mapper/system-root /mnt/gentoo/.snapshots

Mount the boot partition:

root #mkdir /mnt/gentoo/boot
root #mount /dev/nvme0n1p1 /mnt/gentoo/boot

Save everything to /etc/fstab:

root #genfstab -U /mnt/gentoo >> /mnt/gentoo/etc/fstab

The swap partition

The swap partition also needs to be mounted by /etc/fstab. To add the appropriate entry, we want to first determine the UUID of the swap partition:

root #blkid | grep system-swap
/dev/mapper/system-swap: UUID="f72912ff-ce27-4955-946b-d6d0f4171137" TYPE="swap"

Copy the UUID string and edit /etc/fstab:

root #nano /mnt/gentoo/etc/fstab
...

# /dev/nvme0n1p1
UUID=F718-2A01          /boot           vfat     ...

# /dev/system/swap
UUID=f72912ff-ce27-4955-946b-d6d0f4171137       none            swap            0 0

# /dev/mapper/system-root
UUID=b5b8979b-b3a4-4661-a99f-4626209e13e5       /home           btrfs      ...

...

Installation

At this point, everything should be ready for installation of stage3.

To Be Continued

This page is still a work-in-progress. Stand-by for more.