Create Logical volume for swap
[root@demo ~]# fdisk -cu /dev/vda
Command (m for help): p
Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006fab8
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 9914367 4694016 8e Linux LVM
/dev/vda3 9914368 12582911 1334272 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First sector (9916416-12582911, default 9916416):
Using default value 9916416
Last sector, +sectors or +size{K,M,G} (9916416-12582911, default 12582911): +100M
Command (m for help): p
Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006fab8
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 9914367 4694016 8e Linux LVM
/dev/vda3 9914368 12582911 1334272 5 Extended
/dev/vda5 9916416 10121215 102400 83 Linux
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 5
[root@demo ~]# pvcreate /dev/vda5
WARNING: swap signature detected on /dev/vda5. Wipe it? [y/n] y
Wiping swap signature on /dev/vda5.
Writing physical volume data to disk "/dev/vda5"
Physical volume "/dev/vda5" successfully created
[root@demo ~]# vgcreate -s 4M swapgrp /dev/vda5
Volume group "swapgrp" successfully created
[root@demo ~]# lvcreate -L 80M -n swap /dev/swapgrp
Logical volume "swap" created
[root@demo ~]# mkswap /dev/swapgrp/swap
mkswap: /dev/swapgrp/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 81916 KiB
no label, UUID=a81559c0-9ddc-4771-b8b3-fa850de90846
[root@demo ~]# swapon /dev/swapgrp/swap
[root@demo ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-3 partition 81912 0 -1
[root@demo ~]# free -m
total used free shared buffers cached
Mem: 996 888 107 0 33 347
-/+ buffers/cache: 508 488
Swap: 79 0 79
[root@demo ~]# vim /etc/fstab
at the end add the device name
#################################################
/etc/fstab
# Created by anaconda on Sun Feb 2 08:09:32 2014
#
# 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/vgsrv-root / ext4 defaults 1 1
UUID=245a990d-dd79-47d3-a1ef-68bb725c9a04 /boot ext4 defaults 1 2
/dev/mapper/vgsrv-home /home ext4 defaults 1 2
/dev/mapper/vgsrv-swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/swapgrp/swap swap swap defaults 0 0
############################################################################
[root@demo ~]# mount -a
DELETE SWAP
[root@demo ~]# vim /etc/fstab
[root@demo ~]# swapoff /dev/swapgrp/swap
[root@demo ~]# lvremove /dev/swapgrp/swap
Do you really want to remove active logical volume swap? [y/n]: y
Logical volume "swap" successfully removed
[root@demo ~]# vgremove /dev/swapgrp
Volume group "swapgrp" successfully removed
[root@demo ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 vgsrv lvm2 a-- 4.47g 384.00m
/dev/vda5 lvm2 a-- 100.00m 100.00m
[root@demo~]# pvremove /dev/v
vcs vcs4 vcsa1 vcsa5 vda2 vgsrv/
vcs1 vcs5 vcsa2 vcsa6 vda3
vcs2 vcs6 vcsa3 vda vda5
vcs3 vcsa vcsa4 vda1 vga_arbiter
[root@demo ~]# pvremove /dev/vda5
Labels on physical volume "/dev/vda5" successfully wiped
[root@demo~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 vgsrv lvm2 a-- 4.47g 384.00m
[root@demo ~]# fdisk -cu /dev/vda
Command (m for help): p
Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006fab8
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 9914367 4694016 8e Linux LVM
/dev/vda3 9914368 12582911 1334272 5 Extended
Command (m for help): n
Command action
l logical (5 or over)
p primary partition (1-4)
l
First sector (9916416-12582911, default 9916416):
Using default value 9916416
Last sector, +sectors or +size{K,M,G} (9916416-12582911, default 12582911): +100M
Command (m for help): p
Disk /dev/vda: 6442 MB, 6442450944 bytes
16 heads, 63 sectors/track, 12483 cylinders, total 12582912 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x0006fab8
Device Boot Start End Blocks Id System
/dev/vda1 * 2048 526335 262144 83 Linux
/dev/vda2 526336 9914367 4694016 8e Linux LVM
/dev/vda3 9914368 12582911 1334272 5 Extended
/dev/vda5 9916416 10121215 102400 83 Linux
Command (m for help): t
Partition number (1-5): 5
Hex code (type L to list codes): 8e
Changed system type of partition 5 to 8e (Linux LVM)
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
[root@demo ~]# partx -a /dev/vda
BLKPG: Device or resource busy
error adding partition 1
BLKPG: Device or resource busy
error adding partition 2
BLKPG: Device or resource busy
error adding partition 3
BLKPG: Device or resource busy
error adding partition 5
[root@demo ~]# pvcreate /dev/vda5
WARNING: swap signature detected on /dev/vda5. Wipe it? [y/n] y
Wiping swap signature on /dev/vda5.
Writing physical volume data to disk "/dev/vda5"
Physical volume "/dev/vda5" successfully created
[root@demo ~]# vgcreate -s 4M swapgrp /dev/vda5
Volume group "swapgrp" successfully created
[root@demo ~]# lvcreate -L 80M -n swap /dev/swapgrp
Logical volume "swap" created
[root@demo ~]# mkswap /dev/swapgrp/swap
mkswap: /dev/swapgrp/swap: warning: don't erase bootbits sectors
on whole disk. Use -f to force.
Setting up swapspace version 1, size = 81916 KiB
no label, UUID=a81559c0-9ddc-4771-b8b3-fa850de90846
[root@demo ~]# swapon /dev/swapgrp/swap
[root@demo ~]# swapon -s
Filename Type Size Used Priority
/dev/dm-3 partition 81912 0 -1
[root@demo ~]# free -m
total used free shared buffers cached
Mem: 996 888 107 0 33 347
-/+ buffers/cache: 508 488
Swap: 79 0 79
[root@demo ~]# vim /etc/fstab
at the end add the device name
#################################################
/etc/fstab
# Created by anaconda on Sun Feb 2 08:09:32 2014
#
# 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/vgsrv-root / ext4 defaults 1 1
UUID=245a990d-dd79-47d3-a1ef-68bb725c9a04 /boot ext4 defaults 1 2
/dev/mapper/vgsrv-home /home ext4 defaults 1 2
/dev/mapper/vgsrv-swap swap swap defaults 0 0
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
/dev/swapgrp/swap swap swap defaults 0 0
############################################################################
[root@demo ~]# mount -a
DELETE SWAP
[root@demo ~]# vim /etc/fstab
[root@demo ~]# swapoff /dev/swapgrp/swap
[root@demo ~]# lvremove /dev/swapgrp/swap
Do you really want to remove active logical volume swap? [y/n]: y
Logical volume "swap" successfully removed
[root@demo ~]# vgremove /dev/swapgrp
Volume group "swapgrp" successfully removed
[root@demo ~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 vgsrv lvm2 a-- 4.47g 384.00m
/dev/vda5 lvm2 a-- 100.00m 100.00m
[root@demo~]# pvremove /dev/v
vcs vcs4 vcsa1 vcsa5 vda2 vgsrv/
vcs1 vcs5 vcsa2 vcsa6 vda3
vcs2 vcs6 vcsa3 vda vda5
vcs3 vcsa vcsa4 vda1 vga_arbiter
[root@demo ~]# pvremove /dev/vda5
Labels on physical volume "/dev/vda5" successfully wiped
[root@demo~]# pvs
PV VG Fmt Attr PSize PFree
/dev/vda2 vgsrv lvm2 a-- 4.47g 384.00m
No comments:
Post a Comment