38

I have an unique situation where I need to change UUID of usb flash drive to previous UUID. I formatted it and obviously number changed...

I've ubuntu server setup with 1TB hdd, and 4GB usb flash drive to boot from. Grub on hdd is configured for UUID which changed when I formated usb drive and reinstalled ubuntu server. I've no external monitor, so I attach usb to laptop and install server there... than I move it to server hardware.

As I mentioned my problem is that I need usb to go back to previous UUID, otherwise server won't boot. And I cannot get external monitor till monday! :)

I know I need these files changed afterwards:

The files for which UUID is most critical:

/boot/grub/menu.lst

/etc/fstab

/etc/initramfs-tools/conf.d/resume

But I cannot find anywhere on the net info about customizing UUID.

Anyone?

5 Answers 5

43

If you used ext for it:

tune2fs /dev/{device} -U {uuid}

From man tune2fs

-U UUID

Set the universally unique identifier (UUID) of the filesystem to UUID. The format of the UUID is a series of hex digits separated by hyphens, like this: c1b9d5a2-f162-11cf-9ece-0020afc76f16. The UUID parameter may also be one of the following:

clear  clear the filesystem UUID
random generate a new randomly-generated UUID
time   generate a new time-based UUID

The UUID may be used by mount(8), fsck(8), and /etc/fstab(5) (and possibly others) by specifying UUID=uuid instead of a block special device name like /dev/hda1.

6
  • That worked! But I cannot find: /etc/initramfs-tools/conf.d/resume I found that /boot/grub/menu.lst had been converted to /boot/grub/grub.cfg
    – user25389
    May 5, 2012 at 14:32
  • I have a /etc/initramfs-tools/conf.d/resume on my system. And grub.cfg is indeed the new menu.lst (I think that one came into play with the new grub2.
    – Rinzwind
    May 5, 2012 at 14:35
  • No matter what I try, I get an error when trying to set my own UUID (tune2fs: Invalid UUID format). Is there a specific order to things?
    – Andrew
    Sep 26, 2015 at 8:37
  • tun2fs isnt working on my ZFS gpt disk, what do i do there? Oct 26, 2016 at 9:38
  • Looking at the answer for XFS (xfs_admin) I'd suggest looking for a zfs_admin But isn't zfs Solaris?! How do you see Ubuntu being able to help here?
    – Rinzwind
    Oct 26, 2016 at 9:51
15

I realize this is kind of an old question, but I found there was a new change, and this was what google snooped up for me, so I'll post the answer I found here.

when I tried to change my root filesystem's uuid (to a well known beginning and a serial number suffix) on new 14.04 ubuntu, I found to my horror tune2fs reported back: I can't do that to mounted file systems. I depend on being able to use a template image with a well known uuid, and change each install to a serialized uuid. I found the problem wasn't insurmountable.

There's a flag that needs to be disabled, to allow mounted-uuid changes with the new tune2fs. this is what my process looked like:

root@ubuntu1404:~# blkid
/dev/sda1: UUID="2ec827b0-72be-4c73-b58a-102a37aa24a3" TYPE="ext4"
root@ubuntu1404:~# uuid="deafcafe-abba-daba-deca-fc0ffee05065"
root@ubuntu1404:~# root_disk=$(df /|grep /|cut -d' ' -f1)
root@ubuntu1404:~# echo $root_disk
/dev/sda1
root@ubuntu1404:~# tune2fs -U $uuid $root_disk
tune2fs 1.42.9 (4-Feb-2014)
The UUID may only be changed when the filesystem is unmounted.
root@ubuntu1404:~# tune2fs -O ^uninit_bg $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# tune2fs -U $uuid $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# tune2fs -O +uninit_bg $root_disk
tune2fs 1.42.9 (4-Feb-2014)
root@ubuntu1404:~# df -h /
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda1       7.3G  3.9G  3.0G  58% /
root@ubuntu1404:~# blkid
/dev/sda1: UUID="deafcafe-abba-daba-deca-fc0ffee05065" TYPE="ext4"
root@ubuntu1404:~#
3
  • Thanks. Could be helpful in future, but I'm still on 12.04 :)
    – user25389
    May 1, 2014 at 20:05
  • 1
    You could use root_disk=$(findmnt -n -o SOURCE /) instead of piping to grep and cut.
    – mivk
    Apr 7, 2019 at 16:49
  • 1
    DON'T DO THAT OR YOU WILL CORRUPT YOUR FILESYSTEM. I removed then added back uninit_bg and it lead to metadata corruption and automatic read-only remount on next boot (ext4_mb_generate_buddy:757: group 1, block bitmap and bg descriptor inconsistent: 3701 vs 3700 free clusters type of error messages). The reason is that tune2fs directly modifies the disk, under the feet of the kernel and when the kernel gets to updating the bg metadata, half of the times it actually corrupts the metadata! bottomline: the fileysstem UUID can't be safely changed without properly unmounting the filesystem.
    – Eric
    Nov 20, 2019 at 17:47
6

For xfs see man xfs_admin

xfs_admin -U {uuid} {device}

{uuid} can be 'generate' to just get a new uuid.

For reiserfs see man tunefs.reiserfs

tunefs.reiserfs -i {uuid} {device}

For btrfs it seems the uuid is used thoughout the file systems so every node have to be updated. There is no safe way to do that yet.

0

comprehensive info:

how-to-retrieve-and-change-partitions-universally-unique-identifier-uuid-on-linux

1
  • 5
    Welcome to Ask Ubuntu! Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.
    – Peachy
    Sep 27, 2012 at 22:30
0

Just a hint: On my 20.04 system, blkid continued to report the old UUID after running:

sudo tune2fs -U "sudo tune2fs -U "4fa4fa92-8b6a-4597-8481-d0897bdf86fe" /dev/sdb1

blkid /dev/sdb1 reported the new UUID only after checking the partition with GParted. Until then, always the old UUDI was reported by blkid. Of course, reboot would help as well.

1
  • There's syntax error in the command mentioned. Did you retyped sudo tune2fs -U "?
    – Kulfy
    Jan 15, 2021 at 11:04

You must log in to answer this question.