Ridimensionamento Cartelle in CentOS 7

Quando installate CentOS7 di default installa delle partizioni divise per root e home come di seguito riportato:

# lsblk
NAME            MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
fd0               2:0    1    4K  0 disk 
sda               8:0    0   70G  0 disk 
├─sda1            8:1    0  500M  0 part /boot
└─sda2            8:2    0 69.5G  0 part 
  ├─centos-swap 253:0    0    2G  0 lvm  [SWAP]
  ├─centos-root 253:1    0 45.3G  0 lvm  /
  └─centos-home 253:2    0 22.1G  0 lvm  /home
sr0              11:0    1 1024M  0 rom

come si può evincere la Home ha 22.1 gb di spazio e la root 45.3 gb.

Quello che andremo a fare sarà eliminare la partizione home e incrementare lo spazio della directory root

Come prima cosa iniziamo a fare un backup di tutti i dati presenti su tutte le partizioni onde evitare che in caso di errori sulla procedura si possano perdere informazioni importanti. Ricordatevi di salvare tutto ciò che è presente nella directory home in quanto la stessa sarà eliminata definitivamente.

Iniziamo con smontare la Partizione centos-home

# umount /home/
Adesso vediamo i volumi logici

# lvdisplay
  --- Logical volume ---
  LV Path                /dev/centos/root
  LV Name                root
  VG Name                centos
  LV UUID                H8tAWA-f5nF-iBXR-Ew3L-djcI-4Vpg-zcjsPK
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-07-20 05:28:54 -0400
  LV Status              available
  # open                 1
  LV Size                45.34 GiB
  Current LE             11607
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:1
   
  --- Logical volume ---
  LV Path                /dev/centos/home
  LV Name                home
  VG Name                centos
  LV UUID                VvIe9h-ZdOF-KvhU-PDLZ-zpXD-rrMV-MTAwSA
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-07-20 05:28:54 -0400
  LV Status              available
  # open                 0
  LV Size                22.14 GiB
  Current LE             5667
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:2
   
  --- Logical volume ---
  LV Path                /dev/centos/swap
  LV Name                swap
  VG Name                centos
  LV UUID                1C22cf-Mq0r-5cDY-YX5T-d7sh-tMLu-zbAxAh
  LV Write Access        read/write
  LV Creation host, time localhost, 2015-07-20 05:28:55 -0400
  LV Status              available
  # open                 2
  LV Size                2.03 GiB
  Current LE             520
  Segments               1
  Allocation             inherit
  Read ahead sectors     auto
  - currently set to     256
  Block device           253:0

Rimuoviamo il volume logico centos-home

# lvremove /dev/centos/home
Do you really want to remove active logical volume home? [y/n]: y
Logical volume "home" successfully removed


Adesso controlliamo lo spazio disponibile con il comando vgs

# vgs
  VG     #PV #LV #SN Attr   VSize  VFree 
  centos   1   2   0 wz--n- 69.51g 22.14g

Adesso ridimensionamo la partizione centos-root

# lvextend --size +22.13GB -r /dev/mapper/centos-root 
  Rounding size to boundary between physical extents: 22.13 GiB
  Extending logical volume root to 67.47 GiB
  Logical volume root successfully resized
meta-data=/dev/mapper/centos-root isize=256    agcount=4, agsize=2971392 blks
         =                       sectsz=512   attr=2, projid32bit=1
         =                       crc=0
data     =                       bsize=4096   blocks=11885568, imaxpct=25
         =                       sunit=0      swidth=0 blks
naming   =version 2              bsize=4096   ascii-ci=0 ftype=0
log      =internal               bsize=4096   blocks=5803, version=2
         =                       sectsz=512   sunit=0 blks, lazy-count=1
realtime =none                   extsz=4096   blocks=0, rtextents=0
data blocks changed from 11885568 to 17687552

Tags: