Некоторые установщики Linux создают большой раздел /home, если для системных служб необходимо больше места на разделе / (root), можно изменить конфигурацию LVM разделов без перезагрузки сервера.
До изменений раздел / (root) заполнен на 98%, и имеются свободные 141GB на партиции /home
[root@oracle ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_oracle-lv_root 50G 1G 50G 98% / tmpfs 630M 0 630M 0% /dev/shm /dev/cciss/c0d0p1 477M 106M 346M 24% /boot /dev/mapper/vg_oracle-lv_home 149G 60M 141G 1% /home
1. Отмонтируем раздел /home
umount /home
Для успешного отключения раздела, остановите сервисы работающие на нем, а также выйдите из системы всеми пользователями кроме root
2. Уменьшаем размер раздела /home до 20GB, (Система попросит провести проверку тома коммандой e2fsck)
e2fsck -f /dev/mapper/vg_oracle-lv_home resize2fs /dev/mapper/vg_oracle-lv_home 20G
3. Уменьшаем LVM том /dev/mapper/vg_oracle-lv_home до 20G
lvreduce -L 20G /dev/mapper/vg_oracle-lv_home
4. Расширяем LVM том /dev/mapper/vg_oracle-lv_root до максимально возможного размера.
lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root
5. Увеличиваем раздел /root (ext3/4) используя все свободное место.
resize2fs /dev/mapper/vg_oracle-lv_root
6. Монтируем /home
mount /home
Результат:
[root@oracle ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_oracle-lv_root 178G 50G 128G 28% / tmpfs 630M 0 630M 0% /dev/shm /dev/cciss/c0d0p1 477M 106M 346M 24% /boot /dev/mapper/vg_oracle-lv_home 20G 45M 19G 1% /home
Теперь в корневом разделе сервера 72% свободного места.
TL;DR
Уменьшение раздела /home (/dev/mapper/vg_oracle-lv_home) до 20GB и перенос свободного места в корневой раздел диска /root (/dev/mapper/vg_oracle-lv_root):
umount /home e2fsck -f /dev/mapper/vg_oracle-lv_home resize2fs /dev/mapper/vg_oracle-lv_home 20G lvreduce -L 20G /dev/mapper/vg_oracle-lv_home lvextend -l +100%FREE /dev/mapper/vg_oracle-lv_root resize2fs /dev/mapper/vg_oracle-lv_root mount /home
Your heading «_online_ resize…» is misleading because your first
(and necessary) step is unmounting /home.
Online shrinking of LVM partitions is not possible.
I stumbled over this page because I saw «online» and «shrink»
and thought «Oooh something new I have missed something».
🙂 Olaf
sorry for confusion, I agree it is partially online — at least you don’t need to unmount root 🙂
Firstly, thanks for the information. Worked perfect for me and now have plenty of room to store under /root folder. Probably would of been easier for me to set the partitions correctly when I installed fedora but hey no-ones perfect…
Had all sorts of trouble trying to do this on my system to start with because I was logged in.
Recommend to all to use rescue mode boot from usb/cd. This ensured no users being logged in and no files being used in /home directory. Also means you don’t have to carry out ‘lazy’ umount on /home.
Thank you very much,
just resized my filesystem with no issues.
Worked perfectly for me. Thanks for putting this up!
I cannot unmount my /home. It says «device is busy». How do I deal with this
This is common error, try following:
1. change your directory to something not /home (cd /root)
2. check who is logged in to the box by running who, ask them to log off/ kill their pts process (ps -dN|grep pts/3)
3. if you have services running from home, stop them
perfect documents sucessfully shirnk home partition and increase root on centos 6.5
I have applied this in my Centos (2.6.32-431.29.2.el6.x86_64) server and it works fine !!
Thanks
It worked flawlessly on OEL 6.8.Thanks for the excellent tip
I closely followed the instructions, but have an issue after step 2.
I successfully (without errors) ran
e2fsck -f /dev/my_home
resize2fs /dev/my_home 426G
The initial size of /home was 436G, so I tried to reduce by about 10G. I still had about 40G free space in /home.
When I want to run
lvreduce -L 426G /dev/my_home
I obtain an error that the location does not exists. Checking with
df
shows that /dev/my_home does not exist anymore. Any idea what happened?
check dmesg for any errors