3

I have a debian linux with this output of df command:

root@debian:~# df -Th
Filesystem                  Type      Size  Used Avail Use% Mounted on
udev                        devtmpfs  973M     0  973M   0% /dev
tmpfs                       tmpfs     198M  3.0M  195M   2% /run
/dev/mapper/debian--vg-root ext4       17G  1.3G   15G   9% /
tmpfs                       tmpfs     987M     0  987M   0% /dev/shm
tmpfs                       tmpfs     5.0M     0  5.0M   0% /run/lock
tmpfs                       tmpfs     987M     0  987M   0% /sys/fs/cgroup
/dev/sda1                   ext2      236M   77M  147M  35% /boot
/dev/mapper/debian--vg-home ext4       31G   49M   29G   1% /home
tmpfs                       tmpfs     198M     0  198M   0% /run/user/0

How can I reduce or expand the size of / partition. I am not allowed to use umount command. How is it possible?

Update

You see I can't use umount command here. So this is not possible to use e2fsck and resize2fs commands.

Update2

This is the more detailed:

root@debian:~# vgs
  VG        #PV #LV #SN Attr   VSize   VFree
  debian-vg   1   3   0 wz--n- <49.76g    0 
root@debian:~# lsblk
NAME                  MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                     8:0    0   50G  0 disk 
├─sda1                  8:1    0  243M  0 part /boot
├─sda2                  8:2    0    1K  0 part 
└─sda5                  8:5    0 49.8G  0 part 
  ├─debian--vg-root   254:0    0 16.6G  0 lvm  /
  ├─debian--vg-swap_1 254:1    0    2G  0 lvm  [SWAP]
  └─debian--vg-home   254:2    0 31.2G  0 lvm  /home
sr0                    11:0    1  319M  0 rom  
Valentin Bajrami
  • 9,244
  • 3
  • 25
  • 38
yasin
  • 65
  • 2
  • 7
  • `ext4` will allow you to grow the file system while mounted. Shrinking requires the file system to be unmounted. Do you want to grow the partition, or shrink it? – Haxiel Dec 04 '18 at 11:13
  • @Haxiel, thank you for response. Would you please tell me both growing and shrinking solutions? – yasin Dec 04 '18 at 11:37
  • @yasin can you update your question and show the output of `lsblk` and `vgs`. Also do you want to `expand` or `shrink` the partition? I didn't get that from your question though – Valentin Bajrami Dec 04 '18 at 11:45
  • @ValentinBajrami, I have updated the question. This is a practice so I would be thankful if you can tell both expanding and shrinking methods. – yasin Dec 04 '18 at 11:53
  • There are a lot of tutorials for this already, for example https://askubuntu.com/questions/24027/how-can-i-resize-an-ext-root-partition-at-runtime – Panki Dec 04 '18 at 12:24
  • @Panki, I want to reduce / size and add it to /home for example!! This is not related to my question – yasin Dec 04 '18 at 12:30
  • 2
    You cannot shrink the root filesystem online. You will need to boot from some rescue medium so that you can access the root filesystem while it is not mounted. – wurtel Dec 04 '18 at 12:34
  • @wurtel, You mean I have to use live linx for doing that? – yasin Dec 04 '18 at 12:35
  • 1
    @Panki. This is fairly easy. You need to boot from a `Live USB` or a `Live CD`. This doesn't have to match your current OS though. Then once you've booted you can just run `lvresize -r -L -5G /dev/mapper/debian-vg-root` This will perform the shrinking of the file system as well as the disk size – Valentin Bajrami Dec 04 '18 at 12:36
  • 1
    Where `-5G` is your desired number of gibibytes to shrink! – Valentin Bajrami Dec 04 '18 at 12:37
  • @Panki, Thank you, you can put it in answer part in more detailed to be accepted – yasin Dec 04 '18 at 12:38

1 Answers1

3

Ok, so here is a recap.

First download a Live ISO so you can boot from. For example if you are using a Debian operating system you could e.g download a CentOS Live iso to boot from.

Once you've booted just become super user by typing sudo su

To locate your exact Logical volume name issue the following commands (as displayed in your question):

lvs && lsblk

The lvresize utility has an option -r that kills two birds with one stone! It shrinks the file system and the disk size on the same run. The -r option stands for resizefs and the long option is --resizefs. By passing -L -5G option you tell lvresize to shrink the file system by 5GB.

Since you are using ext4 file system for your / root partition, shrinking is possible! For the XFS file system, this is not the case.

Reboot the system and you'll see that / has shrunk.

Since you wanted to assign the remaining space of the volume group debian-vg to /home then you'd run the following command to extend /home

lvresize -r -l +100%FREE /dev/mapper/debian-vg-home
Valentin Bajrami
  • 9,244
  • 3
  • 25
  • 38