Linux下磁碟分區與LVM創建

火星人 @ 2014-03-09 , reply:0


Linux下磁碟分區與LVM創建

1.首先在系統上添加2塊2G的硬碟 2.進入系統以後用fdisk -l 看看兩塊磁碟是否存在了, 有了磁碟之後,用fdisk和parted 兩個工具對磁碟進行分區,現在已經進入系統 我們可以進行操作了;我們可以看到/dev/sdb 和/dev/sdc兩塊磁碟;現在我們來分區 這裡按錯了,不能按o鍵,從來:我們已經用fdisk將/dev/sdb分好了 Device Boot Start End Blocks Id System /dev/sdb1 1 62 497983 83 Linux /dev/sdb2 63 261 1598467 5 Extended /dev/sdb5 63 185 987966 83 Linux /dev/sdb6 186 261 610438 83 Linux 3.現在來進行格式化:格式化的命令有2種,效果都一樣.也可以將它格式化為vfat等格式 [root@www /]# mkfs -t ext3 /dev/sdb2 [root@www /]# mkfs.ext3 /dev/sdb1 4.現在用parted來對另一塊磁碟做分區: 還不能用parted,我們換一種方式就可以分區了 用到的命令是:parted -s /dev/sdc mktable msdos 先將它的格式變為msdos 就可以分區了:parted -s /dev/sdc mkpart primary 0 500M是將主分區大小劃為500M parted -s /dev/sdc mkpart extended 500M 1.9G 其餘的全為擴展分區 在擴展分區上來進行邏輯分區的劃分 parted -s /dev/sdc mkpart logical 500M 1500M 第一個邏輯分區大小為1G parted -s /dev/sdc mkpart logical 1500M 1.9G 第二個邏輯分區大小為400M 留下一小點空間,否則會報錯,全部填寫完也沒事,忽略錯誤也可以 5.現在要用set來設置lvm標誌 (parted) set 分區編號? 2 Flag to Invert? lvm 新狀態? [開]/on/關/off? on (parted) set 5 Flag to Invert? lvm 新狀態? [開]/on/關/off? on (parted) set 6 Flag to Invert? lvm 新狀態? [開]/on/關/off? on (parted) p Device Boot Start End Blocks Id System /dev/sdc1 1 61 488281 8e Linux LVM Partition 1 does not end on cylinder boundary. /dev/sdc2 61 261 1608201 f W95 Ext'd (LBA) /dev/sdc5 61 183 976562 8e Linux LVM /dev/sdc6 184 261 626503 8e Linux LVM 哦;sdb忘記設置lvm標誌了,現在來設置 Device Boot Start End Blocks Id System /dev/sdb1 1 62 497983 8e Linux LVM /dev/sdb2 63 261 1598467 5 Extended /dev/sdb5 63 185 987966 8e Linux LVM /dev/sdb6 186 261 610438 8e Linux LVM 6.現在來創建PV;有successfully,說明創建成功了, [root@www /]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created [root@www /]# pvcreate /dev/sdb5 Physical volume "/dev/sdb5" successfully created [root@www /]# pvcreate /dev/sdb6 Physical volume "/dev/sdb6" successfully created [root@www /]# 現在創建sdc的PV [root@www /]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created [root@www /]# pvcreate /dev/sdc5 Physical volume "/dev/sdc5" successfully created [root@www /]# pvcreate /dev/sdc6 Physical volume "/dev/sdc6" successfully created 接下來,創建VG;這裡可以將2塊磁碟的pv都創建到一個VG裡面,也可以分開創建 首先創建ftpVG卷組 vgcreate ftpVG /dev/sdb1 /dev/sdb5 /dev/sdb6 Volume group "ftpVG" successfully created 在VG上創建LV [root@www /]# vgdisplay --- Volume group --- VG Name ftpVG System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 1.99 GB PE Size 4.00 MB Total PE 510 Alloc PE / Size 0 / 0 Free PE / Size 510 / 1.99 GB VG UUID 7aOcVh-QlKm-qGoP-Fjqu-ehU7-6TjX-WbMt6A 還有Free PE,現在將它添加進去: [root@www /]# lvcreate -l 510 -n ftp ftpVG /dev/cdrom: open failed: 只讀文件系統 Logical volume "ftp" created [root@www /]# vgdisplay --- Volume group --- VG Name ftpVG System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 1.99 GB PE Size 4.00 MB Total PE 510 Alloc PE / Size 510 / 1.99 GB Free PE / Size 0 / 0 VG UUID 7aOcVh-QlKm-qGoP-Fjqu-ehU7-6TjX-WbMt6A 現在的Free PE變為0了,說明所有的空間都在裡面了 [root@www /]# lvdisplay --- Logical volume --- LV Name /dev/ftpVG/ftp VG Name ftpVG LV UUID ax7f3n-mzTm-uvmt-TX9l-s70J-TH0B-FAR5iD LV Write Access read/write LV Status available # open 0 LV Size 1.99 GB Current LE 510 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 總大小為2G了 現在創建另外一個卷組:用到的命令vgcreate <卷組名> 《物理卷設備》 《?》 《》 注意這裡一定要用-l Free PE 才能加得進去: [root@www /]# lvcreate -l 509 -n vol volVG /dev/cdrom: open failed: 只讀文件系統 Logical volume "vol" created [root@www /]# lvdisplay --- Logical volume --- LV Name /dev/volVG/vol VG Name volVG LV UUID go0Q37-aEfj-zCmw-H3Q8-dcR8-hGOe-2f7u7Q LV Write Access read/write LV Status available # open 0 LV Size 1.99 GB Current LE 509 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 [root@www /]# vgdisplay --- Volume group --- VG Name volVG System ID Format lvm2 Metadata Areas 3 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 3 Act PV 3 VG Size 1.99 GB PE Size 4.00 MB Total PE 509 Alloc PE / Size 509 / 1.99 GB Free PE / Size 0 / 0 VG UUID GcQfX5-PgwW-T0t1-wRxb-8tXI-t6Y4-eHqvnE 現在已經有2個卷組了;現在格式化;剛才已經格式化過每一塊分區了,現在不用了 7.現在我們將這兩塊磁碟掛載上去 [root@www /]# df -ah 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 15G 5.9G 7.9G 43% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/sda1 114M 14M 95M 13% /boot tmpfs 186M 0 186M 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs none 0.0K 0.0K 0.0K - /proc/fs/vmblock/mountPoint /dev/hdc 619M 619M 0 100% /media/CentOS_5.3_Final 現在是看不到的,沒掛載;現在我們創建兩個掛載的目錄; 這裡可以隨意創建,比如 /soft/vol movie/ftp 現在掛載:[root@www /]# mount /dev/ftpVG/ftp /movie/ftp mount: you must specify the filesystem type 提示指定文件系統類型;看來還沒格式化; mkfs.ext3 /dev/ftpVG/ftp 或mkfs -t ext3 /dev/ftpVG/ftp 現在已經掛上了;看一下 [root@www /]# df -ah 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 15G 5.9G 7.9G 43% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/sda1 114M 14M 95M 13% /boot tmpfs 186M 0 186M 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs none 0.0K 0.0K 0.0K - /proc/fs/vmblock/mountPoint /dev/hdc 619M 619M 0 100% /media/CentOS_5.3_Final /dev/mapper/ftpVG-ftp 現在來掛另外一塊; [root@www /]# df -ah 文件系統 容量 已用 可用 已用% 掛載點 /dev/sda3 15G 5.9G 7.9G 43% / proc 0 0 0 - /proc sysfs 0 0 0 - /sys devpts 0 0 0 - /dev/pts /dev/sda1 114M 14M 95M 13% /boot tmpfs 186M 0 186M 0% /dev/shm none 0 0 0 - /proc/sys/fs/binfmt_misc sunrpc 0 0 0 - /var/lib/nfs/rpc_pipefs none 0.0K 0.0K 0.0K - /proc/fs/vmblock/mountPoint /dev/hdc 619M 619M 0 100% /media/CentOS_5.3_Final /dev/mapper/ftpVG-ftp 2.0G 36M 1.9G 2% /movie/ftp /dev/mapper/volVG-vol 2.0G 36M 1.9G 2% /soft/vol 2.0G 36M 1.9G 2% /movie/ftp 這裡是不多出了一塊了,現在是有2塊2G的硬碟了,現在我們在裡面寫內容,然後再減小磁碟 空間,看看有什麼變化; 還是拷貝u盤上的文件算了,大點的才好檢驗;我們就拷貝.iso文件了,有600多兆的;就這 幾個了,可以檢驗就行了;我們是拷到volVG/vol下面的,現在將volVG/vol的空間劃出1G來; [root@www /]# lvresize -L -1G /dev/volVG/vol /dev/cdrom: open failed: 只讀文件系統 WARNING: Reducing active and open logical volume to 1012.00 MB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vol? [y/n]: y Reducing logical volume vol to 1012.00 MB Logical volume vol successfully resized 現在來看看大小;這裡已經變為1G了 [root@www /]# lvdisplay --- Logical volume --- LV Name /dev/volVG/vol VG Name volVG LV UUID go0Q37-aEfj-zCmw-H3Q8-dcR8-hGOe-2f7u7Q LV Write Access read/write LV Status available # open 1 LV Size 1012.00 MB Current LE 253 Segments 2 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 現在lv /dev/volVG/vol的大小已經變成了1012M了,我們看看文件有沒有丟失? 文件依然存在沒有丟失,小我們又把空間加回去, 完了出現亂子了,我們自己打一個標記 好識別; 內容: [root@www vol]# cat <<! > index.html > hello ,everyone ,this is my VG,lv,please > see it more carefully,no changes > ! [root@www vol]# cat index.html hello ,everyone ,this is my VG,lv,please see it more carefully,no changes [root@www vol]# root@www /]# lvextend -l 256 /dev/volVG/vol /dev/cdrom: open failed: 只讀文件系統 Extending logical volume vol to 1.99 GB Logical volume vol successfully resized 已經添加到lv vol裡面去了; root@www /]# lvdisplay --- Logical volume --- LV Name /dev/volVG/vol VG Name volVG LV UUID go0Q37-aEfj-zCmw-H3Q8-dcR8-hGOe-2f7u7Q LV Write Access read/write LV Status available # open 1 LV Size 1.99 GB Current LE 509 Segments 3 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:1 先看看index.html依然沒什麼變化,這樣劃分空間是不是很方便了! 演示就到這裡了!· *****LVM 有一整套的命令集,下表列出了常用的命令. 任務 PV VG LV 創建 pvcreate vgcreate lvcreate 刪除 pvremove vgremove lvremove 掃描列表 pvscan vgscan lvscan 顯示屬性 pvdisplay vgdisplay lvdisplay 顯示信息 pvs vgs lvs 改變屬性 pvchange vgchange lvchange 擴展 vgextend lvextend 縮減 vgreduce lvreduce 重命名 vgrename lvrename 改變容量 pvresize lvresize 檢查一致性 pvck vgck 用戶可以使用如下命令顯示上述命令的功能: #pvcreate -h ****#vgscan:讀取系統中創建的所有卷組 #vgchange -a y :激活所有卷組 (開機執行,redhat可在/etc/rc.d/rc.sysinit系統啟動初始化腳本里可以找到) #vgchange -a n :關閉所有卷組(提示:在umount所有的文件系統后,才能成功執行 ****使用# pvremove –ff /dev/sda7 命令后,/dev/sda7設備丟失. [root@srv2 ~]# pvdisplay Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. --- Physical volume --- PV Name /dev/md4 VG Name VolGroup02 PV Size 3.91 GB / not usable 32.00 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 124 Free PE 0 Allocated PE 124 PV UUID DqhTMp-TS1g-BSbK-ySWa-d3za-3B0x-0AZdHX --- Physical volume --- PV Name /dev/md3 VG Name VolGroup01 PV Size 2.92 GB / not usable 12.00 MB Allocatable yes (but full) PE Size (KByte) 32768 Total PE 93 Free PE 0 Allocated PE 93 PV UUID gk0yn3-PVrf-lJVQ-052f-sL0K-msA3-OPtcUQ Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. --- Physical volume --- PV Name /dev/md1 VG Name VolGroup00 PV Size 776.25 MB / not usable 256.00 KB Allocatable yes PE Size (KByte) 4096 Total PE 194 Free PE 194 Allocated PE 0 PV UUID uREKkP-53pQ-Nhmn-JfsL-sfPT-eLvr-0HQfRJ Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. --- Physical volume --- PV Name unknown device VG Name VolGroup00 PV Size 250.98 MB / not usable 2.98 MB Allocatable yes PE Size (KByte) 4096 Total PE 62 Free PE 62 Allocated PE 0 PV UUID bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA [root@srv2 ~]# vgs Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. VG #PV #LV #SN Attr VSize VFree VolGroup00 2 0 0 wz-pn- 1.00G 1.00G VolGroup01 1 1 0 wz--n- 2.91G 0 VolGroup02 1 2 0 wz--n- 3.88G 0 [root@srv2 ~]# pvs Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. PV VG Fmt Attr PSize PFree /dev/md1 VolGroup00 lvm2 a- 776.00M 776.00M /dev/md3 VolGroup01 lvm2 a- 2.91G 0 /dev/md4 VolGroup02 lvm2 a- 3.88G 0 /dev/sda7 lvm2 -- 250.98M 250.98M unknown device VolGroup00 lvm2 a- 248.00M 248.00M [root@srv2 ~]# lvs -a -o devices Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. LV VG Attr LSize Origin Snap% Move Log Copy% Convert Devices LogVol00 VolGroup01 -wi-ao 2.91G /dev/md3(0) LogVol00 VolGroup02 -wi-ao 1.44G /dev/md4(78) LogVol01 VolGroup02 -wi-ao 2.44G /dev/md4(0) 解決: [root@srv2 ~]# pvcreate --uuid "bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA" 最好是:[root@srv2 ~]# pvcreate --uuid "bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA" --restorefile /etc/lvm/archive/VolGroup00_00017.vg /dev/sda7 Couldn't find device with uuid 'bEeyIg-347X-T3vl-MfOJ-kx1a-u7c4-6qqblA'. Physical volume "/dev/sda7" successfully created #pvs #vgs

本文出自 「netsword.blogchina.com」 博客,請務必保留此出處http://netsword.blog.51cto.com/13993/492333





[火星人 via ] Linux下磁碟分區與LVM創建已經有221次圍觀

http://www.coctec.com/docs/linux/show-post-49384.html