Already back in 2008 I created the following pages, explaining how to extend and reduce logical volumes (LV):
However, in the mentioned pages, I didn't cover the lvreduce for an ext3 partition. So here's a practical example for an LV used for a MySQL partition:
1. As data-loss is always a possibility (however it actually never happened to me yet) when a file system is reduced, the first step should be a working backup. As this is a MySQL partition, this is of course y MySQL dump of the existing databases.
2. Stop MySQL and unmount the partition:
# /etc/init.d/mysql stop
# umount /var/lib/mysql
3. Make a file system check:
# e2fsck -f /dev/vgdata/lvmysql
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgdata/lvmysql: 160/2444624 files (4.4% non-contiguous), 1089992/9765888 blocks
4. Resize the file system. Remember to always shrink the file system before the logical volume!
Here I define a new total size of the file system as 20 GB.
# resize2fs -p /dev/vgdata/lvmysql 20G
resize2fs 1.41.12 (17-May-2010)
Resizing the filesystem on /dev/vg_data/lv_mysql to 5242880 (4k) blocks.
Begin pass 2 (max = 1)
Relocating blocks XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 3 (max = 299)
Scanning inode table XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Begin pass 4 (max = 8)
Updating inode references XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
The filesystem on /dev/vgdata/lvmysql is now 5242880 blocks long.
5. Make another file system check. It should show the new size in blocks:
# e2fsck -f /dev/vgdata/lvmysql
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgdata/lvmysql: 160/1308160 files (4.4% non-contiguous), 1017660/5242880 blocks
6. Shrink/reduce the logical volume. Give it a little bit more space than the file system (to make sure the file system isn't bigger than the lv by accident).
As you see, I tell to use a total size of 20.25 GB for the LV.
# lvreduce -L20.25G /dev/vgdata/lvmysql
WARNING: Reducing active logical volume to 20.25 GiB
THIS MAY DESTROY YOUR DATA (filesystem etc.)
Do you really want to reduce lvmysql? [y/n]: y
Reducing logical volume lvmysql to 20.25 GiB
Logical volume lvmysql successfully resized
7. And, you guessed it, another file system check, to make sure, everything is OK:
# e2fsck -f /dev/vgdata/lvmysql
e2fsck 1.41.12 (17-May-2010)
Pass 1: Checking inodes, blocks, and sizes
Pass 2: Checking directory structure
Pass 3: Checking directory connectivity
Pass 4: Checking reference counts
Pass 5: Checking group summary information
/dev/vgdata/lvmysql: 160/1308160 files (4.4% non-contiguous), 1017660/5242880 blocks
The freed up space can now be seen by vgdisplay and can be used to extend other LV's.
After these steps, the partition can be mounted and MySQL started again.
# mount /dev/vgdata/lvmysql /var/lib/mysql
# /etc/init.d/mysql start
In case there are errors in the applications using MySQL or in the error log, you should import the database dumps created in step 1 again.
No comments yet.
AWS Android Ansible Apache Apple Atlassian BSD Backup Bash Bluecoat CMS Chef Cloud Coding Consul Containers CouchDB DB DNS Database Databases Docker ELK Elasticsearch Filebeat FreeBSD Galera Git GlusterFS Grafana Graphics HAProxy HTML Hacks Hardware Icinga Influx Internet Java KVM Kibana Kodi Kubernetes LVM LXC Linux Logstash Mac Macintosh Mail MariaDB Minio MongoDB Monitoring Multimedia MySQL NFS Nagios Network Nginx OSSEC OTRS Office OpenSearch PGSQL PHP Perl Personal PostgreSQL Postgres PowerDNS Proxmox Proxy Python Rancher Rant Redis Roundcube SSL Samba Seafile Security Shell SmartOS Solaris Surveillance Systemd TLS Tomcat Ubuntu Unix VMWare VMware Varnish Virtualization Windows Wireless Wordpress Wyse ZFS Zoneminder