在linux虚拟机上添加几块硬盘
# ls –l /dev |grep sd
检查是否有新的设备产生,名称如sdx (其中SCSI设备名的格式为sdx,为sdxx为a,b,c 顺序,第一盘为sda,这个是装操作系统时就有的,第二个盘为sdb)
划分分区
使用fdisk对新加的硬盘进行分区 (其中设备名为/dev/sdx , x根据硬盘的顺序号从a,b,c等字母顺序)
1 进入fdisk菜单,使用相应命令
fdisk /dev/sdx
[root@localhostdev]# fdisk /dev/sdb
Device containsneither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOSdisklabel with disk identifier 0xba131224.
Changes willremain in memory only, until you decide to write them.
After that, ofcourse, the previous content won't be recoverable.
Warning: invalidflag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING:DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') andchange display units to
sectors (command 'u').
Command (m forhelp): p
Disk /dev/sdb:2147 MB, 2147483648 bytes
255 heads, 63sectors/track, 261 cylinders
Units = cylindersof 16065 * 512 = 8225280 bytes
Sector size(logical/physical): 512 bytes / 512 bytes
I/O size(minimum/optimal): 512 bytes / 512 bytes
Disk identifier:0xba131224
Device Boot Start End Blocks Id System
注意查看硬盘大小和分区内容确定是否新硬盘。
查看fdisk常用菜单命令
Command (m forhelp): 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 systemid
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
2.划分一个新的Linux分区
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number(1-4): 1
First cylinder(1-261, default 1):
Using defaultvalue 1
Last cylinder,+cylinders or +size{K,M,G} (1-261, default 261): +200M
Command (m forhelp): p
Disk /dev/sdb:2147 MB, 2147483648 bytes
255 heads, 63sectors/track, 261 cylinders
Units = cylindersof 16065 * 512 = 8225280 bytes
Sector size(logical/physical): 512 bytes / 512 bytes
I/O size(minimum/optimal): 512 bytes / 512 bytes
Disk identifier:0xba131224
Device Boot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
Command (m forhelp): w
The partitiontable has been altered!
Calling ioctl() tore-read partition table.
Syncing disks.
得到一个新的分区设备 /dev/sdb1
3 创建LVM的分区 /dev/sdb2、/dev/sdb3、/dev/sdb5
注意 /dev/sdb4为扩展分区,需占用/dev/sdb3之后的所有空间,然后再在扩展分区内分配/dev/sdb5空间
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (27-261, default 27):
Using default value 27
Last cylinder, +cylinders or +size{K,M,G} (27-261,default 261): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (53-261, default 53):
Using default value 53
Last cylinder, +cylinders or +size{K,M,G} (53-261,default 261): +200M
Command (m for help): n
Command action
e extended
p primary partition (1-4)
e
Selected partition 4
First cylinder (79-261, default 79):
Using default value 79
Last cylinder, +cylinders or +size{K,M,G} (79-261,default 261):
Using default value 261
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba131224
DeviceBoot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb3 53 78 208845 83 Linux
/dev/sdb4 79 261 1469947+ 5 Extended
Command (m for help): n
First cylinder (79-261, default 79):
Using default value 79
Last cylinder, +cylinders or +size{K,M,G} (79-261,default 261): +200M
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba131224
DeviceBoot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 83 Linux
/dev/sdb3 53 78 208845 83 Linux
/dev/sdb4 79 261 1469947+ 5 Extended
/dev/sdb5 79 104 208813+ 83 Linux
以下步骤修改分区/dev/sdb2 /dev/sdb3 /dev/sdb5类型,从83Linux修改为8eLinux LVM
Command (m for help): t
Partition number (1-5): 2
Hex code (type L to list codes): L
0 Empty 24 NEC DOS 81 Minix / old Lin bf Solaris
1 FAT12 39 Plan 9 82 Linux swap / So c1 DRDOS/sec (FAT-
2 XENIX root 3c PartitionMagic 83 Linux c4 DRDOS/sec (FAT-
3 XENIX usr 40 Venix 80286 84 OS/2 hidden C: c6 DRDOS/sec (FAT-
4 FAT16 <32M 41 PPC PReP Boot 85 Linux extended c7 Syrinx
5 Extended 42 SFS 86 NTFS volume set da Non-FS data
6 FAT16 4d QNX4.x 87 NTFS volume set db CP/M / CTOS / .
7 HPFS/NTFS 4e QNX4.x 2nd part 88 Linuxplaintext de Dell Utility
8 AIX 4f QNX4.x 3rd part 8e Linux LVM df BootIt
9 AIX bootable 50 OnTrack DM 93 Amoeba e1 DOS access
a OS/2 Boot Manag 51 OnTrack DM6 Aux 94 Amoeba BBT e3 DOS R/O
b W95 FAT32 52 CP/M 9f BSD/OS e4 SpeedStor
c W95 FAT32 (LBA) 53 OnTrack DM6 Aux a0 IBM Thinkpad hi eb BeOS fs
e W95 FAT16 (LBA) 54 OnTrackDM6 a5 FreeBSD ee GPT
f W95 Ext'd (LBA) 55 EZ-Drive a6 OpenBSD ef EFI (FAT-12/16/
10 OPUS 56 Golden Bow a7 NeXTSTEP f0 Linux/PA-RISC b
11 HiddenFAT12 5c Priam Edisk a8 Darwin UFS f1 SpeedStor
12 Compaqdiagnost 61 SpeedStor a9 NetBSD f4 SpeedStor
14 Hidden FAT16<3 63 GNU HURD or Sys ab Darwin boot f2 DOS secondary
16 HiddenFAT16 64 Novell Netware af HFS/ HFS+ fb VMware VMFS
17 HiddenHPFS/NTF 65 Novell Netware b7 BSDI fs fc VMware VMKCORE
18 ASTSmartSleep 70 DiskSecure Mult b8 BSDI swap fd Linux raid auto
1b Hidden W95FAT3 75 PC/IX bb Boot Wizard hid fe LANstep
1c Hidden W95FAT3 80 Old Minix be Solaris boot ff BBT
1e Hidden W95FAT1
Hex code (type L to list codes): 8e
Changed system type of partition 2 to 8e (Linux LVM)
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba131224
DeviceBoot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 8e Linux LVM
/dev/sdb3 53 78 208845 83 Linux
/dev/sdb4 79 261 1469947+ 5 Extended
/dev/sdb5 79 104 208813+ 83 Linux
按照上面的方法继续修改 /dev/sdb3 /dev/sdb5的类型为 8e (Linux LVM)
最后结果:
Command (m for help): p
Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0xba131224
DeviceBoot Start End Blocks Id System
/dev/sdb1 1 26 208813+ 83 Linux
/dev/sdb2 27 52 208845 8e Linux LVM
/dev/sdb3 53 78 208845 8e Linux LVM
/dev/sdb4 79 261 1469947+ 5 Extended
/dev/sdb5 79 104 208813+ 8e Linux LVM
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
创建PV、VG、LV和文件系统
1 创建物理卷PV
[root@localhost dev]# pvcreate /dev/sdb2
Writingphysical volume data to disk "/dev/sdb2"
Physicalvolume "/dev/sdb2" successfully created
[root@localhost dev]# set -o vi
[root@localhost dev]# pvcreate /dev/sdb3
Writingphysical volume data to disk "/dev/sdb3"
Physicalvolume "/dev/sdb3" successfully created
[root@localhost dev]# pvcreate /dev/sdb5
Writingphysical volume data to disk "/dev/sdb5"
Physicalvolume "/dev/sdb5" successfully created
2 创建卷组
[root@localhost dev]# vgcreate -s 8 myvg /dev/sdb2 /dev/sdb3/dev/sdb5
Volume group"myvg" successfully created
3 创建逻辑卷
[root@localhostdev]# lvcreate -n lv01 -L 180M /dev/myvg
Rounding upsize to full physical extent 184.00 MiB
Logical volume"lv01" created
# lvcreate -n lv02 -L 180M /dev/myvg
Rounding upsize to full physical extent 184.00 MiB
Logical volume"lv02" created
4 创建文件系统
# mkfs -t ext4 /dev/myvg/lv01
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
47104 inodes, 188416 blocks
9420 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
23 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193,24577, 40961, 57345, 73729
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accountinginformation: 完成
This filesystem will be automatically checked every 34mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost dev]# mkfs -t ext4 /dev/myvg/lv02
mke2fs 1.41.12 (17-May-2010)
文件系统标签=
操作系统:Linux
块大小=1024 (log=0)
分块大小=1024 (log=0)
Stride=0 blocks, Stripe width=0 blocks
47104 inodes, 188416 blocks
9420 blocks (5.00%) reserved for the super user
第一个数据块=1
Maximum filesystem blocks=67371008
23 block groups
8192 blocks per group, 8192 fragments per group
2048 inodes per group
Superblock backups stored on blocks:
8193,24577, 40961, 57345, 73729
正在写入inode表: 完成
Creating journal (4096 blocks): 完成
Writing superblocks and filesystem accountinginformation: 完成
This filesystem will be automatically checked every 31mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
5 挂载文件系统
[root@localhost dev]# mkdir -p /fs1/fs2
[root@localhost dev]# vi /fs1/fs2/file2
[root@localhost dev]# mount -t ext4 /dev/myvg/lv01 /fs1
[root@localhostdev]# df -h
文件系统 容量 已用 可用已用%% 挂载点
/dev/sda2 18G 2.2G 15G 14% /
tmpfs 376M 264K 376M 1% /dev/shm
/dev/sda1 291M 32M 245M 12% /boot
/dev/sr0 45M 45M 0 100% /media/CDROM_
/dev/sr1 2.9G 2.9G 0 100% /media/RHEL_6.2 i386 Disc 1
/dev/mapper/myvg-lv01
179M 5.6M 164M 4% /fs1
[root@localhostdev]# mkdir /fs1/fs2
[root@localhost dev]# vi /fs1/fs2/file2
[root@localhost dev]# pwd
/dev
[root@localhostdev]# mount -t ext4 /dev/myvg/lv02 /fs1/fs2
[root@localhost dev]# df -h
文件系统 容量 已用 可用已用%% 挂载点
/dev/sda2 18G 2.2G 15G 14% /
tmpfs 376M 264K 376M 1% /dev/shm
/dev/sda1 291M 32M 245M 12% /boot
/dev/sr0 45M 45M 0 100% /media/CDROM_
/dev/sr1 2.9G 2.9G 0 100% /media/RHEL_6.2 i386 Disc 1
/dev/mapper/myvg-lv01
179M 5.6M 164M 4% /fs1
/dev/mapper/myvg-lv02
179M 5.6M 164M 4% /fs1/fs2