1

So this is what i want to achieve,

  • Unmount home partition at /home
  • Remove home logical volume /dev/cl/home
  • create new home logical volume from the same volume group cl and name home
  • make xfs filesystem
  • mount the new logical volume at /home.

for that i wrote this bash script

umount -v /home/
if [ $? -ne 0 ]
then
  echo "Couldn't not unmount /home"
  exit 1
fi

# delete
lvremove /dev/cl/home

if [ $? -ne 0 ]
then
  echo "Couldn't delete LVM /dev/cl/home."
  exit 1
fi

# create home
lvcreate -L2G -n home cl

if [ $? -ne 0 ]
then
  echo "Couldn't create a new LVM /dev/cl/home."
  exit 1
fi

mkfs.xfs /dev/cl/home

if [ $? -ne 0 ]
then
  echo "Couldn't create a file system for /dev/cl/home."
  exit 1
fi

# restore home
mount /dev/cl/home /home/

the script fails at the line mkfs.xfs /dev/cl/home with msg mkfs.xfs: /dev/cl/home contains a mounted filesystem, it seems lvcreate -L2G -n home cl doesn't really create a new logical volume it just retrieves the previously removed logical volume with the same filesystem and mount it at the same mounting point /home, what could possible cause this?

  • If you dont want the previous data, you could try the -f option of mkfs.xfs. It will format the LV anyway. From man mkfs.ext4 "-f Force overwrite when an existing filesystem is detected on the device. By default, mkfs.xfs will not write to the device if it suspects that there is a filesystem or partition table on the device already." – varun Dec 29 '16 at 5:36
  • i don't have this problem anymore and i did try with the -f option, it never helped though – ahmedjaad Dec 29 '16 at 9:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.