先關閉虛擬機電源,做如下設置:“ 虛擬機”--“虛擬機設置”--“磁盤”--“擴展”

選擇添加好內存后 點擊 點擊"Expand“ 左邊第一個
可以隨意添加你需要增到到的磁盤大小(如15Gb,表示磁盤總量,包含原來的磁盤容量); 再重啟電源進入系統做如下步驟設置。
1. 啟動虛擬機系統,用root登錄(后續所有步驟都應以root用戶身份登錄操作),在 命令行用fdisk -l查看。由於這里是直接修改了原始空間大小,因此可以看到/dev/sda空間改變為16.1GB(原磁盤空間從10G增加到15G)。如果是從VMware菜單里增加虛擬硬盤,則會多出一個/dev/sd?,這里的?代表硬盤編號,第一個硬盤編號為a即sda,第二個就是sdb,第三個是sdc,以此類推,一般來說,如果以前沒有增加過硬盤,那么原來的硬盤就是sda,通過VMware菜單增加的虛擬硬盤編號就是sdb。如果添加的第二塊硬盤是IDE硬盤,就應該看到hdb,如果是 SCSI硬盤,看到的就應該是sdb。
使用linux下的fdisk工具進行分區
用root用戶登錄到你的linux系統,查看你系統的分區 如圖

