14.5. Switching to the New Layout
A migration is finished when the data sits on the new storage, but the system is not finished with the change: every configuration file and service that refers to the old location must follow the data, and when the migration moves the root filesystem, the boot path itself is part of the work. This section updates the mount and unlock configuration to the new identifiers, stages a bootable replacement root on a separate disk without modifying the running one, validates both trees, and ends with the retirement of old devices and the duplicate identifiers that cloning can leave behind.
14.5.1. Updating fstab, crypttab, and Service Paths
The kernel can mount a new filesystem by device name, but device names
are not stable. fstab and crypttab should use UUIDs for the same
reason Chapter 11 recommended them for ordinary
mounts: the identifier belongs to the filesystem or header, not to the
order in which the kernel discovered the disk.
Read the identifiers before editing either file:
# blkid /dev/md0 /dev/stackvg/stacklv
/dev/md0: UUID="0891fcb7-7286-4eea-bc53-31d3ef0f4f50" TYPE="crypto_LUKS"
/dev/stackvg/stacklv: LABEL="stacklv" UUID="b0f323be-9876-4714-9c62-6f1d1fec18b5" BLOCK_SIZE="4096" TYPE="ext4"
The crypttab entry names the mapping, the LUKS UUID, the key file, and
the luks option. Add one line to /etc/crypttab with a text editor,
using the UUID just read; the resulting file on the practice system is:
# cat /etc/crypttab
# <target name> <source device> <key file> <options>
cryptstack UUID=0891fcb7-7286-4eea-bc53-31d3ef0f4f50 /etc/luks-keys/stack.key luks
The matching fstab line uses the ext4 UUID and the mount point
/srv/stack. Append it to /etc/fstab; in this file it is the last
entry:
# tail -3 /etc/fstab
UUID=b0f323be-9876-4714-9c62-6f1d1fec18b5 /srv/stack ext4 defaults 0 2
Selected output; the two comment lines that precede this entry in the file are omitted.
The fields are:
| File | Field | Meaning |
|---|---|---|
crypttab |
target | Mapping name under /dev/mapper |
crypttab |
source | UUID=, LABEL=, PARTUUID=, or a device path |
crypttab |
key file | File or none for an interactive passphrase |
crypttab |
options | luks, discard, noauto, nofail, timeout=, and others |
fstab |
device | UUID=, LABEL=, or a device path |
fstab |
mount point | Directory where the filesystem is mounted |
fstab |
type | ext4, xfs, btrfs, auto, and so on |
fstab |
options | defaults, noatime, nofail, x-systemd.*, and so on |
fstab |
dump, pass | Backup and fsck order fields; 0 2 is common for a data filesystem |
Validate the fstab syntax before relying on it:
# findmnt --verify --tab-file /etc/fstab
[W] your fstab has been modified, but systemd still uses the old version;
use 'systemctl daemon-reload' to reload
0 parse errors, 0 errors, 1 warning
The warning is expected immediately after an edit; systemd reads the
file at boot and through its mount units. Reload the manager after the
edit:
# systemctl daemon-reload
The command is silent. To test the crypttab entry, unmount the filesystem,
deactivate the volume group, stop the mapping, and let cryptdisks_start
open it with the key file:
# umount /srv/stack
The command is silent.
# vgchange -an stackvg
0 logical volume(s) in volume group "stackvg" now active
# cryptdisks_stop cryptstack
Stopping crypto disk...cryptstack (stopping)...done.
# cryptdisks_start cryptstack
Starting crypto disk...cryptstack (starting)...cryptstack (started)...done.
# vgchange -ay stackvg
1 logical volume(s) in volume group "stackvg" now active
# mount -a
The command is silent when every fstab entry is already satisfied or successfully mounted.
# findmnt /srv/stack
TARGET SOURCE FSTYPE OPTIONS
/srv/stack /dev/mapper/stackvg-stacklv ext4 rw,relatime
The findmnt line proves that the mount came back through the fstab
entry, and the checksum file still verifies:
# sha256sum -c /home/john/debian-handbook/storage-migration/stack-keep.sha256
/srv/stack/keep.bin: OK
On a systemd host, the cryptdisks scripts and the
systemd-cryptsetup@.service generator both understand crypttab; which
one activates a mapping depends on the Debian package and the boot path.
Chapter 13 Section 13.4.4 covers the systemd
integration. The important migration lesson is that the UUID and the key
path in crypttab must match the new storage; a stale UUID produces a
mapping with the old device or a failed unlock at boot.
Services that refer to mount points by absolute path also need attention.
A unit can declare its dependency on the mount with RequiresMountsFor.
The practice unit file contains:
[Unit]
Description=Verify the stack data mount
RequiresMountsFor=/srv/stack
After=local-fs.target
[Service]
Type=oneshot
ExecStart=/usr/bin/findmnt -n /srv/stack
Save that as /etc/systemd/system/stackprobe.service, reload the manager,
and start the unit:
# systemctl daemon-reload
The reload is silent.
# systemctl start stackprobe.service
The start is silent because the unit's output goes to the journal. Read the journal to see the command's result:
# journalctl -u stackprobe.service --no-pager -n 4
Nov 20 18:02:18 migrate systemd[1]: Starting stackprobe.service - Verify the stack data mount...
Nov 20 18:02:18 migrate findmnt[12359]: /srv/stack /dev/mapper/stackvg-stacklv ext4 rw,relatime
Nov 20 18:02:18 migrate systemd[1]: stackprobe.service: Deactivated successfully.
Nov 20 18:02:18 migrate systemd[1]: Finished stackprobe.service - Verify the stack data mount.
RequiresMountsFor makes systemd pull in the mount unit before the
service starts. If the mount point is renamed during the migration, the
unit's absolute paths, WorkingDirectory, ReadWritePaths, and any
application configuration that names the old path must be updated as
well. A service that keeps the old path will start but read or write the
wrong directory, or fail only when it first touches the moved data.
14.5.2. Root Filesystem Migration, Initramfs, and Boot Loader Updates
Migrating a data filesystem is reversible by changing a mount line. Migrating the root filesystem is a boot-path change: the firmware, boot loader, initramfs, kernel command line, and fstab must all agree on where the root is. Stage the new root, validate it, and keep the old root bootable.
Figure 14.4. Staging a root filesystem on a new disk. The running root is never modified; the new disk is made bootable and validated before the boot order is changed.
Before touching the new disk, record the identity of the running boot configuration. The checksum taken now is compared against the same file in Section 14.5.3, proving that the staging work never modified the running system:
# sha256sum /boot/grub/grub.cfg
d92c3917c3dd3579cc1763fef489046200e5763fb3d5b9820080d2ea7203307a /boot/grub/grub.cfg
All boot-file work in this section happens under /mnt/newroot; the
running /boot/grub is only read. The practice target is the
disposable /dev/vdm. For a BIOS/GPT system, the disk needs a BIOS
boot partition for GRUB's core image and a data partition for the root
logical volume:
# parted -s /dev/vdm mklabel gpt
# parted -s /dev/vdm unit MiB mkpart biosgrub 1 2
# parted -s /dev/vdm set 1 bios_grub on
# parted -s /dev/vdm unit MiB mkpart rootlvm 2 100%
# parted -s /dev/vdm set 2 lvm on
The five preceding commands are silent.
# parted -s /dev/vdm unit MiB print
Model: Virtio Block Device (virtblk)
Disk /dev/vdm: 2048MiB
Sector size (logical/physical): 512B/512B
Partition Table: gpt
Disk Flags:
Number Start End Size File system Name Flags
1 1.00MiB 2.00MiB 1.00MiB biosgrub bios_grub
2 2.00MiB 2047MiB 2045MiB rootlvm lvm
The set 1 bios_grub on and set 2 lvm on commands turn on GPT
partition-type flags: bios_grub reserves the small first partition for
the GRUB core image that grub-install writes later, and lvm marks the
second partition as an LVM physical volume so partitioning and
installation tools recognize its role.
A UEFI system uses an EFI system partition instead of a BIOS boot
partition, formatted FAT32 and mounted at /boot/efi; the GRUB target is
x86_64-efi rather than i386-pc. The rest of the staging procedure is
the same.
Create the LVM layer, filesystem, and mount point on the new disk:
# pvcreate /dev/vdm2
Physical volume "/dev/vdm2" successfully created.
# vgcreate rootvg /dev/vdm2
Volume group "rootvg" successfully created
# lvcreate -L 1800M -n rootlv rootvg
Logical volume "rootlv" created.
# mkfs.ext4 -L rootlv /dev/rootvg/rootlv
Creating filesystem with 460800 4k blocks and 115200 inodes
Filesystem UUID: 218c3113-c18f-4736-9c47-270cf9f2ff21
...
Selected output; the ... omits the superblock-backup and progress
lines, as in the earlier mkfs.ext4 transcripts.
# mount /dev/rootvg/rootlv /mnt/newroot
The mount is silent.
The new root is 1.8 GiB because the whole target disk is only 2 GiB. The running root uses about 1.1 GiB, so the stage fits, but a real system must be sized from its actual used space plus room for logs and package updates. The copy excludes virtual filesystems, the mount points that belong to other storage, and temporary data:
# rsync -aHAXx --numeric-ids \
--exclude=/proc --exclude=/sys --exclude=/dev --exclude=/run \
--exclude=/tmp --exclude=/var/tmp --exclude=/mnt --exclude=/media \
--exclude=/srv --exclude=/lost+found --exclude=/var/cache/apt/archives \
/ /mnt/newroot/
-x keeps the copy on the root filesystem, so a mounted /srv or /boot
does not recurse into another tree. The explicit excludes document the
same boundary and also omit temporary directories that will be recreated.
The command is silent on success. Check the staged size:
# du -sh /mnt/newroot
1.1G /mnt/newroot
Create the directories that were excluded, then bind the runtime filesystems so the chroot's package scripts and initramfs tools can run:
# mkdir -p /mnt/newroot/dev /mnt/newroot/proc /mnt/newroot/sys /mnt/newroot/run \
/mnt/newroot/tmp /mnt/newroot/var/tmp
# chmod 1777 /mnt/newroot/tmp /mnt/newroot/var/tmp
The two commands are silent.
# for d in dev proc sys run; do mount --bind /$d /mnt/newroot/$d; done
The loop is one bounded operation that binds four directories. It is
silent. Do not bind /mnt or /srv; the staged root has its own /mnt
and the application data remains on its existing stack.
Update the staged root's fstab so its / entry uses the new filesystem
UUID. The exact editing command depends on the editor; a scripted
replacement is shown here because the value is generated by blkid:
# new=$(blkid -s UUID -o value /dev/rootvg/rootlv)
The assignment is silent.
# sed -i "s|^UUID=[^[:space:]]*[[:space:]]/[[:space:]].*|UUID=$new / ext4 defaults 0 1|" /mnt/newroot/etc/fstab
The edit is silent.
# grep -E "^[^#].*[[:space:]]/[[:space:]]" /mnt/newroot/etc/fstab
UUID=218c3113-c18f-4736-9c47-270cf9f2ff21 / ext4 defaults 0 1
The grep shows only the root line. A real
root may also have separate /boot, /var, or swap entries; update each
one whose device changed, and leave the entries for storage that is not
moving untouched.
Regenerate the initramfs inside the staged root:
# chroot /mnt/newroot update-initramfs -u -k all
update-initramfs: Generating /boot/initrd.img-6.12.86+deb13-amd64
W: No zstd in /usr/bin:/sbin:/bin, using gzip
The warning means the initramfs was compressed with gzip because the
chroot did not have zstd available; the image is still valid. If the
new root is on LVM, RAID, or LUKS, the initramfs must contain the
matching userspace tools and kernel modules. Debian's initramfs-tools
includes them when the packages are installed and the root is visible in
the chroot. Check the result rather than assuming: lsinitramfs lists
the archive's contents, and grep keeps the lines that name the
encryption module and the LVM files:
# lsinitramfs /mnt/newroot/boot/initrd.img-6.12.86+deb13-amd64 | grep -E "dm-crypt|lvm"
usr/lib/modules/6.12.86+deb13-amd64/kernel/drivers/md/dm-crypt.ko.xz
etc/lvm
etc/lvm/archive
...
usr/sbin/lvm
Selected output; the ... stands for the archive, backup,
configuration, profile, and udev entries that the same grep matched. The
listing confirms the kernel module and the LVM userspace files are
present. A root on LUKS also needs the hook from the
cryptsetup-initramfs package and a valid crypttab entry for the
root device; a root on RAID needs the md
modules and an assembly path. Those dependencies are the reason to test
the new root's initramfs before changing the boot order.
Generate the GRUB configuration from the staged tree:
# chroot /mnt/newroot update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-6.12.86+deb13-amd64
Found initrd image: /boot/initrd.img-6.12.86+deb13-amd64
Adding boot menu entry for UEFI Firmware Settings ...
done
update-grub runs grub-mkconfig; it writes the menu inside the chroot's
/boot/grub, not the running system's /boot/grub. The generated menu
searches for the new root UUID:
# grep -m2 -E "search --no-floppy|linux[[:space:]]" /mnt/newroot/boot/grub/grub.cfg
search --no-floppy --fs-uuid --set=root --hint='lvmid/rJuy5B-Lp9A-U2dJ-CQwy-cwim-3HV7-EonQ3b/R70BZK-m3Dg-jzgh-3pTP-yi4t-QZ45-rJEd9R' 218c3113-c18f-4736-9c47-270cf9f2ff21
search --no-floppy --fs-uuid --set=root 218c3113-c18f-4736-9c47-270cf9f2ff21
If that UUID is the new root's, the menu is pointing at the right filesystem. Install the boot loader onto the new disk. Because the disk has a BIOS boot partition and the root is on LVM, the BIOS target can embed the LVM module:
# chroot /mnt/newroot grub-install --target=i386-pc /dev/vdm
Installing for i386-pc platform.
Installation finished. No error reported.
A UEFI system installs to the mounted ESP instead, for example
grub-install --target=x86_64-efi --efi-directory=/boot/efi, and the
firmware boot entry must point at the new disk. GRUB on a partitionless
LVM PV or on a disk without the required boot partition will refuse the
install or warn about embedding; the partition layout is part of the
boot design, not an afterthought.
14.5.3. Validating the New System and Keeping a Rollback Path
Validation has two goals: prove that the staged files are internally consistent, and prove that the running system has not been changed. The first checks read the staged tree:
# grub-script-check /mnt/newroot/boot/grub/grub.cfg
grub-script-check is silent when the GRUB script parses.
# findmnt --verify --tab-file /mnt/newroot/etc/fstab
Success, no errors or warnings detected
findmnt --verify reports no errors in the staged fstab. A chroot
smoke test such as chroot /mnt/newroot /bin/true is a further option:
it is silent and exits zero when the staged tree can execute its own
binaries. It does not prove that the kernel will mount the root, but it
catches a broken dynamic linker or a badly incomplete copy.
The second goal is to keep the running boot path unchanged. The old root
is still mounted on /, and the running GRUB configuration has not been
rewritten:
# findmnt -n -o SOURCE,FSTYPE /
/dev/vda1 ext4
# sha256sum /boot/grub/grub.cfg
d92c3917c3dd3579cc1763fef489046200e5763fb3d5b9820080d2ea7203307a /boot/grub/grub.cfg
The checksum matches the one recorded at the start of Section 14.5.2;
the new menu lives under /mnt/newroot/boot/grub, not in the running
/boot/grub. Keep
the old root disk, the old boot entry, and the restore material until the
new system has booted and served its workload. A rollback path is not a
copy of the old filesystem; it is a boot path that still works.
| Validation | Command | What it proves |
|---|---|---|
| GRUB syntax | grub-script-check FILE |
The generated menu parses |
| fstab syntax | findmnt --verify --tab-file FILE |
Entries are syntactically valid |
| Initramfs contents | lsinitramfs IMAGE |
Required modules and tools are present |
| Staged root execution | chroot /mnt/newroot /bin/true |
The staged tree can run its own binaries |
| Old root unchanged | findmnt /, checksum of running grub.cfg |
The running system still boots the old layout |
| Data intact | sha256sum -c on copied files |
The copy matches the source |
A test boot is the only proof that the firmware, boot loader, initramfs, and root filesystem agree. If the boot fails, boot the old root from the existing boot entry, restore the old fstab or boot order, and inspect the new root's initramfs and GRUB configuration from the working system. Do not wipe the old disk until the new system has been tested under its normal workload.
14.5.4. Retiring Old Storage and Handling Duplicate Identifiers
Retirement is the last step, not the first. After the data has moved and the new layout has been validated, remove the old signatures so the kernel and the administrative tools do not rediscover the old identity. For the pvmove and md replacement exercises, the old devices have already been removed from their volume group and array. Confirm that fact, then wipe the remaining signatures:
# pvs /dev/vde
Failed to find physical volume "/dev/vde".
The message is written to standard error and the command exits nonzero:
pvremove erased the label, so pvs finds no physical volume. The md
check confirms that the old array member is equally anonymous:
# mdadm --examine /dev/vdd
mdadm: No md superblock detected on /dev/vdd.
# wipefs -a /dev/vde /dev/vdd
wipefs -a prints nothing when there is nothing left to erase; its
purpose is to remove any remaining filesystem, RAID, or partition
signature. The pvs failure and the mdadm message are the expected
answers for a device that is no longer a member. Do not use the device
for a new filesystem until blkid shows no unexpected signature.
Duplicate identifiers are a distinct hazard. Cloning a disk, restoring a
whole-device image, or copying a filesystem with a tool that preserves
the UUID can leave two devices claiming the same identity. fstab and
crypttab then have no way to choose the intended one, and md or LVM may
assemble the wrong set. The XFS practice filesystem is no longer needed. Unmount it and wipe its
signature before reusing the device:
# umount /srv/xfs
The command is silent.
# wipefs -a /dev/vdb
/dev/vdb: 4 bytes were erased at offset 0x00000000 (xfs): 58 46 53 42
The practice then creates an ext4 clone on /dev/vdb with the same UUID
as stacklv:
# mkfs.ext4 -q -L clone /dev/vdb
The quiet filesystem creation is silent.
# tune2fs -U "$(blkid -s UUID -o value /dev/stackvg/stacklv)" /dev/vdb
tune2fs 1.47.2 (1-Jan-2025)
tune2fs prints only its version banner; it changes the clone's UUID to
the existing value.
# blkid -s UUID -o value /dev/stackvg/stacklv /dev/vdb
b0f323be-9876-4714-9c62-6f1d1fec18b5
b0f323be-9876-4714-9c62-6f1d1fec18b5
Both devices now report the same
UUID. If both were attached at boot, fstab's UUID=b0f323be... entry
would be ambiguous. Give the clone a new UUID:
# tune2fs -U random /dev/vdb
tune2fs 1.47.2 (1-Jan-2025)
# blkid -s UUID -o value /dev/stackvg/stacklv /dev/vdb
b0f323be-9876-4714-9c62-6f1d1fec18b5
fb6508d6-f691-4dfb-a876-7861edc74d3d
The two values now differ. The same principle applies to other identifiers:
| Identifier | Inspect | Change or clear |
|---|---|---|
| ext4/XFS filesystem UUID | blkid, tune2fs -l, xfs_admin -u |
tune2fs -U random, xfs_admin -U generate |
| Btrfs filesystem UUID | btrfs filesystem show |
btrfstune -u on an unmounted filesystem |
| LUKS UUID | cryptsetup luksUUID |
cryptsetup luksUUID --uuid UUID DEVICE |
| md array UUID | mdadm --detail, mdadm --examine |
mdadm --zero-superblock and recreate the array |
| GPT disk and partition GUIDs | sgdisk --print, blkid |
sgdisk --disk-guid, sgdisk --partition-guid |
| LVM PV/VG UUIDs | pvs -o pv_uuid, vgs -o vg_uuid |
pvchange -u, vgchange -u; do not duplicate a VG identity |
Changing a UUID that is referenced by fstab, crypttab, or a boot
loader entry requires a corresponding update to that reference. A new
UUID is safer than two devices with the same one, but it is not invisible
to the configuration.
After the old devices are wiped and the duplicate identifiers are resolved, update the layout record from Section 14.1.2 and check the final state:
Run lsblk -o NAME,SIZE,TYPE,FSTYPE,MOUNTPOINTS, blkid, pvs,
vgs, lvs -o lv_name,vg_name,lv_size,devices, findmnt --verify, and
df -h, and compare them with the layout captured in Section 14.1.2.
The exact output depends on which practice devices remain in service.
The checks are the same ones used at the start: every mounted filesystem
has a unique identifier, every layer reports the expected size, and the
data checksums still match. A storage migration is complete only when the
old identity is gone, the new layout is mounted, and a reboot has proved
that the boot path and the configuration files agree.