建立虛拟硬碟
1、關閉VM中正在運作的虛拟系統;
2、EDIT Virtual Machine Settings;
3、在Hardware頁點“Add”-》Add a hard disk-》Create a new virtual disk-》SCSI(recommended)-》配置設定空間大小-》OK;
4、可以看見Hardware中出現了一塊新的硬碟Hard Disk 2。
對虛拟硬碟進行分區和格式化
[[email protected] data1]# fdisk -l ## 這裡是檢視目前系統上有幾塊硬碟
Disk /dev/sda: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 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 1530 10241437+ 83 Linux
/dev/sda3 4296 4425 1044225 82 Linux swap
/dev/sda4 1531 4295 22209862+ f Win95 Ext'd (LBA)
/dev/sda5 1531 2805 10241406 83 Linux
/dev/sda6 2806 4295 11968393+ 83 Linux
Partition table entries are not in disk order
Disk /dev/sdb: 36.7 GB, 36703918080 bytes ## 這裡發現/dev/sdb,容量36.7G,切未被分區
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdc doesn't contain a valid partition table
[[email protected] root]# fdisk /dev/sdb ## 接下去就對/dev/sdb分區進行分區
The number of cylinders for this disk is set to 4462.
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): 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 system id
u change display/entry units
v verify the partition table
w write table to disk and exit
x extra functionality (experts only)
Command (m for help): p ## 列印出目前該硬碟下的分區清單
Disk /dev/sdb: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
Command (m for help): n ## 增加一個分區
Command action
e extended
p primary partition (1-4)
## 因為通常選擇主分區,是以這裡打一個p
p
Partition number (1-4): 1 ## 這裡因為是第一個分卻,是以隻選擇1,如果是第二個分區,則選擇2,依次類推
First cylinder (1-4462, default 1): ## 新分區起始的磁盤塊數
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-4462, default 4462): 如果要分區10G,這裡可以直接輸入:+10240M,因為這裡要全部使用硬碟空間,則用預設
Using default value 4462
Command (m for help): p
Disk /dev/sdb: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 4462 35840983+ 83 Linux
## 這裡第一個分區已經分好了,接下去得把這個分區寫入硬碟,用w
Command (m for help): w
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
下面的工作就是對該硬碟進行格式,我這裡是格式化成ext3
[[email protected] root]# mkfs.ext3 /dev/sdb1 (這裡原來的指令是:mke2fs -j /dev/sdb1,試了一下不成 功,改了)
mke2fs 1.32 (09-Nov-2002)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
4480448 inodes, 8960245 blocks
448012 blocks (5.00%) reserved for the super user
First data block=0
274 block groups
32768 blocks per group, 32768 fragments per group
16352 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 (8192 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.
檢查一下,是否已經格式好
[[email protected] root]# fdisk -l
Disk /dev/sda: 36.4 GB, 36401479680 bytes
255 heads, 63 sectors/track, 4425 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 1530 10241437+ 83 Linux
/dev/sda3 4296 4425 1044225 82 Linux swap
/dev/sda4 1531 4295 22209862+ f Win95 Ext'd (LBA)
/dev/sda5 1531 2805 10241406 83 Linux
/dev/sda6 2806 4295 11968393+ 83 Linux
Partition table entries are not in disk order
Disk /dev/sdb: 36.7 GB, 36703918080 bytes
255 heads, 63 sectors/track, 4462 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 4462 35840983+ 83 Linux
挂載虛拟硬碟
分區分好,也格式化好了,下面就是挂載
我把/dev/sdb1挂載到/data1下
[[email protected] root]# mkdir /data1 ## 首先建立挂載的目錄data1
[[email protected] root]# mount /dev/sdb1 /data1 ##将sdb1挂載到data1
重新開機系統之後,檢視是否挂載成功:
[[email protected] data1]# df -h
檔案系統 容量 已用 可用 已用% 挂載點
/dev/sda1 2.0G 454M 1.4G 25% /
/dev/sda6 12G 53M 11G 1% /bak
/dev/sdb1 34G 33M 32G 1% /data1
none 250M 0 250M 0% /dev/shm
/dev/sda2 9.7G 1.5G 7.7G 17% /usr
/dev/sda5 9.7G 8.6G 559M 95% /var
這裡看到/dev/sda6 12G 53M 11G 1% /bak
說明已經挂載成功了。到根目錄“/”下可以檢視到這個挂載好的data1。
轉移資料
其實一直做到這裡都還隻是準備工作,如果根分區下的資料不轉移到這個虛拟硬碟中的話,還是會提示空間不足。下面是将/usr全部轉移到虛拟硬碟中的過程(參考Linux人生的《Linux系統精華之一——挂載》),同樣也可以轉移其他目錄:
1、将/usr中的全部資料拷貝到data1(可以用mv一個一個拷貝,也可以用tar壓縮之後一次拷貝,具體參見這兩個指令的man)
2、清空usr目錄:
# rm -r /usr
# mkdir /usr
3、解除安裝剛才挂上的虛拟硬碟,重新将它挂載到usr目錄:
# umount /dev/sdb1 /data1
# mount /dev/sdb1 /usr
4、# vi /etc/fstab ## 用vi修改/etc/fstab,使系統啟動就可以自動挂載
(點選“i”進入插入模式對文本内容進行修改,改好後點“Esc”,輸入冒号“:”進入指令行模式,輸入wq儲存退出,具體操作可以參考vi常用指令)
在内容中加上一行:
/dev/sdb1 /usr ext3 defaults 1 2
5、Ok,重新啟動之後,可以檢視現在的硬碟使用情況了:
# df -h
檔案系統 容量 已用 可用 已用% 挂載點
/dev/sda2 3.6G 1.3G 2.4G 35% /
udev 125M 124K 125M 1% /dev
/dev/sdb1 4.0G 2.3G 1.6G 60% /usr
根分區的“已用%”從99%降到了35%,哈哈,大功告成,可以繼續做其他的事情了。不過這次添加的虛拟硬碟還是比較小,完全可以在添加的時候設得大一點的。美中不足。