1

I've 3 partitions sdb1 sdb2 and sdb3. I wanna to create a volume group and lvms in the sdb3 which is the mounted linux partition where is located my root folder.

I'm typing:

pvcreate /dev/sdb3 

but i get:

Can't open /dev/sdb3 exclusively. Mounted filesystem.

So well, I know that my partition is mounted in fact I'm just working on it. Is there a way to create the volume group without asking my provider to reformat my partitions. I mean through SSH ?

  • What are you trying to do? This seems like a bad, bad idea. – fuero Feb 4 '15 at 22:30
  • You tried to reformat your root partition??? Is it real? And now you ask, why it doesn't work? You had to be thankful to God, that the lvm developers put this check in their code! – peterh - Reinstate Monica Feb 4 '15 at 22:33
  • I'm trying to divide my partition in many LVMs since I need 1 free volume to encrypt my data. – Claudio Ferraro Feb 4 '15 at 22:33
  • sdb3 is the root of the current linux installation. – Claudio Ferraro Feb 4 '15 at 22:34
  • You are trying to change the foundation that the house is already built on top of. Surely you can understand why this is a problem? – Aaron Copley Feb 4 '15 at 22:34
2

You can do that, but it is hard.

The steps are essentially the following:

  1. Clone or create a rescue system on a ramfs, and start it. It must be enough big to be able to get new packages, if you forgot something.
  2. Start it in a chrooted environment.
  3. Start his own ssh daemon on it (which will be run on a port different from 22, of course). Of course, you should test if you can log into this ssh daemon.
  4. Here is the key. It works only on linux, it is named pivot_root. This syscall/tool can change the root partition of your currently running system.
  5. pivot_root /mnt/rescuesys, where your chrooted ramfs rescue system is running. If it succedded, from this point your original system will run in chroot, and your rescue system will run as the real root system.
  6. With a telinit q command restart the init (the process 1) to run also from your real (now ramfs) system and not from the sdb3-based one. Maybe telinit Q, telinit u or telinit U could be also needed for that, it depends on your init system, too.
  7. With an lsof -n|grep /mnt/<oldsysroot> command you can check, if there is any existing open fiedescriptor to your old system. If yes, kill, stop them one by one.
  8. Umount, swapoff, until nothing remains from your old system. If you did everything okay, now you can umount your old sdb3. If not, goto 7 (or even 6).
  9. Backup the contents of your sdb3. You could do this even with a little bit of filesystem resizing, repartitioning, copying, as you have place.
  10. Create your lvm volume with your pvcreate, etc. commands, create the lvs, mount them, and copy your root system back.
  11. Do the 1-9 points again, including the pivot_root. From this point, your real root system is soon the logical volume, which you originally wanted to have.
  12. Destroy your rescue system (as 6-8 point did) to free memory. Don't forget to enable swap. In ideal, security-optimized case it should also live on an encrypted logical volume, despite it degrades speed seriously.
  13. Fix /etc/fstab, reconfigure/reinstall grub, and any similar.
  14. Because you can't be sure, that your system is really bootable, until you didn't booted it, do everything as you can, but try to make your next reboot if you are physically by your server (or, have at least sufficient remote management capabilities, which can be a remote management service of your hosting provider).
| improve this answer | |
  • 1
    +1 for pivot_root, didn't know that. – fuero Feb 4 '15 at 22:43
1

What you suggest shouldn't be done online, as it's error prone and possibly dangerous. You need to resize partitions to do that, you likely lose data when trying to mess with the partition your system's root filesystem is placed on. This is what that check is for.

Use a livecd with gparted to resize your partitions, then setup an encrypted filesystem in the freed up space.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.