DIY motocycle trailer

4′ x 8′ bed

Needs to be 5′ 10″ from the bed to the top and weigh under 500 lbs

3/4″ pressure-treated (or not) plywood, can of weatherproofing available for post-build



Shrinking xfs root logical volumes on CentOS 7 VMs

We have a CentOS 7.3 root partition at 30GB with 16GB free space. Let’s shrink that root partition from 30GB to 16GB and save ourselves some room. This post is adapted from the comprehensive Dude!’s Blog post Resizing root LVM with Oracle 7.

1. Check xfs partitions and note the Volume group name

# df -PhT
Filesystem               Type     Size Used  Avail Use% Mounted on
/dev/mapper/centos-root  xfs      27G  12G   16G   42%  /
devtmpfs                 devtmpfs 1.9G  0    1.9G   0%  /dev
tmpfs                    tmpfs    1.9G  0    1.9G   0%  /dev/shm
tmpfs                    tmpfs    1.9G  8.5M 1.9G   1%  /run
tmpfs                    tmpfs    1.9G  0    1.9G   0%  /sys/fs/cgroup
/dev/sda1                xfs      497M  188M 309M  38%  /boot
tmpfs                    tmpfs    380M  0    380M   0%  /run/user/0
# lvs --segments -o +devices
 LV  VG     Attr      #Str Type   SSize  Devices
root centos -wi-ao---- 1   linear 26.47g /dev/sda2(768)
swap centos -wi-ao---- 1   linear  3.00g /dev/sda2(0)
# pvs
 PV       VG     Fmt  Attr PSize  PFree
/dev/sda2 centos lvm2 a--  29.51g 40.00m

In the centos Volume group we have two Logical volumes:
   root with a Logical Volume Size of 26.47 GB
   swap  with a Logical Volume Size of 3.00 GB

2. Compress and delete unneeded files and logs (optional)

# logrotate –f /etc/logrotate.conf
# rm -rf /var/log/*-???????? /var/log/*.gz
# rm -rvf /var/log/messages*
# rm -rf /var/log/dmesg.old
# rm -rf /var/log/anaconda
# cat /dev/null > /var/log/audit/audit.log
# cat /dev/null > /var/log/wtmp
# cat /dev/null > /var/log/lastlog
# cat /dev/null > /var/log/grubby
# cat /dev/zero >/zero.txt
# rm /zero.txt

3. Shut down the VM. Add a 16GB virtual disk (using vSphere here)


4. Mount the CentOS Installation DVD and have the VM connect to it on boot


5. Select VM Options -> Boot Options -> During the next boot, force entry into the BIOS setup screen


6. Click OK. Reboot into the VM BIOS. Click Right Arrow to the Boot menu, and move CD-ROM Drive to the top of the boot order


7. Click Right Arrow to Exit and continue booting. Boot the system in Rescue Mode by booting Installation Media then select Troubleshooting -> Rescue a CentOS Linux system


8. Press Enter to boot into Rescue Mode then 3 – Skip to shell


9. Use parted to create a label and partition table on the new device

sh-4.2# ls -l /dev/sdb
brw-rw---- 1 root disk 8, 16 Aug 2 14:41 /dev/sdb
sh-4.2# parted
GNU Parted 3.1
Using /dev/sda
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) select /dev/sdb
(parted) mklabel msdos
(parted) mkpart
Partition type? primary/extended? primary
File system type? [ext2]? xfs
Start? 1
End? -1
(parted) print
Model: VMware Virtual disk (scsi)
Disk /dev/sdb: 17.2GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos
Disk Flags:

Number Start   End     Size   Type    File system Flags
1      1049kB  17.2GB  17.2GB primary

(parted) quit

6. Create an xfs filesystem and mount the new partition

sh-4.2# mkfs.xfs /dev/sdb1
meta-data=/dev/sdb1 isize=512 agcount=4, agsize=1048448 blks
= sectsz=512 attr=2, projid32bit=1
= crc=1 finobt=0, sparse=0
data = bsize=4096 blocks=4193792, imaxpct=25
= sunit=0 swidth=0 blks
naming =version 2 bsize=4096 ascii-ci=0 ftype=1
log =internal log bsize=4096 blocks=2560, version=2
= sectsz=512 sunit=0 blks, lazy-count=1
realtime =none extsz=4096 blocks=0, rtextents=0

