Add rename-vg.sh
This commit is contained in:
commit
db02c24d14
54
rename-vg.sh
Normal file
54
rename-vg.sh
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# Script per rinominare i volumes group su VM Debian
|
||||||
|
# Autore: Mattia Tadini
|
||||||
|
# Nome File: rename-vg.sh
|
||||||
|
# Revisione: 1.0
|
||||||
|
|
||||||
|
# Must be run with root permissions
|
||||||
|
# sudo will be sufficient
|
||||||
|
if [ "$(id -u)" -ne 0 ]; then
|
||||||
|
echo "This script must be run as root" 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Ask for new hostname $newhost
|
||||||
|
echo Set a New Volume Group Name:
|
||||||
|
read newhostname -p "Enter new hostname: "
|
||||||
|
#oldhostname=$(cat /etc/hostname)
|
||||||
|
|
||||||
|
echo Changing LVM names
|
||||||
|
# ${var//-} syntax removes all dashes from the name simplifying the
|
||||||
|
# requirement to use a double-dash in some places to escape the dash
|
||||||
|
newvg=${newhostname//-}
|
||||||
|
|
||||||
|
# Find the volume group that root is in
|
||||||
|
vg=$(lvdisplay -C | awk '$1=="root" {print $2}')
|
||||||
|
echo "old vg name: " $vg
|
||||||
|
echo "new vg name: " $newvg
|
||||||
|
if [[ ${vg} == *"-"* ]]; then
|
||||||
|
# has dashes in current name
|
||||||
|
vgrename ${vg} ${newhostname//-}
|
||||||
|
vg=${vg//-/--}
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /etc/fstab
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /boot/grub/grub.cfg
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /etc/initramfs-tools/conf.d/resume
|
||||||
|
else
|
||||||
|
# no dashes in current name
|
||||||
|
vgrename ${vg} ${newvg}
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /etc/fstab
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /boot/grub/grub.cfg
|
||||||
|
sed -i "s/${vg}/${newvg}/g" /etc/initramfs-tools/conf.d/resume
|
||||||
|
fi
|
||||||
|
|
||||||
|
#check files
|
||||||
|
echo fstab update:
|
||||||
|
grep ${newvg} /etc/fstab
|
||||||
|
|
||||||
|
echo grub.cfg update:
|
||||||
|
grep ${newvg} /boot/grub/grub.cfg
|
||||||
|
|
||||||
|
echo resume update:
|
||||||
|
grep ${newvg} /etc/initramfs-tools/conf.d/resume
|
||||||
|
|
||||||
|
echo update initramfs
|
||||||
|
update-initramfs -c -k all
|
||||||
Loading…
Reference in New Issue
Block a user