萬盛學電腦網

 萬盛學電腦網 >> Linux教程 >> Linux系統vbox虛擬機添加新磁盤方法

Linux系統vbox虛擬機添加新磁盤方法

  通過 fdisk查看現在物理磁盤的信息(這個要用root權限才行)

  以下操作均是root權限。

  [root@orangleliu ~]# fdisk -l

  ...

  Disk /dev/sdb: 32.2 GB, 32212254720 bytes

  255 heads, 63 sectors/track, 3916 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

  ...

  寫分區表

  下面是個交互是過程,每次輸入之後根據提示,在進行輸入

  [root@orangleliu ~]# fdisk /dev/sdb

  Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel

  Building a new DOS disklabel with disk identifier 0xa4378777.

  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)

  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): 1

  First cylinder (1-3916, default 1):

  Using default value 1

  Last cylinder, +cylinders or +size{K,M,G} (1-3916, default 3916):

  Using default value 3916

  Command (m for help): w

  The partition table has been altered!

  Calling ioctl() to re-read partition table.

  Syncing disks.

  操作完之後我們再來看磁盤信息

  # fdisk -l

  ...

  Disk /dev/sdb: 32.2 GB, 32212254720 bytes

  255 heads, 63 sectors/track, 3916 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: 0xa4378777

  Device Boot Start End Blocks Id System

  /dev/sdb1 1 3916 31455238+ 83 Linux

  ...

  多了一塊分區信息

  格式化分區

  一個命令就可以搞定了

  # mkfs.ext4 /dev/sdb1

  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

  1966080 inodes, 7863809 blocks

  393190 blocks (5.00%) reserved for the super user

  First data block=0

  Maximum filesystem blocks=4294967296

  240 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

  ?

  Writing inode tables: done

  Creating journal (32768 blocks): done

  Writing superblocks and filesystem accounting information: done

  This filesystem will be automatically checked every 26 mounts or

  180 days, whichever comes first. Use tune2fs -c or -i to override.

  創建新卷標(可忽略)

  這一步,我看到有些人做了,有些人沒有做,於是查了下資料。

  可以看下參考 e2label命令

  後面沒用上,可以不操作的。

  # e2label /dev/sdb1 /data

  檢查一下

  # e2label /dev/sdb1

  /data

  掛載

  創建掛載目錄,跟上一步一致

  mkdir /data

  為了開機自動掛載,還需要編輯 /etc/fstab 文件,文件後面添加一行

  /dev/sdb1 /data ext4 defaults 0 0

  有些可能對這個配置文件不太熟悉,請參見[fatab中文解釋](https://wiki.archlinux.org/index.php/Fstab_(%E7%AE%80%E4%BD%93%E4%B8%AD%E6%96%87)

  測試

  # mount -a

  # df -lh

  Filesystem Size Used Avail Use% Mounted on

  /dev/mapper/vg_orangleliu-lv_root

  6.5G 3.2G 3.0G 52% /

  tmpfs 499M 0 499M 0% /dev/shm

  /dev/sda1 477M 29M 424M 7% /boot

  /dev/sdb1 30G 44M 28G 1% /data

  然後重啟下,再次查看掛載情況,正常掛載,成功。

copyright © 萬盛學電腦網 all rights reserved