Expand the disk to its full capacity after initial installation of ubuntu
1. lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
2. resize2fs /dev/ubuntu-vg/ubuntu-lv
CONFIGURING AN LVM VOLUME WITH AN EXT4 FILE SYSTEM
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/high_availability_add-on_administration/s1-lvmsetupnfs-haaa
Basic Steps:
In VMware to enlarge a disk size
#cfdisk (create a LVM partition)
#pvcreate my_vg /dev/sda3 (create a physical volume)
#vgcreate lvm1 /dev/sda3 (create a volume group)
#lvcreate -n my_lv -l 100%FREE my_vg (take 100% free space)
or # lvcreate -n my_lv -L 10G my_vg (take 10G space)
#lvs or lvdisplay (display logical volume)
#mkfs.ext4 /dev/my_vg/my_lv (Create ext4 file system on logical volume)
#mount /dev/lvm1/vol_data /mnt/web (1st create a mount point: /mnt/web)
#blkid /dev/lvm1/vol_data (Find UUID of the logical volumn)
Mount the partition at boot:
#edit /etc/fstab
add following to fstab and save it:
UUID=df9f8cd9-b477-4be1-bb8f-d52bacca84e2 /mnt/web ext4 defaults 0 0
Important:
run sudo mount -a to test it. If nothing is returned it means no errors found.
Remove Logical Volume
#lvremove
Remove Physical Volumes
#vgreduce my_volume_group /dev/hda1
Displaying Information about All LVM Compatible Block Storage Devices
#lvmdiskscan
Displaying Information about Physical Volumes
#sudo lvmdiskscan -l
Ubuntu Server 18.04 LVM out of space with improper default partitioning
partition:
…
/dev/mapper/ubuntu–vg-ubuntu–lv 3.9G 3.6G 92M 98% /
…
Solution:
We need to resize the logical volume to use all the existing and free space of the volume group:
$ sudo lvm
lvm> lvextend -l +100%FREE /dev/ubuntu-vg/ubuntu-lv
lvm> exit
And then, we need to resize the file system to use the new available space in the logical volume
$ sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
Expand a Hard Disk with Ubuntu LVM
(Must be with the partition type of LVM)
https://packetpushers.net/ubuntu-extend-your-default-lvm-space/
1. Add disk space from VMW
2. Check free space:
sudo parted
3. Create a new partition using:
sudo cfdisk
4. Check the new partition:
sudo fdisk -l /dev/sda
5. Create physical volume:
sudo pvcreate /dev/sda3 (It may require reboot before creating it.)
6. Check the new physical volume:
sudo pvdisplay
7. Extend my volume group into our new physical volume (/dev/sda3):
sudo vgextend ubuntu02-vg /dev/sda3
8. Check logical volume:
sudo lvdisplay
(The following 9 and 10 can resize the disk size to its 100% allocated space after installation of Ubuntu recent edition like 20.04)
9. Extend the logical volume to all free space available:
sudo lvextend -l+100%FREE /dev/ubuntu-vg/ubuntu-lv
10. Extend the filesystem:
sudo resize2fs /dev/ubuntu-vg/ubuntu-lv
How to Create a Partition and Mount It
List logical disks and partitions
sudo fdisk -l
Partition the disk
sudo fdisk /dev/sdb
Press n to create a partition
Press p or l to create primary or logical partitions
Press w to write your changes or q to quit
Format the partition
sudo mkfs -t ext4 /dev/sdb1
Mount disk
mount – Shows what is mounted
mkdir /mnt/mydrive
mount -t ext4 /dev/sdb1 /mnt/mydrive
Get disk’s UUID
ls -al /dev/disk/by-uuid/
or
blkid
Mount at boot
Add the following line to your /etc/fstab file adjusting the UUID to your device’s id and the directory to where you want to mount:
UUID=811d3de0-ca6b-4b61-9445-af2e306d9999 /mnt/mydrive ext4 defaults 0 0
mount -a – remounts filesystems from /etc/fstab
Create LVM partition and mount it
https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/high_availability_add-on_administration/s1-lvmsetupnfs-haaa
Some useful commands:
Remove Logical Volume
#lvremove
Remove Physical Volumes
#vgreduce my_volume_group /dev/hda1
Displaying Information about All LVM Compatible Block Storage Devices
#lvmdiskscan
Displaying Information about Physical Volumes
#sudo lvmdiskscan -l
#sudo pvdisplay
Create ext4 file system on logical volume:
#mkfs.ext4 /dev/my_vg/my_lv
Clean up disk
sudo apt install deborphan
To see a list of orphaned packages, run the command below:
$ deborphan
To list all orphaned packages and remove them at same time, run the command below:
$ deborphan | xargs sudo apt –purge remove
More:
https://linoxide.com/remove-orphaned-packages-ubuntu/
https://ubuntuhandbook.org/index.php/2020/12/clear-systemd-journal-logs-ubuntu/
Clear journal size:
https://ma.ttias.be/clear-systemd-journal/