Rename a Volume Group in Ubuntu 12.04


This post is in the category: Tips

Random small break-fix or enlightening ideas


Ubuntu names the volume group according to the hostname of the computer, but sometimes I want to change it after the fact, and doing so is pretty easy.

Since writing this procedure, I did run into a reason why unique volume groups could be useful. I had a system crash, which required me to take the HDD and connect it into a working system. Both machines used the VG name of “system”, so this caused a conflict with mounting both VGs. In this case, I had to rename one of them to perform my data recovery.

Rebooting after only partially completing these steps will result in a broken system!

I created a test system with the initial hostname of dev-xfce-01. Take a look at one of the device names.

[root]$ df -h
Filesystem                          Size  Used Avail Use% Mounted on
/dev/mapper/dev--xfce--01--vg-root  6.7G  1.1G  5.3G  17% /
udev                                494M  4.0K  494M   1% /dev
tmpfs                               201M  300K  200M   1% /run
none                                5.0M     0  5.0M   0% /run/lock
none                                501M     0  501M   0% /run/shm
/dev/sda1                           228M   24M  192M  12% /boot

That just looks messy. The swap partition, not shown here, looks just as bad. Why do I care? I want to have a consistent VG name across all my systems for easy monitoring.

To see the actual VG name, run this.

[root]$ vgs
  VG             #PV #LV #SN Attr   VSize VFree 
  dev-xfce-01-vg   1   2   0 wz--n- 7.76g 32.00m

I used this command to rename the system VG (volume group) to something more generic:

[root]$ vgrename dev-xfce-01-vg system

Rebooting the system at this point is a very bad idea. Take a look at what is now in /dev/mapper, and how that compares to /etc/fstab.

[root]$ ls -alh /dev/mapper
total 0
drwxr-xr-x  2 root root     100 Nov  7 19:45 .
drwxr-xr-x 15 root root    4.1K Nov  7 19:45 ..
crw-------  1 root root 10, 236 Nov  7 19:33 control
lrwxrwxrwx  1 root root       7 Nov  7 19:45 system-root -> ../dm-0
lrwxrwxrwx  1 root root       7 Nov  7 19:45 system-swap_1 -> ../dm-1
[root]$ cat /etc/fstab | grep /dev/mapper
/dev/mapper/dev--xfce--01--vg-root /               ext4    errors=remount-ro 0       1
/dev/mapper/dev--xfce--01--vg-swap_1 none            swap    sw              0       0

So although we changed the name, the mount points are not automatically updated. Let’s change that.

[root]$ vim /etc/fstab

Find any drives that referenced the old VG name, and update to the new /dev/mapper/ path. On a typical system, you will have at least the root and swap paths to change.

We want to be uber sure the changes are correct. Run these informational commands and check your work. The /dev/mapper/ paths must match the entries in the /etc/fstab file.

[root]$ ls -alh /dev/mapper
total 0
drwxr-xr-x  2 root root     100 Nov  7 19:45 .
drwxr-xr-x 15 root root    4.1K Nov  7 19:45 ..
crw-------  1 root root 10, 236 Nov  7 19:33 control
lrwxrwxrwx  1 root root       7 Nov  7 19:45 system-root -> ../dm-0
lrwxrwxrwx  1 root root       7 Nov  7 19:45 system-swap_1 -> ../dm-1
[root]$ cat /etc/fstab | grep /dev/mapper
/dev/mapper/system-root /               ext4    errors=remount-ro 0       1
/dev/mapper/system-swap_1 none            swap    sw              0       0

Much better. Finally, update grub.

[root]$ update-grub

Now, it should be safe to reboot.

This entry was posted in Tips on by .

About Andrew Wells

I have been developing on the LAMP stack since about 2006. I run Ubuntu XFCE on my desktop and have a history of managing Ubuntu and CentOS servers. I code web applications mostly in PHP but have experience with other languages as well. When I'm not working, I can be found working in my home lab or out snowboarding, hiking, camping, or biking depending on the season.

6 thoughts on “Rename a Volume Group in Ubuntu 12.04

  1. Christoipher Lee

    When I tried this, the update-grub step gave an error “probe-grub error: … cannot find canonical path for /dev/mapper/old-name…” After searching in vain for solutions on the web, it occurred to me that I should just edit /boot/grub/grub.cfg to make the same oldname –> newname replacement that I did in /etc/fstab (after all, that’s all that running update-grub would do). That worked great, my renamed system volume booted up fine.

    Reply
    1. Andrew Wells Post author

      Thanks for the info. Just curious, is this on a more recent version of Ubuntu? If so can you let me know what version you had to do this on? I’ll update the article content if that’s the case. Thanks!

      Reply
  2. Joe Rossidivito

    This worked for me on Ubuntu server 14.04. I never had a successful update-grub, even after updating the grub.cfg file. But after restarting everything appears to be operating correctly
    🙂

    Reply
  3. Werner Keil

    Unfortunately the last step caused our Ubuntu 14.04 to become totally unbootable ;-( update-grup also failed with the same message and after reboot it keeps looking for the old lvm path with the old name.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *