How do I combine two logical volumes that reside on a single physical volume in LVM?
Clash Royale CLAN TAG#URR8PPP
up vote
13
down vote
favorite
I have two logical volumes, one is mounted as /, the other is mounted as /home.
I want to combine them, because the /
volume is constantly running out of space. (Yes, I know what's using all that space; no, I can't remove it.)
I'm willing to take the machine down for a day or two to do it.
OS: Linux xxxxx 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(CentOS)
centos lvm
add a comment |
up vote
13
down vote
favorite
I have two logical volumes, one is mounted as /, the other is mounted as /home.
I want to combine them, because the /
volume is constantly running out of space. (Yes, I know what's using all that space; no, I can't remove it.)
I'm willing to take the machine down for a day or two to do it.
OS: Linux xxxxx 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(CentOS)
centos lvm
1
Why not just grow the/
volume, isn't that the point of using LVM?
– jasonwryan
Mar 13 '13 at 19:53
2
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57
add a comment |
up vote
13
down vote
favorite
up vote
13
down vote
favorite
I have two logical volumes, one is mounted as /, the other is mounted as /home.
I want to combine them, because the /
volume is constantly running out of space. (Yes, I know what's using all that space; no, I can't remove it.)
I'm willing to take the machine down for a day or two to do it.
OS: Linux xxxxx 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(CentOS)
centos lvm
I have two logical volumes, one is mounted as /, the other is mounted as /home.
I want to combine them, because the /
volume is constantly running out of space. (Yes, I know what's using all that space; no, I can't remove it.)
I'm willing to take the machine down for a day or two to do it.
OS: Linux xxxxx 2.6.32-279.22.1.el6.x86_64 #1 SMP Wed Feb 6 03:10:46 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux
(CentOS)
centos lvm
centos lvm
asked Mar 13 '13 at 19:08
Nick ODell
9692820
9692820
1
Why not just grow the/
volume, isn't that the point of using LVM?
– jasonwryan
Mar 13 '13 at 19:53
2
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57
add a comment |
1
Why not just grow the/
volume, isn't that the point of using LVM?
– jasonwryan
Mar 13 '13 at 19:53
2
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57
1
1
Why not just grow the
/
volume, isn't that the point of using LVM?– jasonwryan
Mar 13 '13 at 19:53
Why not just grow the
/
volume, isn't that the point of using LVM?– jasonwryan
Mar 13 '13 at 19:53
2
2
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57
add a comment |
4 Answers
4
active
oldest
votes
up vote
9
down vote
accepted
I'm done, and the re-partition worked. However, since there are missing areas in both guides, I am going to summarize what I did. Please note that I have replaced my username with zzzz
and the name of my computer with xxxxxxx
. Also, all commands should be run as root unless otherwise noted.
First, I backed up:
tar -zcvf /media/e14be279-8c11-450a-b52c-1493cff3c632/xxxxxxx-home.tar.gz --exclude=/home/zzzz/Downloads /home
This creates a compressed backup of the /home directory, and puts it on my external drive. (Note that your external drive will have a different path.)
Now, you need to reboot into single-user mode.
reboot
When your computer turns on again, you need to look for a screen like this:
Booting Centos 2.6.32-279.22.1.el6.x86_64 in 3 seconds...
Press any key to interrupt that. You should see a screen like this:
Press a, then Space, then type single
. Hit enter.
You should see a prompt like this:
[root@xxxxxxx /] #
Enter the following commands:
df -h
It should show you Size
, Used
, and Avail
. We're interested in Used
.
Write down how much space is in use by your home volume. We'll need that later.
umount /home
e2fsck -f /dev/mapper/vg_xxxxxxx-lv_home
Remember how much space your home volume used? Double that, and give it to this command. For example, I had 15 gigabytes used by my home directory, so I sized it to 30 gigabytes.
resize2fs /dev/mapper/vg_xxxxxxx-lv_home 30G
Warning: This next step is the one that can lose data. Make sure that you put in a size larger than the previous command. Add 5 Gigabytes to be sure.
lvresize -L 35G vg_xxxxxxx/lv_home
Tell the root partition to use all that space we just freed up.
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
Copy your data to the root partition
mount -t ext4 /dev/mapper/vg_xxxxxxx-lv_home /mnt/home
ls /mnt/home
cp -a /mnt/home/. /home/
(By the way, that -a
is important, because otherwise everything will be owned by root, and you don't want that.)
Do a quick check that the data copied correctly:
ls -lR /home
Now we remove the home partition, and tell root to take the new space again.
umount /mnt/home
lvremove /dev/mapper/vg_xxxxxxx-lv_home
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
At this point, I made a big mistake, one which you can learn from. I rebooted, and when the system came back up, it refused to mount my root partition as read-write because it couldn't mount my /home partition. So, before we reboot, we type
nano /etc/fstab
One of those lines will tell the system to mount the /home partition. Put a #
before it. Press Ctrl-O, Enter, Ctrl-X. Now you can reboot.
(Hypothetically, if you were to forget to edit fstab like I did, the command to mount your root partition is mount -n -o remount -t ext2 /dev/vg_xxxxxxxx/lv_root /
)
love the detail!
– nmr
Oct 19 '15 at 6:51
add a comment |
up vote
3
down vote
WARNING: Backup all critical data before doing anything!
You would need to move all the data from the /home partition to another partition, local partition or external drive or wherever other place you have enough space.
Remove the /home lv and then expand the / (root) lv
Copy the data back to /home directory
Edit 1
The answer above is assuming you don't have enough space in the root partition to place the data in the home partition.
If this is not the case, just mount the home partition somewhere else and copy the data, for example:
umount /home
mount /dev/mapper/lv-home /mnt/home
cp -a /mnt/home/. /home/
Then just remove the home partition and expand the root partition
add a comment |
up vote
3
down vote
You can do it without any external storage, running from /
, but you will need to unmount /home
.
This isn't a particularly risky procedure if you're careful, but nonetheless, the standard advice applies: make backups first, and test them.
I'll use foo
for the volume group name, and root
and home
as the logical volume names. This makes the logical volume paths foo/root
and foo/home
, and the device paths /dev/mapper/foo-root
and /dev/mapper/foo-home
. I assume that they are in the same volume group, otherwise this gets more complicated and is dependent on the physical volume layout of the two volume groups.
First, unmount /home
and run e2fsck -f /dev/mapper/foo-home
. Then shrink the filesystem first, and the logical volume accordingly. Run resize2fs /dev/mapper/foo-home NNNN
where NNNN is the number of blocks you want to retain inside the volume (you can use kB or MB or GB instead with the suffix K
, M
or G
). After shrinking the filesystem, shrink the logical volume with lvresize -L MMMM foo/home
where MMMM is a number of megabytes (note that the default unit is different from resize2fs
, but you can use the same suffixes K
, M
, G
). Be very careful not to shrink the logical volume further than the filesystem — this is the one dangerous step in this procedure.
There is now unused room in the volume group. Run lvresize -l +100%FREE foo/root
to make the root volume grab all the free space in the volume group. Then run resize2fs /dev/mapper/foo-root
(with no size parameter) to enlarge the filesystem to span the whole logical volume; enlarging can be done while the volume is mounted.
You now have room to copy some files. If you don't have enough room for everything, move as much as you can, then repeat the procedure.
Once you've copied all the files out of /home
, you're ready to destroy it. Verify that /home
is empty (if you moved the files) or that all the files in /home
have been copied to /root
(if you copied the files). To destroy the now-unneeded logical volume, run lvremove foo/home
. Finally, enlarge the root volume with lvresize -l 0%FREE foo/root
and its filesystem with resize2fs /dev/mapper/foo-home
.
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
add a comment |
up vote
1
down vote
OK, I found myself in exactly the same position. It seems CentOS creates a small root volume by default and fills the remainder of your space with /home
. I even tested my setup first in a VM but with the smaller disk CentOS didn't create the home volume. I picked up on this problem before becoming space constrained tho' and also figured how not to have to enter single user mode. As follows:
Get access to the machine, ssh is fine (assuming non-root user).
cd /
so you're not in the home directorysudo -s
we'll be root for all of thislsof /home
check that no one is using the home volume, shouldn't bemv
,tar
, or similar the contents of home to somewhere elselvremove centos/home
- Edit
/etc/fstab
and comment out or remove the line for/home
- Move the contents of home that you backed up before back into
/home
- you are now at a safe position, a reboot here should be OK lvresize -l +100%FREE centos/root
xfs_growfs /dev/centos/root
on CentOS 7, others might useresize2fs
df -h
have you succeeded?
Hope this makes it easier for someone. It really is quite amazing what you can do live on filesystems these days.
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
add a comment |
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
9
down vote
accepted
I'm done, and the re-partition worked. However, since there are missing areas in both guides, I am going to summarize what I did. Please note that I have replaced my username with zzzz
and the name of my computer with xxxxxxx
. Also, all commands should be run as root unless otherwise noted.
First, I backed up:
tar -zcvf /media/e14be279-8c11-450a-b52c-1493cff3c632/xxxxxxx-home.tar.gz --exclude=/home/zzzz/Downloads /home
This creates a compressed backup of the /home directory, and puts it on my external drive. (Note that your external drive will have a different path.)
Now, you need to reboot into single-user mode.
reboot
When your computer turns on again, you need to look for a screen like this:
Booting Centos 2.6.32-279.22.1.el6.x86_64 in 3 seconds...
Press any key to interrupt that. You should see a screen like this:
Press a, then Space, then type single
. Hit enter.
You should see a prompt like this:
[root@xxxxxxx /] #
Enter the following commands:
df -h
It should show you Size
, Used
, and Avail
. We're interested in Used
.
Write down how much space is in use by your home volume. We'll need that later.
umount /home
e2fsck -f /dev/mapper/vg_xxxxxxx-lv_home
Remember how much space your home volume used? Double that, and give it to this command. For example, I had 15 gigabytes used by my home directory, so I sized it to 30 gigabytes.
resize2fs /dev/mapper/vg_xxxxxxx-lv_home 30G
Warning: This next step is the one that can lose data. Make sure that you put in a size larger than the previous command. Add 5 Gigabytes to be sure.
lvresize -L 35G vg_xxxxxxx/lv_home
Tell the root partition to use all that space we just freed up.
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
Copy your data to the root partition
mount -t ext4 /dev/mapper/vg_xxxxxxx-lv_home /mnt/home
ls /mnt/home
cp -a /mnt/home/. /home/
(By the way, that -a
is important, because otherwise everything will be owned by root, and you don't want that.)
Do a quick check that the data copied correctly:
ls -lR /home
Now we remove the home partition, and tell root to take the new space again.
umount /mnt/home
lvremove /dev/mapper/vg_xxxxxxx-lv_home
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
At this point, I made a big mistake, one which you can learn from. I rebooted, and when the system came back up, it refused to mount my root partition as read-write because it couldn't mount my /home partition. So, before we reboot, we type
nano /etc/fstab
One of those lines will tell the system to mount the /home partition. Put a #
before it. Press Ctrl-O, Enter, Ctrl-X. Now you can reboot.
(Hypothetically, if you were to forget to edit fstab like I did, the command to mount your root partition is mount -n -o remount -t ext2 /dev/vg_xxxxxxxx/lv_root /
)
love the detail!
– nmr
Oct 19 '15 at 6:51
add a comment |
up vote
9
down vote
accepted
I'm done, and the re-partition worked. However, since there are missing areas in both guides, I am going to summarize what I did. Please note that I have replaced my username with zzzz
and the name of my computer with xxxxxxx
. Also, all commands should be run as root unless otherwise noted.
First, I backed up:
tar -zcvf /media/e14be279-8c11-450a-b52c-1493cff3c632/xxxxxxx-home.tar.gz --exclude=/home/zzzz/Downloads /home
This creates a compressed backup of the /home directory, and puts it on my external drive. (Note that your external drive will have a different path.)
Now, you need to reboot into single-user mode.
reboot
When your computer turns on again, you need to look for a screen like this:
Booting Centos 2.6.32-279.22.1.el6.x86_64 in 3 seconds...
Press any key to interrupt that. You should see a screen like this:
Press a, then Space, then type single
. Hit enter.
You should see a prompt like this:
[root@xxxxxxx /] #
Enter the following commands:
df -h
It should show you Size
, Used
, and Avail
. We're interested in Used
.
Write down how much space is in use by your home volume. We'll need that later.
umount /home
e2fsck -f /dev/mapper/vg_xxxxxxx-lv_home
Remember how much space your home volume used? Double that, and give it to this command. For example, I had 15 gigabytes used by my home directory, so I sized it to 30 gigabytes.
resize2fs /dev/mapper/vg_xxxxxxx-lv_home 30G
Warning: This next step is the one that can lose data. Make sure that you put in a size larger than the previous command. Add 5 Gigabytes to be sure.
lvresize -L 35G vg_xxxxxxx/lv_home
Tell the root partition to use all that space we just freed up.
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
Copy your data to the root partition
mount -t ext4 /dev/mapper/vg_xxxxxxx-lv_home /mnt/home
ls /mnt/home
cp -a /mnt/home/. /home/
(By the way, that -a
is important, because otherwise everything will be owned by root, and you don't want that.)
Do a quick check that the data copied correctly:
ls -lR /home
Now we remove the home partition, and tell root to take the new space again.
umount /mnt/home
lvremove /dev/mapper/vg_xxxxxxx-lv_home
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
At this point, I made a big mistake, one which you can learn from. I rebooted, and when the system came back up, it refused to mount my root partition as read-write because it couldn't mount my /home partition. So, before we reboot, we type
nano /etc/fstab
One of those lines will tell the system to mount the /home partition. Put a #
before it. Press Ctrl-O, Enter, Ctrl-X. Now you can reboot.
(Hypothetically, if you were to forget to edit fstab like I did, the command to mount your root partition is mount -n -o remount -t ext2 /dev/vg_xxxxxxxx/lv_root /
)
love the detail!
– nmr
Oct 19 '15 at 6:51
add a comment |
up vote
9
down vote
accepted
up vote
9
down vote
accepted
I'm done, and the re-partition worked. However, since there are missing areas in both guides, I am going to summarize what I did. Please note that I have replaced my username with zzzz
and the name of my computer with xxxxxxx
. Also, all commands should be run as root unless otherwise noted.
First, I backed up:
tar -zcvf /media/e14be279-8c11-450a-b52c-1493cff3c632/xxxxxxx-home.tar.gz --exclude=/home/zzzz/Downloads /home
This creates a compressed backup of the /home directory, and puts it on my external drive. (Note that your external drive will have a different path.)
Now, you need to reboot into single-user mode.
reboot
When your computer turns on again, you need to look for a screen like this:
Booting Centos 2.6.32-279.22.1.el6.x86_64 in 3 seconds...
Press any key to interrupt that. You should see a screen like this:
Press a, then Space, then type single
. Hit enter.
You should see a prompt like this:
[root@xxxxxxx /] #
Enter the following commands:
df -h
It should show you Size
, Used
, and Avail
. We're interested in Used
.
Write down how much space is in use by your home volume. We'll need that later.
umount /home
e2fsck -f /dev/mapper/vg_xxxxxxx-lv_home
Remember how much space your home volume used? Double that, and give it to this command. For example, I had 15 gigabytes used by my home directory, so I sized it to 30 gigabytes.
resize2fs /dev/mapper/vg_xxxxxxx-lv_home 30G
Warning: This next step is the one that can lose data. Make sure that you put in a size larger than the previous command. Add 5 Gigabytes to be sure.
lvresize -L 35G vg_xxxxxxx/lv_home
Tell the root partition to use all that space we just freed up.
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
Copy your data to the root partition
mount -t ext4 /dev/mapper/vg_xxxxxxx-lv_home /mnt/home
ls /mnt/home
cp -a /mnt/home/. /home/
(By the way, that -a
is important, because otherwise everything will be owned by root, and you don't want that.)
Do a quick check that the data copied correctly:
ls -lR /home
Now we remove the home partition, and tell root to take the new space again.
umount /mnt/home
lvremove /dev/mapper/vg_xxxxxxx-lv_home
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
At this point, I made a big mistake, one which you can learn from. I rebooted, and when the system came back up, it refused to mount my root partition as read-write because it couldn't mount my /home partition. So, before we reboot, we type
nano /etc/fstab
One of those lines will tell the system to mount the /home partition. Put a #
before it. Press Ctrl-O, Enter, Ctrl-X. Now you can reboot.
(Hypothetically, if you were to forget to edit fstab like I did, the command to mount your root partition is mount -n -o remount -t ext2 /dev/vg_xxxxxxxx/lv_root /
)
I'm done, and the re-partition worked. However, since there are missing areas in both guides, I am going to summarize what I did. Please note that I have replaced my username with zzzz
and the name of my computer with xxxxxxx
. Also, all commands should be run as root unless otherwise noted.
First, I backed up:
tar -zcvf /media/e14be279-8c11-450a-b52c-1493cff3c632/xxxxxxx-home.tar.gz --exclude=/home/zzzz/Downloads /home
This creates a compressed backup of the /home directory, and puts it on my external drive. (Note that your external drive will have a different path.)
Now, you need to reboot into single-user mode.
reboot
When your computer turns on again, you need to look for a screen like this:
Booting Centos 2.6.32-279.22.1.el6.x86_64 in 3 seconds...
Press any key to interrupt that. You should see a screen like this:
Press a, then Space, then type single
. Hit enter.
You should see a prompt like this:
[root@xxxxxxx /] #
Enter the following commands:
df -h
It should show you Size
, Used
, and Avail
. We're interested in Used
.
Write down how much space is in use by your home volume. We'll need that later.
umount /home
e2fsck -f /dev/mapper/vg_xxxxxxx-lv_home
Remember how much space your home volume used? Double that, and give it to this command. For example, I had 15 gigabytes used by my home directory, so I sized it to 30 gigabytes.
resize2fs /dev/mapper/vg_xxxxxxx-lv_home 30G
Warning: This next step is the one that can lose data. Make sure that you put in a size larger than the previous command. Add 5 Gigabytes to be sure.
lvresize -L 35G vg_xxxxxxx/lv_home
Tell the root partition to use all that space we just freed up.
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
Copy your data to the root partition
mount -t ext4 /dev/mapper/vg_xxxxxxx-lv_home /mnt/home
ls /mnt/home
cp -a /mnt/home/. /home/
(By the way, that -a
is important, because otherwise everything will be owned by root, and you don't want that.)
Do a quick check that the data copied correctly:
ls -lR /home
Now we remove the home partition, and tell root to take the new space again.
umount /mnt/home
lvremove /dev/mapper/vg_xxxxxxx-lv_home
lvresize -l +100%FREE vg_xxxxxxx/lv_root
resize2fs /dev/mapper/vg_xxxxxxx-lv_root
At this point, I made a big mistake, one which you can learn from. I rebooted, and when the system came back up, it refused to mount my root partition as read-write because it couldn't mount my /home partition. So, before we reboot, we type
nano /etc/fstab
One of those lines will tell the system to mount the /home partition. Put a #
before it. Press Ctrl-O, Enter, Ctrl-X. Now you can reboot.
(Hypothetically, if you were to forget to edit fstab like I did, the command to mount your root partition is mount -n -o remount -t ext2 /dev/vg_xxxxxxxx/lv_root /
)
edited Feb 14 '15 at 2:08
answered Mar 14 '13 at 21:19
Nick ODell
9692820
9692820
love the detail!
– nmr
Oct 19 '15 at 6:51
add a comment |
love the detail!
– nmr
Oct 19 '15 at 6:51
love the detail!
– nmr
Oct 19 '15 at 6:51
love the detail!
– nmr
Oct 19 '15 at 6:51
add a comment |
up vote
3
down vote
WARNING: Backup all critical data before doing anything!
You would need to move all the data from the /home partition to another partition, local partition or external drive or wherever other place you have enough space.
Remove the /home lv and then expand the / (root) lv
Copy the data back to /home directory
Edit 1
The answer above is assuming you don't have enough space in the root partition to place the data in the home partition.
If this is not the case, just mount the home partition somewhere else and copy the data, for example:
umount /home
mount /dev/mapper/lv-home /mnt/home
cp -a /mnt/home/. /home/
Then just remove the home partition and expand the root partition
add a comment |
up vote
3
down vote
WARNING: Backup all critical data before doing anything!
You would need to move all the data from the /home partition to another partition, local partition or external drive or wherever other place you have enough space.
Remove the /home lv and then expand the / (root) lv
Copy the data back to /home directory
Edit 1
The answer above is assuming you don't have enough space in the root partition to place the data in the home partition.
If this is not the case, just mount the home partition somewhere else and copy the data, for example:
umount /home
mount /dev/mapper/lv-home /mnt/home
cp -a /mnt/home/. /home/
Then just remove the home partition and expand the root partition
add a comment |
up vote
3
down vote
up vote
3
down vote
WARNING: Backup all critical data before doing anything!
You would need to move all the data from the /home partition to another partition, local partition or external drive or wherever other place you have enough space.
Remove the /home lv and then expand the / (root) lv
Copy the data back to /home directory
Edit 1
The answer above is assuming you don't have enough space in the root partition to place the data in the home partition.
If this is not the case, just mount the home partition somewhere else and copy the data, for example:
umount /home
mount /dev/mapper/lv-home /mnt/home
cp -a /mnt/home/. /home/
Then just remove the home partition and expand the root partition
WARNING: Backup all critical data before doing anything!
You would need to move all the data from the /home partition to another partition, local partition or external drive or wherever other place you have enough space.
Remove the /home lv and then expand the / (root) lv
Copy the data back to /home directory
Edit 1
The answer above is assuming you don't have enough space in the root partition to place the data in the home partition.
If this is not the case, just mount the home partition somewhere else and copy the data, for example:
umount /home
mount /dev/mapper/lv-home /mnt/home
cp -a /mnt/home/. /home/
Then just remove the home partition and expand the root partition
edited Mar 13 '13 at 20:38
Stéphane Chazelas
295k54555898
295k54555898
answered Mar 13 '13 at 19:22
ghm1014
98778
98778
add a comment |
add a comment |
up vote
3
down vote
You can do it without any external storage, running from /
, but you will need to unmount /home
.
This isn't a particularly risky procedure if you're careful, but nonetheless, the standard advice applies: make backups first, and test them.
I'll use foo
for the volume group name, and root
and home
as the logical volume names. This makes the logical volume paths foo/root
and foo/home
, and the device paths /dev/mapper/foo-root
and /dev/mapper/foo-home
. I assume that they are in the same volume group, otherwise this gets more complicated and is dependent on the physical volume layout of the two volume groups.
First, unmount /home
and run e2fsck -f /dev/mapper/foo-home
. Then shrink the filesystem first, and the logical volume accordingly. Run resize2fs /dev/mapper/foo-home NNNN
where NNNN is the number of blocks you want to retain inside the volume (you can use kB or MB or GB instead with the suffix K
, M
or G
). After shrinking the filesystem, shrink the logical volume with lvresize -L MMMM foo/home
where MMMM is a number of megabytes (note that the default unit is different from resize2fs
, but you can use the same suffixes K
, M
, G
). Be very careful not to shrink the logical volume further than the filesystem — this is the one dangerous step in this procedure.
There is now unused room in the volume group. Run lvresize -l +100%FREE foo/root
to make the root volume grab all the free space in the volume group. Then run resize2fs /dev/mapper/foo-root
(with no size parameter) to enlarge the filesystem to span the whole logical volume; enlarging can be done while the volume is mounted.
You now have room to copy some files. If you don't have enough room for everything, move as much as you can, then repeat the procedure.
Once you've copied all the files out of /home
, you're ready to destroy it. Verify that /home
is empty (if you moved the files) or that all the files in /home
have been copied to /root
(if you copied the files). To destroy the now-unneeded logical volume, run lvremove foo/home
. Finally, enlarge the root volume with lvresize -l 0%FREE foo/root
and its filesystem with resize2fs /dev/mapper/foo-home
.
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
add a comment |
up vote
3
down vote
You can do it without any external storage, running from /
, but you will need to unmount /home
.
This isn't a particularly risky procedure if you're careful, but nonetheless, the standard advice applies: make backups first, and test them.
I'll use foo
for the volume group name, and root
and home
as the logical volume names. This makes the logical volume paths foo/root
and foo/home
, and the device paths /dev/mapper/foo-root
and /dev/mapper/foo-home
. I assume that they are in the same volume group, otherwise this gets more complicated and is dependent on the physical volume layout of the two volume groups.
First, unmount /home
and run e2fsck -f /dev/mapper/foo-home
. Then shrink the filesystem first, and the logical volume accordingly. Run resize2fs /dev/mapper/foo-home NNNN
where NNNN is the number of blocks you want to retain inside the volume (you can use kB or MB or GB instead with the suffix K
, M
or G
). After shrinking the filesystem, shrink the logical volume with lvresize -L MMMM foo/home
where MMMM is a number of megabytes (note that the default unit is different from resize2fs
, but you can use the same suffixes K
, M
, G
). Be very careful not to shrink the logical volume further than the filesystem — this is the one dangerous step in this procedure.
There is now unused room in the volume group. Run lvresize -l +100%FREE foo/root
to make the root volume grab all the free space in the volume group. Then run resize2fs /dev/mapper/foo-root
(with no size parameter) to enlarge the filesystem to span the whole logical volume; enlarging can be done while the volume is mounted.
You now have room to copy some files. If you don't have enough room for everything, move as much as you can, then repeat the procedure.
Once you've copied all the files out of /home
, you're ready to destroy it. Verify that /home
is empty (if you moved the files) or that all the files in /home
have been copied to /root
(if you copied the files). To destroy the now-unneeded logical volume, run lvremove foo/home
. Finally, enlarge the root volume with lvresize -l 0%FREE foo/root
and its filesystem with resize2fs /dev/mapper/foo-home
.
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
add a comment |
up vote
3
down vote
up vote
3
down vote
You can do it without any external storage, running from /
, but you will need to unmount /home
.
This isn't a particularly risky procedure if you're careful, but nonetheless, the standard advice applies: make backups first, and test them.
I'll use foo
for the volume group name, and root
and home
as the logical volume names. This makes the logical volume paths foo/root
and foo/home
, and the device paths /dev/mapper/foo-root
and /dev/mapper/foo-home
. I assume that they are in the same volume group, otherwise this gets more complicated and is dependent on the physical volume layout of the two volume groups.
First, unmount /home
and run e2fsck -f /dev/mapper/foo-home
. Then shrink the filesystem first, and the logical volume accordingly. Run resize2fs /dev/mapper/foo-home NNNN
where NNNN is the number of blocks you want to retain inside the volume (you can use kB or MB or GB instead with the suffix K
, M
or G
). After shrinking the filesystem, shrink the logical volume with lvresize -L MMMM foo/home
where MMMM is a number of megabytes (note that the default unit is different from resize2fs
, but you can use the same suffixes K
, M
, G
). Be very careful not to shrink the logical volume further than the filesystem — this is the one dangerous step in this procedure.
There is now unused room in the volume group. Run lvresize -l +100%FREE foo/root
to make the root volume grab all the free space in the volume group. Then run resize2fs /dev/mapper/foo-root
(with no size parameter) to enlarge the filesystem to span the whole logical volume; enlarging can be done while the volume is mounted.
You now have room to copy some files. If you don't have enough room for everything, move as much as you can, then repeat the procedure.
Once you've copied all the files out of /home
, you're ready to destroy it. Verify that /home
is empty (if you moved the files) or that all the files in /home
have been copied to /root
(if you copied the files). To destroy the now-unneeded logical volume, run lvremove foo/home
. Finally, enlarge the root volume with lvresize -l 0%FREE foo/root
and its filesystem with resize2fs /dev/mapper/foo-home
.
You can do it without any external storage, running from /
, but you will need to unmount /home
.
This isn't a particularly risky procedure if you're careful, but nonetheless, the standard advice applies: make backups first, and test them.
I'll use foo
for the volume group name, and root
and home
as the logical volume names. This makes the logical volume paths foo/root
and foo/home
, and the device paths /dev/mapper/foo-root
and /dev/mapper/foo-home
. I assume that they are in the same volume group, otherwise this gets more complicated and is dependent on the physical volume layout of the two volume groups.
First, unmount /home
and run e2fsck -f /dev/mapper/foo-home
. Then shrink the filesystem first, and the logical volume accordingly. Run resize2fs /dev/mapper/foo-home NNNN
where NNNN is the number of blocks you want to retain inside the volume (you can use kB or MB or GB instead with the suffix K
, M
or G
). After shrinking the filesystem, shrink the logical volume with lvresize -L MMMM foo/home
where MMMM is a number of megabytes (note that the default unit is different from resize2fs
, but you can use the same suffixes K
, M
, G
). Be very careful not to shrink the logical volume further than the filesystem — this is the one dangerous step in this procedure.
There is now unused room in the volume group. Run lvresize -l +100%FREE foo/root
to make the root volume grab all the free space in the volume group. Then run resize2fs /dev/mapper/foo-root
(with no size parameter) to enlarge the filesystem to span the whole logical volume; enlarging can be done while the volume is mounted.
You now have room to copy some files. If you don't have enough room for everything, move as much as you can, then repeat the procedure.
Once you've copied all the files out of /home
, you're ready to destroy it. Verify that /home
is empty (if you moved the files) or that all the files in /home
have been copied to /root
(if you copied the files). To destroy the now-unneeded logical volume, run lvremove foo/home
. Finally, enlarge the root volume with lvresize -l 0%FREE foo/root
and its filesystem with resize2fs /dev/mapper/foo-home
.
edited Mar 14 '13 at 19:06
answered Mar 13 '13 at 22:20
Gilles
522k12610401575
522k12610401575
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
add a comment |
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: /home refused to unmount until I rebooted into single-user mode.
– Nick ODell
Mar 14 '13 at 1:59
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Note: It's referred to as vg_(machine name) and lv_home
– Nick ODell
Mar 14 '13 at 2:19
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
Ok, I got it working. There were a few details missing from this guide though, so I'll post my full command history soon.
– Nick ODell
Mar 14 '13 at 3:37
add a comment |
up vote
1
down vote
OK, I found myself in exactly the same position. It seems CentOS creates a small root volume by default and fills the remainder of your space with /home
. I even tested my setup first in a VM but with the smaller disk CentOS didn't create the home volume. I picked up on this problem before becoming space constrained tho' and also figured how not to have to enter single user mode. As follows:
Get access to the machine, ssh is fine (assuming non-root user).
cd /
so you're not in the home directorysudo -s
we'll be root for all of thislsof /home
check that no one is using the home volume, shouldn't bemv
,tar
, or similar the contents of home to somewhere elselvremove centos/home
- Edit
/etc/fstab
and comment out or remove the line for/home
- Move the contents of home that you backed up before back into
/home
- you are now at a safe position, a reboot here should be OK lvresize -l +100%FREE centos/root
xfs_growfs /dev/centos/root
on CentOS 7, others might useresize2fs
df -h
have you succeeded?
Hope this makes it easier for someone. It really is quite amazing what you can do live on filesystems these days.
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
add a comment |
up vote
1
down vote
OK, I found myself in exactly the same position. It seems CentOS creates a small root volume by default and fills the remainder of your space with /home
. I even tested my setup first in a VM but with the smaller disk CentOS didn't create the home volume. I picked up on this problem before becoming space constrained tho' and also figured how not to have to enter single user mode. As follows:
Get access to the machine, ssh is fine (assuming non-root user).
cd /
so you're not in the home directorysudo -s
we'll be root for all of thislsof /home
check that no one is using the home volume, shouldn't bemv
,tar
, or similar the contents of home to somewhere elselvremove centos/home
- Edit
/etc/fstab
and comment out or remove the line for/home
- Move the contents of home that you backed up before back into
/home
- you are now at a safe position, a reboot here should be OK lvresize -l +100%FREE centos/root
xfs_growfs /dev/centos/root
on CentOS 7, others might useresize2fs
df -h
have you succeeded?
Hope this makes it easier for someone. It really is quite amazing what you can do live on filesystems these days.
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
add a comment |
up vote
1
down vote
up vote
1
down vote
OK, I found myself in exactly the same position. It seems CentOS creates a small root volume by default and fills the remainder of your space with /home
. I even tested my setup first in a VM but with the smaller disk CentOS didn't create the home volume. I picked up on this problem before becoming space constrained tho' and also figured how not to have to enter single user mode. As follows:
Get access to the machine, ssh is fine (assuming non-root user).
cd /
so you're not in the home directorysudo -s
we'll be root for all of thislsof /home
check that no one is using the home volume, shouldn't bemv
,tar
, or similar the contents of home to somewhere elselvremove centos/home
- Edit
/etc/fstab
and comment out or remove the line for/home
- Move the contents of home that you backed up before back into
/home
- you are now at a safe position, a reboot here should be OK lvresize -l +100%FREE centos/root
xfs_growfs /dev/centos/root
on CentOS 7, others might useresize2fs
df -h
have you succeeded?
Hope this makes it easier for someone. It really is quite amazing what you can do live on filesystems these days.
OK, I found myself in exactly the same position. It seems CentOS creates a small root volume by default and fills the remainder of your space with /home
. I even tested my setup first in a VM but with the smaller disk CentOS didn't create the home volume. I picked up on this problem before becoming space constrained tho' and also figured how not to have to enter single user mode. As follows:
Get access to the machine, ssh is fine (assuming non-root user).
cd /
so you're not in the home directorysudo -s
we'll be root for all of thislsof /home
check that no one is using the home volume, shouldn't bemv
,tar
, or similar the contents of home to somewhere elselvremove centos/home
- Edit
/etc/fstab
and comment out or remove the line for/home
- Move the contents of home that you backed up before back into
/home
- you are now at a safe position, a reboot here should be OK lvresize -l +100%FREE centos/root
xfs_growfs /dev/centos/root
on CentOS 7, others might useresize2fs
df -h
have you succeeded?
Hope this makes it easier for someone. It really is quite amazing what you can do live on filesystems these days.
answered Apr 18 '15 at 7:53
Damon Maria
1265
1265
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
add a comment |
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
It's definitely easier if you don't need to migrate any data. :)
– Nick ODell
Apr 18 '15 at 8:06
add a comment |
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f67822%2fhow-do-i-combine-two-logical-volumes-that-reside-on-a-single-physical-volume-in%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Why not just grow the
/
volume, isn't that the point of using LVM?– jasonwryan
Mar 13 '13 at 19:53
2
@jasonwryan Why should I need to manually adjust how disk space is allocated? Isn't that the whole point of a filesystem?
– Nick ODell
Mar 13 '13 at 19:56
@NickODell No. If one volume is too small to hold the data, then it's just too small. Overall capacity is a factor of volume size, not filesystem size. Logical volumes do make it easier to resize the mounted volumes and to merge disparate storage resources into a single volume, though. With LVM you should be able to do what jasonwryan is suggesting without even rebooting: make sure regular users are logged off (to free /home) umount /home lvreduce it (don't forget -r) re-mount it then do an lvextend on the root filesystem and you're done. If you want to merge you have to do an rsync.
– Bratchley
Mar 21 '13 at 13:10
@JoelDavis If I require that all users to log out, is it relevant whether need to I reboot?
– Nick ODell
Mar 21 '13 at 20:44
@NickODell Um...yeah? Most linux systems are servers, you should realize that will be people's assumption unless you say otherwise.
– Bratchley
Mar 21 '13 at 23:57