700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > linux中如何新建一个磁盘 如何在Linux操作系统中新建磁盘分区

linux中如何新建一个磁盘 如何在Linux操作系统中新建磁盘分区

时间:2021-02-24 09:30:52

相关推荐

linux中如何新建一个磁盘 如何在Linux操作系统中新建磁盘分区

判断虚拟机初始化磁盘的容量大小。

小于2TB时请执行步骤 2。

大于等于2TB时请执行步骤 21。

登录虚拟机,在操作系统桌面上单击右键,选择“打开终端”,进入命令行界面。

http://localhost:7890/pages/31188558/03/31188558/03/resources/public_sys-resources/icon-note.gif

执行以下命令,查看被扩容的磁盘。

fdisk -l

回显如下类似信息,说明“/dev/xvde”磁盘已扩容至40GB,且磁盘下已有分区“/dev/xvde3”。

Disk /dev/xvde: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x1a1453ef Device Boot Start End Blocks Id System /dev/xvde3 1 3916 31455238+ 83 Linux

执行以下命令,进入fdisk模式。

本步骤中以“/dev/xvde”为例。

fdisk /dev/xvde

屏幕回显如下:

... Command (m for help):

输入“n”,按“Enter”,开始新建分区。

屏幕回显如下:

... Command action e extended p primary partition (1-4)

输入“p”,按“Enter”。

本步骤中以创建一个主分区为例,说明分区创建过程。

屏幕回显如下:

Partition number (1-4):

输入主分区编号,按“Enter”。

本步骤中以“4”为例。

屏幕回显如下:

... First cylinder (3917-5221, default 3917):

按“Enter”。

本步骤中使用默认初始磁柱编号为例。

屏幕回显如下:

... Using default value 3917 Last cylinder, +cylinders or +size{K,M,G} (3917-5221, default 5221):

按“Enter”。

本步骤中使用默认截止磁柱编号为例。

屏幕回显如下:

... Using default value 5221 Command (m for help):

输入“p”,按“Enter”,查看新建分区。

屏幕回显如下:

... Disk /dev/xvde: 42.9 GB, 42949672960 bytes 255 heads, 63 sectors/track, 5221 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Disk identifier: 0x1a1453ef Device Boot Start End Blocks Id System /dev/xvde3 1 3916 31455238+ 83 Linux /dev/xvde4 3917 5221 10482412+ 83 Linux

输入“w”,按“Enter”。

将分区结果写入分区表中,分区创建完毕。

屏幕回显如下:

The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot. Syncing disks.

执行以下命令,重启虚拟机。

reboot

虚拟机重启完成后,执行以下命令,将新建分区文件系统设为ext3格式。

本步骤中以“ext3”文件格式为例。

mkfs -t ext3 /dev/xvde4

屏幕回显如下:

... Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

执行以下命令,将新建分区挂载到“/mnt/new”目录下。

本步骤中以“/mnt/new”为例。

mkdir /mnt/new

mount /dev/xvde4 /mnt/new

执行以下命令,查看挂载结果。

df -TH

屏幕回显如下:

文件系统 类型 容量 已用 可用 已用% 挂载点 ... /dev/xvde4 ext3 11G 158M 9.9G 2% /mnt/new

是否需要将新增磁盘设置为开机自动挂载?

是,执行步骤 17。

否,任务结束。

执行以下命令,使用VI编辑器打开“fstab”文件。

vi /etc/fstab

按“i”,进入编辑模式。

将光标移至文件末尾,按“Enter”,添加一行命令。

/dev/xvde4 /mnt/new ext3 defaults 1 1

按“ESC”后,输入“:wq”,按“Enter”。

保存设置并退出编辑器。

该步骤执行完,任务结束。

登录虚拟机,在操作系统桌面上单击右键,选择“打开终端”,进入命令行界面。

执行以下命令,查看被扩容的磁盘。

parted /dev/xvde

屏幕回显如下: ... (parted)

输入“p”,按“Enter”。

判断屏幕回显信息。

若屏幕回显如下信息请输入“Fix”,按“Enter”后继续执行步骤 24;否则直接执行步骤 24。

... Error: The backup GPT table is not at the end of the disk, as it should be. This might mean that another operating system believes the disk is smaller. Fix, by moving the backup to the end (and removing the old backup)? Fix/Ignore/Cancel?

若屏幕回显如下信息请输入“Fix”,按“Enter”后继续执行步骤 25;否则直接执行步骤 25。

... Warning: Not all of the space available to /dev/xvde appears to be used, you can fix the GPT to use all of the space (an extra 209715200 blocks) or continue with the current setting? Fix/Ignore?

若屏幕回显如下信息请输入“Fix”,按“Enter”后继续执行步骤 25;否则直接执行步骤 25。 ... Warning: Not all of the space available to /dev/xvde appears to be used, you can fix the GPT to use all of the space (an extra 209715200 blocks) or continue with the current setting? Fix/Ignore?

屏幕回显如下信息时请输入“unit GiB print”,按“Enter”。 Disk /dev/xvde: 2306GB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 17.4kB 2199GB 2199GB ext3 primary , , , , , , , , , , , (parted)

屏幕回显如下: Disk /dev/xvde: 2148GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 0.00GiB 2048GiB 2048GiB ext3 primary , , , , , , , , , , , (parted)

输入“mkpart”,按“Enter”,进行新建分区操作。

屏幕回显如下:

... Partition name? []?

输入新建分区名称,这里以“TestExtend”为例,输入“TestExtend”,按“Enter”。

屏幕回显如下:

... File system type? [ext2]?

输入新建分区文件系统类型,这里以“ext3”为例,输入“ext3”,按“Enter”。

屏幕回显如下:

... Start?

输入新建分区起始位置,这里以“2050GiB”为例,输入“2050GiB”,按“Enter”。

屏幕回显如下:

... End?

输入新建分区结束位置,这里以“2100GiB”为例,输入“2100GiB”,按“Enter”。

屏幕回显如下:

... End?

输入“p”,查看新建分区信息。

屏幕回显如下:

Disk /dev/xvde: 2148GiB Sector size (logical/physical): 512B/512B Partition Table: gpt Number Start End Size File system Name Flags 1 0.00GiB 2048GiB 2048GiB ext3 primary , , , , , , , , , , , 2 2050GiB 2100GiB 50.0GiB TestExtend , , , , , , , , , , , (parted)

记录新建分区ID对应标记号“2”,即新建分区为“/dev/xvde2”。

输入“quit”,返回虚拟机命令行界面。

执行以下命令,对新建分区进行格式化操作。

mkfs.ext3 /dev/xvde2

屏幕回显如下:

... Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 24 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.

执行以下命令,将新建分区挂载到指定目录下。这里以“/mnt/testextend”为例。

mkdir /mnt/testextend

mount /dev/xvde2 /mnt/testextend

执行以下命令,查看挂载结果。

df -TH

屏幕回显如下:

Filesystem Type Size Used Avail Use% Mounted on ... /dev/xvde2 ext3 53G 189M 50G 1% /mnt/testextend

是否需要将新增磁盘设置为开机自动挂载?

是,执行步骤 37。

否,任务结束。

执行以下命令,使用VI编辑器打开“fstab”文件。

vi /etc/fstab

按“i”,进入编辑模式。

将光标移至文件末尾,按“Enter”,添加一行命令。

/dev/xvde2 /mnt/testextend ext3 defaults 1 1

按“ESC”后,输入“:wq”,按“Enter”。

保存设置并退出编辑器。

该步骤执行完,任务结束。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。