Extended LVM and Resize XFS
ถึงแม้ว่าในยุคของ Cloud Computing ความจำเป็นที่ต้องติดตั้งระบบปฏิบัติการเองมีความจำเป็นน้อยลง ทำให้ปัญหาการผิดพลาดในการแบ่ง partition น้อยลงไปด้วยก็ตาม แต่การเปลี่ยนแปลงขนาดของ file system ก็เองก็ยังจำเป็นต้องเปลี่ยนบ้างในกรณีที่ template ของ Cloud Computing ที่ให้มายังไม่เป็นไปตามความต้องการ หรือ ระบบมีการขยายตัวจนจำเป็นต้องเพิ่มขนาดของ file system
ในกรณีที่ติดตั้ง Red Hat Enterprise Linux แล้วเลือก Partitioning >> Automatically configure partitioning ในหัวข้อ “Installation Destination” และ Disk ที่เลือกในการติดตั้งมีขนาดมากกว่า 50 GB จะถูกแบ่งเป็น / ขนาด 50 GB และในส่วนที่เหลือจะถูกแบ่งให้เป็น /home ทำให้ /home มีขนาดใหญ่เกินความจำเป็นในการใช้งาน
การเปลี่ยนขนาดของ file system สามารถทำได้โดยไม่จำเป็นต้องติดตั้งระบบปฏิบัติการใหม่ แต่ partition ที่ต้องการปรับแต่งขนาด จำเป็นต้องถูกจัดการด้วย LVM — Logical Volume Management โดยมีขั้นตอนดังนี้
- จัดเตรียมข้อมูลที่จำเป็น
- การแบ่ง Partition และ ขนาด
[root@server1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 52403200 893152 51510048 2% /
devtmpfs 923848 0 923848 0% /dev
tmpfs 934332 0 934332 0% /dev/shm
tmpfs 934332 8808 925524 1% /run
tmpfs 934332 0 934332 0% /sys/fs/cgroup
/dev/mapper/rhel-home 28764444 32928 28731516 1% /home
/dev/sda1 508588 127264 381324 26% /boot
tmpfs 186868 0 186868 0% /run/user/0
- ข้อมูล Volume Group
[root@server1 ~]# vgs
VG #PV #LV #SN Attr VSize VFree
rhel 1 3 0 wz--n- 79.51g 64.00m
- ข้อมูล Logical Volume
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
home rhel -wi-ao---- 27.45g
root rhel -wi-ao---- 50.00g
swap rhel -wi-ao---- 2.00g
- /etc/fstab
[root@server1 ~]# cat /etc/fstab#
# /etc/fstab
# Created by anaconda on Mon Jul 4 21:37:57 2016
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
/dev/mapper/rhel-root / xfs defaults 0 0
UUID=7291fa0e-2436-4a86-a78b-e9de2795805c /boot xfs defaults 0 0
/dev/mapper/rhel-home /home xfs defaults 0 0
/dev/mapper/rhel-swap swap swap defaults 0 0
- Plan Downtime (optional) ในการปรับเพิ่มขนาดของ file system ไม่จำเป็นต้อง reboot ระบบ เพียงแต่ถ้าต้องการยืนยันความถูกต้อง และให้มั่นใจได้ว่าทุกอย่างทำงานเป็นปกติ ควรจะ reboot เพื่อความั่นใจ
- Application Checklist ในการเปลี่ยนแปลงระบบทุกครั้งควรจัดทำ checklist ที่จะทำการตรวจสอบ และขั้นตอนการตรวจสอบ เพื่อตรวจทานการเปลี่ยนแปลงของระบบ จะไม่มีผลกระทบต่อการทำงานของ application
- Backup
2. extended and resize
[root@server1 ~]# tar cvfz /root/home.tgz /home
[root@server1 ~]# umount /home
[root@server1 ~]# lvremove -f rhel/home
[root@server1 ~]# lvextend -l +100%FREE /dev/rhel/root
[root@server1 ~]# xfs_growfs /dev/rhel/root
[root@server1 ~]# tar xvfz /root/home.tgz -C /
[root@server1 ~]# sed -i.bak '/rhel-home/d' /etc/fstab
3. ตรวจสอบความถูกต้อง จะไม่พบ /dev/rhel/home (/dev/mapper/rhel-home) และ ขนาดของ /dev/rhel/root (/dev/mapper/rhel-root) จะเพิ่มขึ้น เป็นขนาดของ / รวมกับขนาดของ /home
[root@server1 ~]# df
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/rhel-root 81247232 899400 80347832 2% /
devtmpfs 923848 0 923848 0% /dev
tmpfs 934332 0 934332 0% /dev/shm
tmpfs 934332 8772 925560 1% /run
tmpfs 934332 0 934332 0% /sys/fs/cgroup /dev/sda1 508588 127260 381328 26% /boot
tmpfs 186868 0 186868 0% /run/user/0
[root@server1 ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert
root rhel -wi-ao---- 77.51g
swap rhel -wi-ao---- 2.00g
4. ในกรณีที่มีการเพิ่ม disk เข้าไปในระบบสามารถใช้แนวทางของเอกสารฉบับนี้เพื่ออ้างอิง และศึกษาเพิ่มเติมเรื่อง LVM — Logical Volume Management การเพิ่ม disk เข้าไปใน Volume Group เดิมที่มีอยู่