I have linux with root partition luck encrypted. Luck uuid is in /etc/crypttab but where is underlying uuid of ext4 partition? It isn't in /etc/fstab. Where is it? On root or on boot partition?
Assistant
When you have a LUKS-encrypted root partition on a Linux system, the setup involves several layers. Let's outline where you can typically find the relevant pieces of information, including the underlying ext4 partition's UUID:
User
I changed underlying partition id and by system cannot boot because it expects this id. Where the id is located in system files?
Assistant
User
How to change partition id back?
Assistant
If you've changed the partition ID (UUID) and need to revert it back to its original value, you can do so using tools like tune2fs or for ext4 filesystems. However, this requires you to know the original UUID. Here’s how you can change the UUID back if you have that information:
User
Can I find my original id without regeneration of initramfs?
Assistant
If you're trying to find the original UUID of a partition without regenerating the initramfs, there are a few things you can try:
Check System Backups or Logs:
If you have system backups or logs that were created prior to the UUID change, you may be able to find the original UUID there. Look in configuration files such as , , or any system configuration management tools you use.
User
What does each command mean there: zcat /boot/initrd.img-$(uname -r) | cpio -idmv
grep -r “UUID”
zcat is a command that reads compressed files (typically those compressed with gzip) and outputs the uncompressed data to standard output, similar to cat for plain text files.
LUKS Encrypted Partition:
The LUKS container is set up directly on a disk partition, whose UUID is typically noted in /etc/crypttab. This UUID refers to the LUKS partition, not the filesystem below it.
Filesystem Inside LUKS:
Once the LUKS partition is unlocked, it reveals a block device (such as /dev/mapper/root), which contains the actual filesystem (ext4 in your case).
Underlying UUID for ext4 Partition:
The UUID for the ext4 filesystem inside the decrypted LUKS container is generally found in /etc/fstab if the mapping is required at boot. However, in a setup where the root partition itself is encrypted, the root partition does not usually appear in /etc/fstab directly by its UUID, because it's already handled by the initramfs during boot.
Locating ext4 UUID:
To find the UUID of the ext4 filesystem inside the LUKS container, you need to unlock the LUKS partition first. This can often be done manually post-boot if you're troubleshooting:
sudo cryptsetup luksOpen /dev/sdX YYY
Here, /dev/sdX represents your LUKS-encrypted partition and YYY is the name you'll use as the decrypted name (e.g., root).
Once unlocked, you can use blkid or lsblk to find out the UUID:
sudo blkid /dev/mapper/YYY
Replace YYY with whatever name you chose.
Boot vs Root Partition:
In traditional setups, the boot partition is separate and unencrypted since it needs to be accessible to the bootloader (GRUB, for instance). It usually contains the kernel, initramfs, and GRUB files but does not have the root filesystem UUIDs directly if they're encrypted.
To summarize, the underlying ext4 UUID is not normally found in /etc/crypttab or /etc/fstab directly for an encrypted root setup; it's derived after the LUKS container is opened, generally by the initramfs, which prepares the system to mount root by processing /etc/crypttab and then providing the decrypted device to the kernel as the root filesystem. If needed manually, blkid or similar tools can be used post-unlock to ascertain UUIDs.
If you've changed the partition UUID of an underlying partition while using LUKS encryption, your system is unable to boot because it relies on this UUID to identify and unlock the encrypted partition during the boot process. Here’s how to resolve this issue:
Where the UUID is Stored
/etc/crypttab:
The /etc/crypttab file contains entries for encrypted partitions that are unlocked during boot. Each entry typically includes the UUID of the LUKS container. If you altered the UUID, this needs to be updated to match the new UUID of the partition.
/etc/fstab:
Although the root partition itself might not be listed directly if it is fully encrypted, other partitions like /home or additional encrypted partitions might use UUIDs in this file. Update any entries with the new UUID if needed.
Initramfs:
The initramfs image, which is used during the early boot process, can also contain references to UUIDs from /etc/crypttab. If you change the UUID, you need to regenerate the initramfs so that it includes these updates.
Steps to Fix the Boot Issue
Boot from a Live Environment:
Use a Linux live CD/USB to boot your system so you can access the files on your disk.
Mount the Root Filesystem:
Once booted into the live environment, mount your root filesystem to a temporary directory. This will usually be the decrypted LUKS container (once unlocked) or a separate root partition if not encrypted.
sudo cryptsetup luksOpen /dev/sdX encrypted_partition
sudo mount /dev/mapper/encrypted_partition /mnt
Edit /etc/crypttab:
Navigate to /mnt/etc/crypttab and update the UUID to the new one. You can find the new UUID using blkid.
sudo nano /mnt/etc/crypttab
Update Initramfs:
Chroot into your mounted filesystem to properly update initramfs.
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
Regenerate the initramfs with the command:
update-initramfs -u
Update /etc/fstab:
Check /mnt/etc/fstab for any outdated UUIDs if other filesystems also rely on UUIDs, and update them accordingly.
Reboot the System:
Exit the chroot environment, unmount the partitions, and reboot. Your system should now boot normally.
By following these steps, you should be able to resolve the boot issues caused by the change in partition UUID.
e2label
Assuming You Know the Original UUID
Boot from a Live Environment:
If your system can't boot, use a Linux live CD/USB to boot your system so you can access the files on your disk.
Identify the Partition:
Find the correct partition that you want to change back. Use lsblk or blkid to list your partitions and their current UUIDs.
Change UUID with tune2fs:
Unmount the partition if it is mounted. Then use tune2fs to revert the UUID to the original.
sudo umount /dev/sdX1 # Replace /dev/sdX1 with your partition
sudo tune2fs -U original-uuid /dev/sdX1
Replace original-uuid with the UUID you want to assign, and /dev/sdX1 with the appropriate partition.
If You Don’t Have the Original UUID
If you don't have a record of the original UUID, you'll need to ensure all configuration files and scripts that rely on the UUID are updated to use the current one after any changes. UUIDs are meant to be unique, so without the original value, you'll have to work around by updating configurations.
Post-Change Steps
Update /etc/crypttab and /etc/fstab:
Ensure these files reflect the updated UUID to avoid boot issues:
Make sure to provide the new UUID where the original one was expected.
Regenerate Initramfs (if changing a UUID affecting boot):
As necessary, regenerate the initramfs inside a chroot environment. This is usually needed if /etc/crypttab was updated:
sudo mount --bind /dev /mnt/dev
sudo mount --bind /proc /mnt/proc
sudo mount --bind /sys /mnt/sys
sudo chroot /mnt
update-initramfs -u
exit
Reboot your System:
After correcting UUIDs in all necessary places, reboot your system. This should resolve UUID mismatch issues.
By carefully applying these steps, you can manage UUID changes and ensure your system is configured accordingly. If you ever need to change UUIDs intentionally, always ensure you keep a record of the originals for such rollbacks.
/etc/crypttab
/etc/fstab
Look in Initramfs/Image:
Although you mentioned not wanting to regenerate the initramfs, the existing initramfs might contain the UUID. You can extract and inspect your current initramfs to see if the original UUID is stored there:
This command will extract the initramfs used by your current kernel version and search for UUIDs. Note that the actual paths and commands might vary slightly depending on your distribution and initramfs format.
GRUB Command Line:
Sometimes, the bootloader (GRUB) configuration might include UUIDs. Inspect /boot/grub/grub.cfg for any UUID entries that might give you clues.
System Documentation:
In case you documented your system setup, installation, or changes, those records might include the original UUIDs.
Disk Imaging Tools:
If you cloned or imaged the disk or partition before making changes, revisit those images, as they will have the original UUID.
If none of these methods are feasible or successful, and you weren't able to retrieve the original UUID from other sources (like backups, documentation, etc.), you would typically need to ensure that systems and scripts expecting the original UUID are updated with the new one unless the original UUID can be restored via documented sources. Regenerating the initramfs is typically associated with making sure the system boots correctly with the updated UUID, but it won't inherently restore the original UUID unless you modify crypttab/fstab or other reference files accordingly.
/boot/initrd.img-$(uname -r):
This part specifies the file you're working with. The uname -r command returns the current kernel version, so $(uname -r) is a command substitution that inserts the kernel version into the file path.
/boot/initrd.img-$(uname -r) refers to the initial RAM disk image (initramfs) that corresponds to the running kernel. This file is used during boot to prepare the system before the root filesystem is mounted.
|:
The pipe | takes the output from the zcat command and passes it as input to the cpio command.
cpio -idmv:
cpio is a tool for creating and extracting archive files.
The options used here:
-i: Read (extract) files from an archive.
-d: Create leading directories where needed.
-m: Retain previous file modification times when creating files.
-v: Verbosely list the files processed.
Together, this command unpacks the initramfs image into the current directory, creating the necessary directory structure.
Command 2: grep -r "UUID"
grep:
grep searches text using pattern matching. In this case, it's used to find occurrences of the string "UUID".
-r:
This option makes grep search recursively through directories. So, it will check every file under the current directory and its subdirectories.
"UUID":
This is the search pattern. The command looks for this specific string in the files.
Together, these commands extract an initramfs image to a temporary directory and search for any occurrence of "UUID" in the extracted files. This can help locate UUID references within the initramfs which might point to the devices expected during boot.