Create /backup and mount the new xfs partition to it
sh-4.2# mkdir /backup
sh-4.2# mount /dev/sdb1 /backup
sh-4.2# df /dev/sdb1      
Filesystem   1K-blocks  Used  Available Use% Mounted on
/dev/sdb1     16764928 32944   16731984   1% /backup

7. Activate existing Logical volumes

sh-4.2# vgchange -a y 
  2 logical volume(s) in volume group "centos" now active
sh-4.2# lvscan
  ACTIVE '/dev/centos/swap' [3.00 GiB] inherit
  ACTIVE '/dev/centos/root' [26.47 GiB] inherit

8. Mount the original root partition in the centos Volume group to /mnt/root

sh-4.2# mkdir /mnt/root
sh-4.2# mount /dev/centos/root /mnt/root

9. Back up the root partition to /backup, verify, then unmount

sh-4.2# xfsdump -f /backup/root.dmp /mnt/root
please enter label for this dump session (timeout in 300 sec)
-> root
please enter label for media in drive 0 (timeout in 300 sec)
-> root
xfsdump: media file size 1113760064 bytes
xfsdump: dump complete: 74 seconds elapsed
xfsdump: Dump Summary:
xfsdump:   stream 0 /backup/root.dmp OK (success)
xfsdump: Dump Status: SUCCESS

Verify results
sh-4.2# ls -l /backup
-rwxr-xr-x. 1 root root 11758274720 Jan  8 14:35 root.dmp

10. Recreate the root Logical volume

Recreate Logical volume root and verify status
sh-4.2# lvremove /dev/centos/root 
  Logical volume "root" successfully removed
sh-4.2# lvcreate -L 16G -n root centos
WARNING: xfs signature detected on /dev/centos/root at offset 0. Wipe it? [y/n]: y
Wiping xfs signature on /dev/centos/root.
Logical volume "root" created.

Verify the physical LVM free volume space has decreased
sh-4.2# pvs
PV         VG       Fmt  Attr PSize  PFree 
/dev/sda2  centos lvm2 a--  29.51g   10.51g
sh-4.2# vgchange -a y
2 logical volume(s) in volume group "centos" now active
# lvscan
ACTIVE            '/dev/centos/swap' [3.88 GiB] inherit
ACTIVE            '/dev/centos/root' [16.00 GiB] inherit

11. Create xfs partition for /root and restore from /backup/root.dmp

Create xfs file system for newly created root partition 
sh-4.2# mkfs.xfs -L root /dev/centos/root 
sh-4.2# mount /dev/centos/root /mnt/root 
sh-4.2# mount /dev/sdb1 /backup

Restore backup 
sh-4.2# xfsrestore -f /backup/root.dmp /mnt/root 
xfsrestore: restore complete: 0 seconds elapsed 
xfsrestore: Restore Summary: 
xfsrestore:   stream 0 /mnt/root/root.dmp OK (success) 
xfsrestore: Restore Status: SUCCESS 
sh-4.2# init 6

11. Use the  UUID of the smaller boot disk in /etc/fstab

# lsblk -o name,size,mountpoint,uuid /dev/sda
sda          30G
|-sda1        1G            433b636e-9b4a-4ea1-8960-6c2288433ac5
# lsblk -o name,size,mountpoint,uuid /dev/sdb1
sdb1 16G f68203c4-1a6f-402c-b415-d4c6c3016f36

Edit fstab to use the new disk
# vi /mnt/root/etc/fstab
/dev/mapper/centos                        /      xfs     defaults        0 0
UUID=f68203c4-1a6f-402c-b415-d4c6c3016f36 /boot  xfs     defaults        0 0

Unmount /mnt/root and /backup then shut down
# umount /mnt/root /backup
# init 6

12. Edit the VM’s settings to disconnect the Installation DVD then boot the VM. Reboot the system and log in to verify new root partition status.

# pvs 
PV         VG       Fmt  Attr PSize  PFree 
/dev/sda2  centos   lvm2 a--  10.00g 2.11g

12. Delete the old large virtual disk