Linux系统vbox虚拟机添加新磁盘方法

2016-11-12

通过 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

然后重启下,再次查看挂载情况,正常挂载,成功。

更多相关阅读

最新发布的文章