- 查看磁盘信息
fdisk -l
- 启动VMware环境下的Linux操作系统,添加新分区,需要root账号身份。
fdisk /dev/sda # 后边参数为指定的扩容的磁盘
命令行提示下输入【m】 输入命令【n】添加新分区。 输入命令【p】创建主分区。 输入【回车】,选择默认大小,这样不浪费空间 输入【回车】,选择默认的start cylinder。 输入【w】,保持修改
- 重启linux,格式化 /dev/sda3
sudo reboot
- 操作示例
[root@master /]# fdisk /dev/sda
WARNING: The size of this disk is 3.7 TB (3688303165440 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): p
Disk /dev/sda: 3688.3 GB, 3688303165440 bytes
255 heads, 63 sectors/track, 448410 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: 0x00000b93
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
Command (m for help): ^C
[root@master /]# fdisk /dev/sda
WARNING: The size of this disk is 3.7 TB (3688303165440 bytes).
DOS partition table format can not be used on drives for volumes
larger than (2199023255040 bytes) for 512-byte sectors. Use parted(1) and GUID
partition table format (GPT).
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 3
First cylinder (2611-448410, default 2611):
Using default value 2611
Last cylinder, +cylinders or +size{K,M,G} (2611-267349, default 267349):
Using default value 267349
Command (m for help): p
Disk /dev/sda: 3688.3 GB, 3688303165440 bytes
255 heads, 63 sectors/track, 448410 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: 0x00000b93
Device Boot Start End Blocks Id System
/dev/sda1 * 1 64 512000 83 Linux
Partition 1 does not end on cylinder boundary.
/dev/sda2 64 2611 20458496 8e Linux LVM
/dev/sda3 2611 267349 2126509322+ 83 Linux
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): 8e
Changed system type of partition 3 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@master /]# mke2fs /dev/sda3
1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
132907008 inodes, 531627330 blocks
26581366 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
16224 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872, 71663616, 78675968,
102400000, 214990848, 512000000
Writing inode tables: done
Creating journal (32768 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.
- 查看挂载点
[root@master ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_master-lv_root
18G 16G 1.1G 94% /
tmpfs 1.4G 12K 1.4G 1% /dev/shm
/dev/sda1 477M 52M 400M 12% /boot
- 添加新LVM到已有的LVM组,实现扩容
lvm 进入lvm管理
lvm> pvcreate /dev/sda3 这是初始化刚才的分区,必须的
lvm> vgextend vg_master /dev/sda3 将初始化过的分区加入到虚拟卷组vg_master (查看虚拟卷组命令:vgdisplay)
lvm>lvextend -L +29.9G /dev/vg_master/lv_root 扩展已有卷的容量(29.9G这个数字在后面解释)
lvm>pvdisplay 查看卷容量,这时你会看到一个很大的卷了
lvm>quit 退出
- 上步只是卷扩容了,下面是文件系统的真正扩容
[root@master ~]# resize2fs -p /dev/vg_master/lv_root 30g //增加分区至30g
- 再次查看分区信息
[root@master ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/vg_master-lv_root
30G 16G 13G 55% /
tmpfs 1.4G 12K 1.4G 1% /dev/shm
/dev/sda1 477M 52M 400M 12% /boo