【Linux】lvm基礎操作,linuxlvm基礎
新增兩塊硬碟,來進行實驗:
[root@jp ~]# fdisk -l
Disk /dev/sda: 107.3 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 255 2048256 83 Linux
/dev/sda2 256 777 4192965 82 Linux swap / Solaris
/dev/sda3 778 13054 98615002+ 83 Linux
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
隨便將/dev/sdb分成三個區
[root@jp ~]# 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.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1): 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +1000M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (124-652, default 124):
Using default value 124
Last cylinder or +size or +sizeM or +sizeK (124-652, default 652): +2000M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (368-652, default 368):
Using default value 368
Last cylinder or +size or +sizeM or +sizeK (368-652, default 652):
Using default value 652
Command (m for help): p
Disk /dev/sdb: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 123 987966 83 Linux
/dev/sdb2 124 367 1959930 83 Linux
/dev/sdb3 368 652 2289262+ 83 Linux
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.
Syncing disks.
/dev/sdc隨便分兩個區:
[root@jp ~]# fdisk /dev/sdc
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.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 1
First cylinder (1-652, default 1):
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-652, default 652): +2000M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (245-652, default 245):
Using default value 245
Last cylinder or +size or +sizeM or +sizeK (245-652, default 652):
Using default value 652
Command (m for help): p
Disk /dev/sdc: 5368 MB, 5368709120 bytes
255 heads, 63 sectors/track, 652 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdc1 1 244 1959898+ 83 Linux
/dev/sdc2 245 652 3277260 83 Linux
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
將所有分區建立PV
[root@jp ~]# pvcreate /dev/sdb1
Physical volume "/dev/sdb1" successfully created
[root@jp ~]# pvcreate /dev/sdb2
Physical volume "/dev/sdb2" successfully created
[root@jp ~]# pvcreate /dev/sdb3
Physical volume "/dev/sdb3" successfully created
[root@jp ~]# pvcreate /dev/sdc1
Physical volume "/dev/sdc1" successfully created
[root@jp ~]# pvcreate /dev/sdc2
Physical volume "/dev/sdc2" successfully created
建立VG,將/dev/sdb1和/dev/sdc1放到該VG中
[root@jp ~]# vgcreate test1 /dev/sdb1 /dev/sdc1
/dev/cdrom: open failed: No medium found
Volume group "test1" successfully created
向VG中增加磁碟:
[root@jp ~]# vgextend test1 /dev/sdb2
Volume group "test1" successfully extended
查看VG資訊:
[root@jp ~]# vgdisplay
--- Volume group ---
VG Name test1
System ID
Format lvm2
Metadata Areas 3
Metadata Sequence No 4
VG Access read/write
VG Status resizable
MAX LV 0
Cur LV 1
Open LV 1
Max PV 0
Cur PV 3
Act PV 3
VG Size 4.68 GB
PE Size 4.00 MB
Total PE 1197
Alloc PE / Size 300 / 1.17 GB
Free PE / Size 897 / 3.50 GB
VG UUID 0ux9KE-yHJP-07Y0-9yCd-ppG2-wWe0-78nLbh
建立LV,從VG:test1中拿出1000M給該LV:lv_test1
[root@jp ~]# lvcreate -L 1000M -n lv_test1 test1
Logical volume "lv_test1" created
格式化LV,LV只有在格式化之後才能儲存資料
[root@jp ~]# mke2fs -j /dev/test1/lv_test1
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
128000 inodes, 256000 blocks
12800 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=264241152
8 block groups
32768 blocks per group, 32768 fragments per group
16000 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376
Writing inode tables: done
Creating journal (4096 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 33 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
掛載LV:
[root@jp ~]# mkdir /test
[root@jp ~]# mount /dev/test1/lv_test1 /test
[root@jp ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 92G 20G 67G 23% /
/dev/sda1 1.9G 42M 1.8G 3% /boot
tmpfs 1014M 0 1014M 0% /dev/shm
/dev/mapper/test1-lv_test1
985M 18M 918M 2% /test
掛載之後,可以但到此LV的容量。
如果要在系統啟動的時候啟動LV,最好是將LV01寫入fstable檔案中
調整LV的大小
[root@jp ~]# lvresize -L +200M /dev/test1/lv_test1
Extending logical volume lv_test1 to 1.17 GB
Logical volume lv_test1 successfully resized
[root@jp ~]# resize2fs /dev/test1/lv_test1
resize2fs 1.39 (29-May-2006)
Filesystem at /dev/test1/lv_test1 is mounted on /test; on-line resizing required
Performing an on-line resize of /dev/test1/lv_test1 to 307200 (4k) blocks.
The filesystem on /dev/test1/lv_test1 is now 307200 blocks long.
linux裡lvm 用來幹什
lvm是linux邏輯卷組管理,用來對磁碟分割進行管理的一種技術。
linux LVM用的多
這是linux 的磁碟分割管理,如有用,請採用。謝謝
LVM是邏輯盤卷管理(Logical Volume Manager)的簡稱,它是Linux環境下對磁碟分割進行管理的一種機制,LVM是建立在硬碟和分區之上的一個邏輯層,來提高磁碟分
LVM
區管理的靈活性。前面談到,LVM是在磁碟分割和檔案系統之間添加的一個邏輯層,來為檔案系統屏蔽下層磁碟分割布局,提供一個抽象的盤卷,在盤卷上建立檔案系統。物理卷(physical volume)物理卷就是指硬碟分區或從邏輯上與磁碟分割具有同樣功能的裝置(如RAID),是LVM的基本存放裝置邏輯塊,但和基本的實體儲存體介質(如分區、磁碟等)比較,卻包含有與LVM相關的管理參數。
Linux使用者安裝Linux作業系統時遇到的一個最常見的難以決定的問題就是如何正確地給評估各分區大小,以分配合適的硬碟空間。而遇到出現 某個分區空間耗盡時,解決的方法通常是使用符號連結,或者使用調整分區大小的工具(比如PatitionMagic等),但這都只是暫時解決辦法,沒有根本解決問題。隨著Linux的邏輯盤卷管理功能的出現,這些問題都迎刃而解,使用者在無需停機的情況下方便地調整各個分區大小