CentOS complete backup and resize LVM partition

General support questions
Post Reply
scatman
Posts: 3
Joined: 2018/03/23 16:18:50

CentOS complete backup and resize LVM partition

Post by scatman » 2018/03/23 16:54:20

Hello everyone, we are two students that have to do a little maintenance to our professor's server. It's the first time we have to deal with centOS and with servers in general. Our task is to shrink home partition and to enlarge the root partition. Giving that we are not really experts on these sort of things, we wanted to make a backup before trying to work with the partitions. First thing we tried was to boot up CloneZilla live from an usb stick, hoping to do a 1:1 copy of the sd to an external drive, BUT clonezilla failed to boot. So we tried to extract the disk and run clonezilla from one of our laptopts, it booted but failed to clone the disk (it saw the single 1 TB disk as two separated 1TB disks and failed to clone both). Now we have two problems:
1) How can we do an easy backup (possibly 1:1 copy) of the entire disk?
2) What is the correct approach to resize an lvm partion?

Here is the partion map:

Code: Select all

Disk /dev/sda: 999.7 GB, 999653638144 bytes, 1952448512 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk label type: dos
Identificativo disco: 0x573a96bf

Dispositivo Boot      Start         End      Blocks   Id  System
/dev/sda1              63       80324       40131   de  Dell Utility
/dev/sda2   *       81920     4276223     2097152    c  W95 FAT32 (LBA)
/dev/sda3         4276224     5300223      512000   83  Linux
/dev/sda4         5300224  1952448511   973574144    5  Extended
/dev/sda5         5302272  1952448511   973573120   8e  Linux LVM

Disk /dev/mapper/centos-root: 53.7 GB, 53687091200 bytes, 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos-swap: 8187 MB, 8187281408 bytes, 15990784 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk /dev/mapper/centos-home: 935.0 GB, 934994247680 bytes, 1826160640 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Here is a tree view:

Code: Select all

NAME            MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda               8:0    0   931G  0 disk 
├─sda1            8:1    0  39,2M  0 part 
├─sda2            8:2    0     2G  0 part 
├─sda3            8:3    0   500M  0 part /boot
├─sda4            8:4    0     1K  0 part 
└─sda5            8:5    0 928,5G  0 part 
  ├─centos-root 253:0    0    50G  0 lvm  /
  ├─centos-swap 253:1    0   7,6G  0 lvm  [SWAP]
  └─centos-home 253:2    0 870,8G  0 lvm  /home
sr0              11:0    1  1024M  0 rom  
The server model is:
Dell PowerEdge T430
CentOS 7 (Core) - Kernel 3.1.0-514.21.1.el7.x86_64

Thanks in advance for all the help!

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: CentOS complete backup and resize LVM partition

Post by hunter86_bg » 2018/03/24 13:12:28

1) For 1:1 image you can use the following from a rescue CD :

Code: Select all

dd if=/dev/sda of=/some/location/image_file.img bs=4M conv=sync,noerror
2)If you used the defaults , your home is on XFS, which means that you should backup "/home" contents , then reduce the lvm size, recreate FS and then copy from the backup. As last step is the expansion of your "/"
Example:

Code: Select all

tar -czvf  /mnt/backupdisk/home_bkp.tgz /home/ \
&& echo "resizing home to 300GB in total" && \
lvresize -L 300GB /dev/centos/home && \
mkfs.ext4 /dev/centos/home && \
tar -xzvf /mnt/backupdisk/home_bkp.tgz -C /home/ && \
lvextend -r -L 100%FREE /dev/centos/root 

scatman
Posts: 3
Joined: 2018/03/23 16:18:50

Re: CentOS complete backup and resize LVM partition

Post by scatman » 2018/03/26 14:35:04

hunter86_bg wrote:1) For 1:1 image you can use the following from a rescue CD :

Code: Select all

dd if=/dev/sda of=/some/location/image_file.img bs=4M conv=sync,noerror
2)If you used the defaults , your home is on XFS, which means that you should backup "/home" contents , then reduce the lvm size, recreate FS and then copy from the backup. As last step is the expansion of your "/"
Example:

Code: Select all

tar -czvf  /mnt/backupdisk/home_bkp.tgz /home/ \
&& echo "resizing home to 300GB in total" && \
lvresize -L 300GB /dev/centos/home && \
mkfs.ext4 /dev/centos/home && \
tar -xzvf /mnt/backupdisk/home_bkp.tgz -C /home/ && \
lvextend -r -L 100%FREE /dev/centos/root 
Hi, firstly thank you very much for your help!
We used those command and everything seemed to work just fine, except for the fact that now ssh doesn't work anymore, every time we try to connect from remote it doesn't accept any password and just gives us "permission denied" , do you know what may be causing this? Could it be a permission problem? How can we fix it?

EDIT: So... we tried restarting the sshd service with systemctl reload sshd.service and it give us a warning like "pkttyagent:): WARNING **: Unable to register authentication agent". Then we tried rebooting the machine thinking it was just a permission problem. Now we can't log in... it starts in emergency mode asking for root password and when we use it, it says "Login incorrect. Give root password for maintenance (or type Control-D to continue): sulogin: /dev/tty1: read failed: Unknown error -8191. Error getting authority: Error initializing authority: Could not connect: No such file or directory (g-io-error-quark, 1). We're a little lost here...

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: CentOS complete backup and resize LVM partition

Post by hunter86_bg » 2018/03/27 04:07:25

Extension of the root shouldn't cause this.
Use a live iso to boot from and check the layout.

P.S.: It seems that I forgot to mount /home back again, but this should not affect the '/'.

scatman
Posts: 3
Joined: 2018/03/23 16:18:50

Re: CentOS complete backup and resize LVM partition

Post by scatman » 2018/03/27 16:48:07

UPDATE: We finally found what was the problem! We made a big oversight not considering that the home partition was flagged as xfs in /etc/fstab and when we gave the command "mkfs.ext4 /dev/centos/home" it made the home partition filesystem ext4, so obviously it couldn't be mounted, and the home partition was creating error on dependecies on cascade with the policykit authentication making the login impossible. So we unmounted home, remade the home filesystem xfs just like /etc/fstab and it fixed itself up!

hunter86_bg
Posts: 2019
Joined: 2015/02/17 15:14:33
Location: Bulgaria
Contact:

Re: CentOS complete backup and resize LVM partition

Post by hunter86_bg » 2018/03/27 18:45:47

I chose "ext4" in my example as it is shrinkable and you can easily resize it bigger or larger. Sadly "xfs" still doesn't have that functionality, and next time you need to resize -> you will have to do the same.

I hope you have noticed the '-r' flag which can be used with 'lvresize/lvreduce/lvextend' - it has saved me several times from making complete mess. It will warn you if your file system is still mounted (that's what happens when you get waken up in 3 am) , makes an fsck and shrinks the FS prior to shrinking LVM, while resizing the FS after a grow ...

Post Reply