Can't open /dev/xxx exclusively. Mounted filesystem. How to create volume groups and lvm on mounted disk?
2,142
Solution 1
You can do that, but it is hard.
The steps are essentially the following:
- 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.
- Start it in a chrooted environment.
- 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.
- 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. 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.- 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. Maybetelinit Q
,telinit u
ortelinit U
could be also needed for that, it depends on your init system, too. - 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. - 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).
- Backup the contents of your sdb3. You could do this even with a little bit of filesystem resizing, repartitioning, copying, as you have place.
- Create your lvm volume with your
pvcreate
, etc. commands, create the lvs, mount them, and copy your root system back. - 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. - 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.
- Fix
/etc/fstab
, reconfigure/reinstall grub, and any similar. - 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).
Solution 2
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.
Related videos on Youtube
Author by
TruMan1
Updated on September 18, 2022Comments
-
TruMan1 over 1 year
The
TabView
seems to stretch to its maximum height, but I'd like it to shorten to height as much as it requires instead of empty space. This is what it looks like even tho there areSpacer
views around it:struct ContentView: View { var body: some View { Text("Some text") Text("Some text") Text("Some text") Spacer() TabView { GroupBox(label: Text("This is the title 1")) { Label("Some item 1", systemImage: "checkmark.circle.fill") Label("Some item 2", systemImage: "checkmark.circle.fill") Label("Some item 3", systemImage: "checkmark.circle.fill") Label("Some item 4", systemImage: "checkmark.circle.fill") } .padding() GroupBox(label: Text("This is the title 2")) { Label("Some item 1", systemImage: "checkmark.circle.fill") Label("Some item 2", systemImage: "checkmark.circle.fill") Label("Some item 3", systemImage: "checkmark.circle.fill") Label("Some item 4", systemImage: "checkmark.circle.fill") } .padding() GroupBox(label: Text("This is the title 3")) { Label("Some item 1", systemImage: "checkmark.circle.fill") Label("Some item 2", systemImage: "checkmark.circle.fill") Label("Some item 3", systemImage: "checkmark.circle.fill") Label("Some item 4", systemImage: "checkmark.circle.fill") } .padding() } .tabViewStyle(PageTabViewStyle()) .background(Color.yellow) Spacer() Text("Some text") Text("Some text") Text("Some text") } }
Is there a way to dynamically tighten the height to what's needed by its children?
-
fuero over 9 yearsWhat are you trying to do? This seems like a bad, bad idea.
-
peterh over 9 yearsYou 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!
-
Claudio Ferraro over 9 yearsI'm trying to divide my partition in many LVMs since I need 1 free volume to encrypt my data.
-
Claudio Ferraro over 9 yearssdb3 is the root of the current linux installation.
-
Aaron Copley over 9 yearsYou are trying to change the foundation that the house is already built on top of. Surely you can understand why this is a problem?
-
fuero over 9 years@ClaudioFerraro get the gparted livecd and use that.
-
Claudio Ferraro over 9 yearsto run gparted I need access to the server. So I need to call my provider . or not ?
-
mahan about 3 yearsDid my answer fix the issue?
-
TruMan1 about 3 yearsIt caused weird layout issues, probably more related to my specific app. But did get me closer.. Thx!
-
-
peterh over 9 yearsCurrently I am writing him, how can it be done.
-
fuero over 9 yearsedited the answer to suggest that doing it online is dangerous.
-
peterh over 9 yearsOf course. Very.
-
fuero over 9 years+1 for
pivot_root
, didn't know that. -
Duc Dang over 1 yearnot working, my tabview disappeared
-
Peter Lapisu over 1 yearthis does no longer work