給虛機添加新的磁盤分區

簡單記錄一下給虛擬機添加新的磁盤分區的步驟。

 


首先關閉虛擬機,然後選擇設置,添加硬盤,創建一個虛擬磁盤,選擇SCSI類型,設置磁盤的容量,並指定保存的操作系統文件名稱。

下面就可以啓動虛擬機。

登陸到虛擬機,切換到root用戶:

[root@yangtk ~]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3142384 2963560 16624 100% /
/dev/sda1 101086 10876 84991 12% /boot
/dev/mapper/VolGroup00-LogVol03
8919192 6665924 1792880 79% /data
tmpfs 257800 0 257800 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02
1015704 34452 928824 4% /tmp
[root@yangtk disk]# cd /dev/disk/by-path
[root@yangtk by-path]# ls -l
total 0
lrwxrwxrwx 1 root root 9 Oct 21 06:00 pci-0000:00:07.1-ide-0:0 -> ../../hdc
lrwxrwxrwx 1 root root 9 Oct 21 06:00 pci-0000:00:10.0-scsi-0:0:0:0 -> ../../sda
lrwxrwxrwx 1 root root 10 Oct 21 06:00 pci-0000:00:10.0-scsi-0:0:0:0-part1 -> ../../sda1
lrwxrwxrwx 1 root root 10 Oct 21 06:00 pci-0000:00:10.0-scsi-0:0:0:0-part2 -> ../../sda2
lrwxrwxrwx 1 root root 9 Oct 21 06:00 pci-0000:00:10.0-scsi-0:0:1:0 -> ../../sdb
[root@yangtk by-path]# fdisk /dev/sdb -l

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Disk /dev/sdb doesn't contain a valid partition table
[root@yangtk by-path]# fdisk /dev/sdb (進行分區)
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.

Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)

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 default value 1
Last cylinder or +size or +sizeM or +sizeK (1-261, default 261):
Using default value 261

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
[root@yangtk by-path]# fdisk /dev/sdb -l

Disk /dev/sdb: 2147 MB, 2147483648 bytes
255 heads, 63 sectors/track, 261 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes

Device Boot Start End Blocks Id System
/dev/sdb1 1 261 2096451 8e Linux LVM
[root@yangtk by-path]# mkdir /data1
[root@yangtk by-path]# mount -t ext3 /dev/sdb1 /data1
mount: wrong fs type, bad option, bad superblock on /dev/sdb1,
missing codepage or other error
In some cases useful info is found in syslog - try
dmesg | tail or so

[root@yangtk by-path]# mkfs.ext3 /dev/sdb1 (製作文件系統)
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
262144 inodes, 524112 blocks
26205 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=536870912
16 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912

Writing inode tables: done
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 27 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@yangtk by-path]# mount -t ext3 /dev/sdb1 /data1 (掛載分區)
[root@yangtk by-path]# df -k
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/VolGroup00-LogVol00
3142384 2963564 16620 100% /
/dev/sda1 101086 10876 84991 12% /boot
/dev/mapper/VolGroup00-LogVol03
8919192 6665924 1792880 79% /data
tmpfs 257800 0 257800 0% /dev/shm
/dev/mapper/VolGroup00-LogVol02
1015704 34452 928824 4% /tmp
/dev/sdb1 2063504 35880 1922804 2% /data1

登陸到系統,新添加的分區不會自動加載,需要在linux環境下去手工mount,首先檢查新增的磁盤在linux中對應的設備名稱。

使用fdisk爲磁盤分區建立分區表,並設置爲Linux LVM類型。

下面仍然不能直接mount,否則會報錯:wrong fs type, bad option, bad superblock on /dev/sdb1

需要使用mkfs建立文件系統,下面就可以通過mount命令來加載這個磁盤了。

如果需要系統重啓後可以自動加載,需要將其添加到/etc/fstab文件中,在文件中加入下面的內容既可。

/dev/sdb1 /data1 ext3 defaults 1 2

 

本文來自: (www.91linux.com) 詳細出處參考:http://www.91linux.com/html/article/partition/20091020/17981.html

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章