LVM on Debian: extend folder / root

0

I run out of space in the / root folder, I need to upgrade to Debian 9. But because of this problem I can not.

My this partition structure:

NAME                     MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                        8:0    0 931,5G  0 disk 
├─sda1                     8:1    0   243M  0 part /boot
├─sda2                     8:2    0     1K  0 part 
└─sda5                     8:5    0 931,3G  0 part 
  ├─educacion--vg-root   254:0    0   9,3G  0 lvm  /
  ├─educacion--vg-swap_1 254:1    0   7,8G  0 lvm  [SWAP]
  └─educacion--vg-home   254:2    0 914,2G  0 lvm  /home
sr0                       11:0    1  1024M  0 rom  

The / root folder is mapped to educacion--vg-root . These are my logical partitions:

lvmdiskscan
  /dev/educacion-vg/root   [       9,31 GiB] 
  /dev/sda1                [     243,00 MiB] 
  /dev/educacion-vg/swap_1 [       7,80 GiB] 
  /dev/educacion-vg/home   [     914,16 GiB] 
  /dev/sda5                [     931,27 GiB] LVM physical volume
  2 disks
  2 partitions
  0 LVM physical volume whole disks
  1 LVM physical volume

If I do a df -h you can see that the root (/dev/dm-0) is full:

df -h
S.ficheros                     Tamaño Usados  Disp Uso% Montado en
/dev/dm-0                        9,1G   8,6G   46M 100% /
udev                              10M      0   10M   0% /dev
tmpfs                            773M   9,1M  764M   2% /run
tmpfs                            1,9G    31M  1,9G   2% /dev/shm
tmpfs                            5,0M   4,0K  5,0M   1% /run/lock
tmpfs                            1,9G      0  1,9G   0% /sys/fs/cgroup
/dev/sda1                        236M    49M  175M  22% /boot
/dev/mapper/educacion--vg-home   900G   8,1G  846G   1% /home
tmpfs                            387M   4,0K  387M   1% /run/user/116
tmpfs                            387M   8,0K  387M   1% /run/user/1000

If I see the volume of the logical partition, there is no space:

vgdisplay
  --- Volume group ---
  VG Name               educacion-vg
  System ID             
  Format                lvm2
  Metadata Areas        1
  Metadata Sequence No  6
  VG Access             read/write
  VG Status             resizable
  MAX LV                0
  Cur LV                3
  Open LV               3
  Max PV                0
  Cur PV                1
  Act PV                1
  VG Size               931,27 GiB
  PE Size               4,00 MiB
  Total PE              238405
  Alloc PE / Size       238405 / 931,27 GiB
  Free  PE / Size       0 / 0  /// aca muestra que  hay espacio 
  VG UUID               ttIQ4H-odre-GnH5-4x11-URPm-aVeK-mb0IW1

I see that the logical partition educacion--vg-home has almost the entire physical space. How can you shrink it and move space to educacion--vg-root ?

Try using Gparted but the logical partition is blocked. I tried with lvextend --resizefs -L 1.15T /dev/educacion-vg/root but since the VG does not have space it can not.

Thank you very much.

    
asked by TOMAS 28.10.2018 в 19:50
source

1 answer

0

Let's see, what you have full is not /root but / . Within that volume resides almost everything ... in this case, everything you do not have in /home .

As /home has space to spare, the first thing I would do is to reduce that partition by leaving a few free gigs at the end (say, 25G). This operation is fast because it does not involve moving data. This is step zero .

Once this is done, you have two ways to follow.

The first is a bit of a patch but almost immediate solution, which would be to remove the swap partition and recreate it at the end of the available space (which you just released by shrinking /home ). This done, you will have 7GB free after / and you should be able to assign them freely.

If it does not let you do it "hot" you would have to start with a bootable pendrive that has lvextend or GPARTED . Those from ubuntu bring it, I imagine that debian also.

Using lvextend , resizing / to the right does not involve moving data, so it is fast and harmless. I'm not sure you Gparted can correctly modify units within an lvm.

After this, you restart normally.

The second way would be to review what occupies the most space within /

 sudo du -h --max-depth=1 /

I would say that, generally, what occupies the most space is /var .

As in the first step you left many free gigs after /home you can create a new partition in that free space:

 sudo lvcreate -L 20G -n var /dev/educacion-vg

Format it as ext4:

 sudo mkfs.ext4 /dev/educacion-vg/var

and mount it in /new_var .

sudo mkdir /new_var
sudo mount /dev/educacion-vg/var /new_var

Then copy all content from /var to /new_var

sudo rsync -avzr /var/ /new_var/

And temporarily mount /new_var/ above /var

sudo mount --bind /new_var /var

However with this you have not yet released space in / . To access the original physical folder /var , which has been hidden with /new_var you can mount / in a directory, inside which will be the original folder, from which you can delete everything

sudo mkdir /original
sudo mount --bind /original /
sudo rm -rf /original/var/*

With that you cleaned the contents of the original folder, freeing space in / .

At this point /dev/educacion-vg/var is temporarily mounted in /new_var and /var is temporarily mounted with bind over /new_var .

To persist all that, you write

sudo blkid

The volume /dev/educacion-vg/var should appear with its respective UUID.

/dev/educacion-vg/var: UUID="920fd9f9-8854-3f97b596e95b" TYPE="ext4" PARTUUID="84def38e-01"

Then in your fstab you can make the /var folder mount on the new volume when you reboot. In your fstab you add (with the appropriate uuid):

UUID=920fd9f9-8854-3f97b596e95b /var   ext4    errors=remount-ro 0  1

And done this, you can restart.

    
answered by 28.10.2018 в 21:58