根據提示信息可以判斷出此系統的磁盤接口為SCSI,對應“sda”如果上面的字體是“hda”,那么此系統的磁盤接口為IDE對應“hda”所以我做一下操作:
2.使用fdisk /dev/sda進入菜單項,m是列出菜單,p是列出分區表,n是增加分區,w是保存並推出。由於這里增加的磁盤只有5G,因此5G划為一個區。
[root@localhost ~]# fdisk /dev/sda The number of cylinders for this disk is set to 1958. There is nothing wrong with that, but this is larger than 1024, and could in certain setups cause problems with: 1) software that runs at boot time (e.g., old versions of LILO) 2) booting and partitioning software from other OSs (e.g., DOS FDISK, OS/2 FDISK) Command (m for help): p Disk /dev/sda: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 3 //fdisk會讓你選擇主分區的編號,如果已經有了主分區sda1,sda2,那么編號就選3,即要創建的該分區為sda3 First cylinder (1306-1958, default 1306): +1306//此時,fdisk又會讓你選擇該分區的開始值這個就是分區的Start 值(start cylinder);這里最好直接按回車 我選擇+1306 意思都一樣的 Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): +1958 //此時,fdisk又會讓你選擇該分區的開始值這個就是分區的End 值這里最好直接按回車 一樣的操作 Value out of range. Last cylinder or +size or +sizeM or +sizeK (1306-1958, default 1958): Using default value 1958 Command (m for help): p //再次查看列表分區 Disk /dev/sda: 16.1 GB, 16106127360 bytes 255 heads, 63 sectors/track, 1958 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Device Boot Start End Blocks Id System /dev/sda1 * 1 13 104391 83 Linux /dev/sda2 14 1305 10377990 8e Linux LVM /dev/sda3 1306 1958 5245222+ 83 Linux //增加了 /dev/sda3 但是 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: 設備或資源忙. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks. /dev/sda3 1306 1958 5245222+ 83 Linux
接着重啟
3. 使用mkfs.ext3 /dev/sda3 格式化分區
[root@localhost ~]# df -h #掛載前的分區情況 文件系統 容量 已用 可用 已用% 掛載點 /dev/mapper/VolGroup00-LogVol00 8.6G 2.8G 5.4G 35% / /dev/sda1 99M 12M 82M 13% /boot tmpfs 125M 0 125M 0% /dev/shm [root@localhost ~]# mkfs.ext3 /dev/sda3 //mkfs.ext3 /dev/sda3 格式化分區 mke2fs 1.39 (29-May-2006) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) 656000 inodes, 1311305 blocks 65565 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1346371584 41 block groups 32768 blocks per group, 32768 fragments per group 16000 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 31 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. [root@localhost ~]# cd / [root@localhost /]# mkdir /cm #增加一個/cm [root@localhost /]# mount /dev/sda3 /cm #掛載分區到 /cm [root@localhost /]# df -h #掛載后的分區情況 文件系統 容量 已用 可用 已用% 掛載點 /dev/mapper/VolGroup00-LogVol00 8.6G 2.8G 5.4G 35% / /dev/sda1 99M 12M 82M 13% /boot tmpfs 125M 0 125M 0% /dev/shm /dev/sda3 5.0G 139M 4.6G 3% /cm
//4.設置開機自動加載
創建加載點:mkdir /cm 掛載之后, 修改vi /etc/fstab 分區表文件,
在文件最后加上
/dev/sda3 /cm ext3 defaults 0 0 然后保存,重啟即可。
(注意:修改分區表如果有誤,將導致進不了linux桌面系統,但這時系統會進入commandline模式,我們可以在commandline模式下對有誤的fstab進行修復更改,不過默認情況下這個commandline模式會是Read-Only file system,這意味着你的任何修改操作都是不允許的,但可以通過命令 mount / -o remount,rw 來解除這個限制)。
擴展分區 完畢 ,相當於winOS 加上一塊硬盤並分區格式化
接下來,的操作相當於給winOS的 C盤擴展內存
liunx 根目錄擴展,使用剛才的加上的/dev/sda3 融進根內存
取消開機自己掛載
在文件最后加上
/dev/sda3 /cm ext3 defaults 0 0 然后保存,重啟即可。
這一步注釋掉
4. 我們的新建分區/dev/sda3,卻不是LVM的。所以,接下來使用fdisk將其改成LVM的
# fdisk /dev/sda Command (m for help): m Command (m for help): t //改變分區系統id Partition number (1-4): 3 //指定分區號 Hex code (type L to list codes): 8e //指定要改成的id號,8e代表LVM Changed system type of partition 3 to 8e (Linux LVM) Command (m for help): w
5、重啟系統后,登陸系統。(一定要重啟系統,否則無法擴充新分區)
6.格式化該新添加的分區
[root@localhost ~]# fdisk -l Disk /dev/sda: 10.7 GB, 10737418240 bytes 255 heads, 63 sectors/track, 1305 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: 0x0000bcfb 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 784 5778432 8e Linux LVM Partition 2 does not end on cylinder boundary. /dev/sda3 784 1305 4190956+ 8e Linux LVM Disk /dev/mapper/VolGroup-lv_root: 5272 MB, 5272240128 bytes 255 heads, 63 sectors/track, 640 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: 0x00000000 Disk /dev/mapper/VolGroup-lv_swap: 641 MB, 641728512 bytes 255 heads, 63 sectors/track, 78 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: 0x00000000
你會發現多了一塊分區 結尾是 Linux LVM
# mkfs -t ext3 /dev/sda3 //在硬盤分區“/dev/sda3”上創建“ext3”文件系統 mke2fs 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 2621440 inodes, 10484755 blocks 524237 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 320 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
# mkfs -t ext3 /dev/sda3 //在硬盤分區“/dev/sda3”上創建“ext3”文件系統
mke2fs 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 2621440 inodes, 10484755 blocks 524237 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=4294967296 320 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 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 23 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
此時我們就可以使用該新增分區啦:
# pvcreate /dev/sda3 Physical volume "/dev/sda3" successfully created # pvcreate /dev/sda3 //pvcreate指令用於將物理硬盤分區初始化為物理卷,以便被LVM使用。要創建物理卷必須首先對硬盤進行分區,並且將硬盤分區的類型設置為“8e”后,才能使用pvcreat指令將分區初始化為物理卷 Physical volume "/dev/sda3" successfully created # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 18G 1.7G 15G 10% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot # vgextend /dev/mapper/VolGroup-lv_root /dev/sda3 //其中是當前需要擴充的lvm組名,可以通過df -h查看,例如我的是: /dev/mapper/VolGroup-lv_root) //vgextend指令用於動態的擴展卷組,它通過向卷組中添加物理卷來增加卷組的容量 Volume group name VolGroup/lv_root has invalid characters # vgextend /dev/mapper/VolGroup /dev/sda3 //原來這個組名,是-之前的字符串——這要是沒有文章看着對比分析,誰知道啊? Volume group "VolGroup" successfully extended #vgdisplay //用於顯示LNM卷組的元數據信息 --- Volume group --- VG Name VolGroup System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 4 VG Access read/write VG Status resizable MAX LV 0 Cur LV 2 Open LV 2 Max PV 0 Cur PV 2 Act PV 2 VG Size 59.50 GiB PE Size 4.00 MiB Total PE 15232 Alloc PE / Size 4994 / 19.51 GiB Free PE / Size 10238 / 39.99 GiB VG UUID Ecv3ml-86eg-LTsH-mALD-mLxW-v3Ao-GEqiFc (主要查看Free PE / Size 10238 / 39.99 GiB,說明我們最多可以有39.99GB的擴充空間。我一般選擇小於等於39.99GB) # lvextend -L +39.99G /dev/VolGroup/lv_root /dev/sda3 Rounding size to boundary between physical extents: 39.99 GiB Extending logical volume lv_root to 57.56 GiB Logical volume lv_root successfully resized # e2fsck -f /dev/VolGroup/lv_root e2fsck 1.41.12 (17-May-2010) /dev/VolGroup/lv_root is mounted. e2fsck: Cannot continue, aborting. # resize2fs /dev/VolGroup/lv_root resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/VolGroup/lv_root is mounted on /; on-line resizing required old desc_blocks = 2, new_desc_blocks = 4 Performing an on-line resize of /dev/VolGroup/lv_root to 15089664 (4k) blocks. The filesystem on /dev/VolGroup/lv_root is now 15089664 blocks long. # df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/VolGroup-lv_root 57G 1.7G 53G 3% / tmpfs 1.9G 0 1.9G 0% /dev/shm /dev/sda1 485M 32M 428M 7% /boot
可以看到,這個邏輯卷已經成功的擴容,根目錄又可以裝更多東西了!
本機

未分區之前:

/*********************/
