การขยายขนาด logical volumn ของ LVM
มีลูกศิษย์ผม e-mail มาขอให้ผมช่วยแสดงวิธีขยายขนาด logical volume ให้ดูหน่อย ผมก็เลยบอกว่าจะเขียนอธิบายไว้ใน blog เผื่อคนอื่นจะได้ดูด้วย
ในที่นี้ผมจะทำแบบเร็วๆ ผมเพิ่มดิสค์ตัวที่ 2 (/dev/sdb) มีขนาด 80 GB
1. สร้าง partition ในดิสค์ตัวใหม่
mydebian2:~# fdisk /dev/sdb
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won’t be recoverable.
The number of cylinders for this disk is set to 10443.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0×0000 of partition table 4 will be corrected by w(rite)
Command (m for help): p
Disk /dev/sdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): m
Command action
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
l list known partition types
m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition’s system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-10443, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-10443, default 10443):
Using default value 10443
Command (m for help):
Command (m for help): p
Disk /dev/sdb: 85.8 GB, 85899345920 bytes
255 heads, 63 sectors/track, 10443 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 10443 83883366 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
2. สร้าง physical volume ให้กับ partition ที่เพิ่งสร้างใหม่
mydebian2:~# pvcreate /dev/sdb1
Physical volume “/dev/sdb1″ successfully created
3. ขยายขนาด volume group
mydebian2:~# vgscan
Reading all physical volumes. This may take a while…
Found volume group “mydebian2” using metadata type lvm2
mydebian2:~# vgextend
Please enter volume group name and physical volume(s)
vgextend: Add physical volumes to a volume group
vgextend
[-A|--autobackup y|n]
[-d|--debug]
[-h|--help]
[-t|--test]
[-v|--verbose]
[--version]
VolumeGroupName PhysicalDevicePath [PhysicalDevicePath...]
mydebian2:~# vgextend mydebian2 /dev/sdb1
Volume group “mydebian2″ successfully extended
4. ขยายขนาด logical volume
mydebian2:~# lvscan
ACTIVE ‘/dev/mydebian2/root’ [119.03 GB] inherit
ACTIVE ‘/dev/mydebian2/swap_1′ [752.00 MB] inherit
mydebian2:~# lvextend -L+80G /dev/mydebian2/root
Extending logical volume root to 199.03 GB
Insufficient suitable allocatable extents for logical volume root: 1 more required
ขยายเพิ่ม 80 G ไม่ได้ เพราะไม่พอ ระบบใช้ไปแล้วส่วนหนึ่ง งั้นใช้ 79.99 G
mydebian2:~# lvextend -L+79.99G /dev/mydebian2/root
Rounding up size to full physical extent 79.99 GB
Extending logical volume root to 199.02 GB
Logical volume root successfully resized
mydebian2:~# lvscan
ACTIVE ‘/dev/mydebian2/root’ [199.02 GB] inherit
ACTIVE ‘/dev/mydebian2/swap_1′ [752.00 MB] inherit
mydebian2:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/mydebian2-root
118G 792M 111G 1% /
tmpfs 63M 0 63M 0% /lib/init/rw
udev 10M 60K 10M 1% /dev
tmpfs 63M 0 63M 0% /dev/shm
/dev/sda1 236M 13M 211M 6% /boot
5. ปรับขนาดระบบไฟล์
mydebian2:~# resize2fs /dev/mapper/mydebian2-root
resize2fs 1.40-WIP (14-Nov-2006)
Filesystem at /dev/mapper/mydebian2-root is mounted on /; on-line resizing required
old desc_blocks = 8, new_desc_blocks = 13
Performing an on-line resize of /dev/mapper/mydebian2-root to 52171776 (4k) blocks.
The filesystem on /dev/mapper/mydebian2-root is now 52171776 blocks long.
mydebian2:~# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/mydebian2-root
196G 792M 186G 1% /
tmpfs 63M 0 63M 0% /lib/init/rw
udev 10M 60K 10M 1% /dev
tmpfs 63M 0 63M 0% /dev/shm
/dev/sda1 236M 13M 211M 6% /boot
จะเห็นได้ว่า
/dev/mapper/mydebian2-root ซึ่ง mount เป็น / มีขาดเพิ่มจาก 111 G -> 186G