Thursday, October 17, 2019

Resizing pre-installed and mounted raid partitions for LVM use

Every time we order a new server from a new provider or even just with a new distro we run into inconsistencies. Meaning even though we go for a minimal distro the server will come with unwanted configurations. In this case I am talking about a server with 2x4TB HDDs that come pre-installed in a raid 1 configuration.
The raid also seems to be configured sensibly.
lsblkreturns the following:



NAME    MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
sda 8:0 0 3.7T 0 disk

├─sda1 8:1 0 16G 0 part
│ └─md0 9:0 0 16G 0 raid1 [SWAP]
├─sda2 8:2 0 512M 0 part
│ └─md1 9:1 0 511.4M 0 raid1 /boot
├─sda3 8:3 0 2T 0 part
│ └─md2 9:2 0 2T 0 raid1 /
├─sda4 8:4 0 1.7T 0 part
│ └─md3 9:3 0 1.7T 0 raid1 /home
└─sda5 8:5 0 1M 0 part
sdb 8:16 0 3.7T 0 disk

├─sdb1 8:17 0 16G 0 part
│ └─md0 9:0 0 16G 0 raid1 [SWAP]
├─sdb2 8:18 0 512M 0 part
│ └─md1 9:1 0 511.4M 0 raid1 /boot
├─sdb3 8:19 0 2T 0 part
│ └─md2 9:2 0 2T 0 raid1 /
├─sdb4 8:20 0 1.7T 0 part
│ └─md3 9:3 0 1.7T 0 raid1 /home
└─sdb5 8:21 0 1M 0 part



As you can see the largest partition of 2TB is mounted at /.
This means it is currently housing and running most of the system.
Now, I plan to add a LVM abstraction layer to the server to have more/better control over my storage. I can of course not umount /dev/md2 since it is busy.
So my question is: How do I properly and safely access the space (or some of it) on /dev/md2 in order to add it to my LVM configuration?
Is it even possible to have a logical volume mounted at / if it has not been configured during setup (due to image rather than manual install)? If so, how do I not lose data when mounting a LV at /, or more specifically how can I mount a LV on an already existing folder and "transfer" the data inside?
Am I missing something or going about it wrong? Any help is greatly appreciated.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...