linux分区划分先后顺序,linux划分分区并挂载磁盘

划分分区并挂载磁盘

本操作以该场景为例,当云服务器挂载了一块新的数据盘时,需要将该数据盘设为主分区,文件系统设为ext4格式,挂载在“/mnt/sdc”目录下,并设置开机启动自动挂载。

1.      执行以下命令,查看新增数据盘。

fdisk -l

[root@pdkcjt-int-zjxrpt-xrapp01 dev]# fdisk -l

Disk /dev/vda: 107.4 GB, 107374182400 bytes

16 heads, 63 sectors/track, 208050 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x000cb3b2

Device Boot Start End Blocks Id System

/dev/vda1 * 3 1018 512000 83 Linux

Partition 1 does not end on cylinder boundary.

/dev/vda2 1018 83221 41430016 8e Linux LVM

Partition 2 does not end on cylinder boundary.

Disk /dev/vdb: 214.7 GB, 214748364800 bytes

16 heads, 63 sectors/track, 416101 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x00000000

Disk /dev/mapper/VolGroup-lv_root: 38.2 GB, 38193332224 bytes

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

Disk /dev/mapper/VolGroup-lv_swap: 4227 MB, 4227858432 bytes

255 heads, 63 sectors/track, 514 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@pdkcjt-int-zjxrpt-xrapp01 dev]#

其中Disk /dev/vdb: 214.7 GB是新增数据盘。

执行以下命令,进入fdisk模式,开始对新增数据盘执行分区操作。

fdisk /dev/vdb

[root@pdkcjt-int-zjxrpt-xrapp01 home]# fdisk  /dev/vdb

-bash: fdisk : command not found

[root@pdkcjt-int-zjxrpt-xrapp01 home]# fdisk /dev/vdb

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

Building a new DOS disklabel with disk identifier 0x0735cc6b.

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”,按“Enter”,开始新建分区。

Command (m for help): n

Command action

e extended

p primary partition (1-4)

表示磁盘有两种分区类型:

“p”表示主要分区。

“e”表示延伸分区。

以创建一个主要分区为例,输入“p”,按“Enter”,开始创建一个主分区。

“Partition number”表示主分区编号,可以选择1-4。

以分区编号选择“1”为例,输入主分区编号“1”,按“Enter”。

“First cylinder”表示初始磁柱区域,可以选择2048-20971519,默认为1,不输入按回车表是默认。

回显类似如下信息,“Last cylinder”表示截止磁柱区域,可以选择1-416101,默认为416101

Command (m for help): n

Command action

e extended

p primary partition (1-4)

p

Partition number (1-4): 1

First cylinder (1-416101, default 1): 1

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

Using default value 416101

Command (m for help):

输入“p”,按“Enter”,查看新建分区的详细信息。

Command (m for help): p

Disk /dev/vdb: 214.7 GB, 214748364800 bytes

16 heads, 63 sectors/track, 416101 cylinders

Units = cylinders of 1008 * 512 = 516096 bytes

Sector size (logical/physical): 512 bytes / 512 bytes

I/O size (minimum/optimal): 512 bytes / 512 bytes

Disk identifier: 0x0735cc6b

Device Boot Start End Blocks Id System

/dev/vdb1 1 416101 209714872+ 83 Linux

Command (m for help):

输入“w”,按“Enter”,将分区结果写入分区表中。

Command (m for help): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

表示分区创建完成。

执行partprobe命令,将新的分区表同步到数据盘上。

如果没有找到命令 安装

yum -y install parted

[root@pdkcjt-int-zjxrpt-xrapp01 home]# partprobe

Warning: WARNING: the kernel failed to re-read the partition table on /dev/vda (设备或资源忙). As a result, it may not reflect all of your changes until after reboot.

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

执行以下命令,将新建分区文件系统设为系统所需格式。

mkfs -t文件系统格式/dev/vdb

以设置文件系统为“ext4”为例:

mkfs -t ext4 /dev/vdb

mkfs -t ext4 /dev/vdb

[root@pdkcjt-int-zjxrpt-xrapp01 home]# mkfs -t ext4 /dev/vdb

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

13107200 inodes, 52428800 blocks

2621440 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=4294967296

1600 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, 7962624, 11239424, 20480000, 23887872

正在写入inode表: 完成

Creating journal (32768 blocks): 完成

riting superblocks and filesystem accounting information: 完成

This filesystem will be automatically checked every 24 mounts or

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

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

格式化需要等待一段时间,请观察系统运行状态,不要退出。

执行以下mkdir命令,新建挂载路径。

以新建挂载路径“/mnt/sdc”为例:

[root@pdkcjt-int-zjxrpt-xrapp01 home]# mkdir /mnt/sdc

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

执行以下命令,将新建分区挂载到新建的路径下。

mount /dev/vdb挂载路径

[root@pdkcjt-int-zjxrpt-xrapp01 home]# mount /dev/vdb /mnt/sdc

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

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

df -TH

[root@pdkcjt-int-zjxrpt-xrapp01 home]# df -TH

Filesystem Type Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root ext4 38G 3.9G 32G 11% /

tmpfs tmpfs 8.4G 0 8.4G 0% /dev/shm

/dev/vda1 ext4 508M 34M 449M 7% /boot

/dev/vdb ext4 212G 197M 201G 1% /mnt/sdc

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

设置开机自动挂载磁盘

如果您需要在云服务器系统启动时自动挂载磁盘,不能采用在 /etc/fstab直接指定 /dev/xvdb1的方法,因为云中设备的顺序编码在关闭或者开启云服务器过程中可能发生改变。推荐使用UUID来配置自动挂载数据盘。

说明:

磁盘的UUID(universally unique identifier)是Linux系统为存储设备提供的唯一的标识字符串。

执行如下命令,查询磁盘分区的UUID。

blkid磁盘分区

[root@pdkcjt-int-zjxrpt-xrapp01 home]# blkid /dev/vdb

/dev/vdb: UUID="d2bd3d45-7ca6-4922-98d3-85ec074a0cad" TYPE="ext4"

[root@pdkcjt-int-zjxrpt-xrapp01 home]#

使用VI编辑器打开“fstab”文件。

vi /etc/fstab

在文件末尾添加:

UUID=d2bd3d45-7ca6-4922-98d3-85ec074a0cad /mnt/sdc      ext4 defaults     0   2

[root@pdkcjt-int-zjxrpt-xrapp01 home]# vi /etc/fstab

#

# /etc/fstab

# Created by anaconda on Tue Oct 18 13:13:32 2016

#

# Accessible filesystems, by reference, are maintained under '/dev/disk'

# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info

#

/dev/mapper/VolGroup-lv_root / ext4 defaults 1 1

UUID=9e1660ac-aa2f-4d2c-8ffc-256b6864f334 /boot ext4 defaults 1 2

/dev/mapper/VolGroup-lv_swap swap swap defaults 0 0

tmpfs /dev/shm tmpfs defaults 0 0

devpts /dev/pts devpts gid=5,mode=620 0 0

sysfs /sys sysfs defaults 0 0

proc /proc proc defaults 0 0

UUID=d2bd3d45-7ca6-4922-98d3-85ec074a0cad /mnt/sdc      ext4 defaults     0   2

相关详细说明:

http://9124573.blog.51cto.com/9114573/1703007

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值