linux命令大全挂盘 卸盘,Linux服务器挂载/卸载数据盘

最近用腾讯云学生价买了一个数据盘,把数据迁移过去,因此记录一下使用过程。

查看挂载状况:

# fdisk -l

Disk /dev/vda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x000e8237

Device Boot Start End Blocks Id System

/dev/vda1 * 2048 41943039 20970496 83 Linux

Disk /dev/vdb: 75.2 GB, 75161927680 bytes

16 heads, 63 sectors/track, 145635 cylinders, total 146800640 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x00000000

Disk /dev/vdb doesn't contain a valid partition table

可以看到 /dev/vdb 没有建立分区表也没有格式化,所以先建立分区表。

建立分区表

执行以下命令,对数据盘进行分区。

# fdisk /dev/vdb

按照界面的提示,依次输入 “n”(新建分区)、“p”(新建扩展分区)、“1”(使用第 1 个主分区),两次回车 (使用默认配置),输入 “w”(保存分区表),开始分区。这里是以创建 1 个分区为例,开发者也可以根据自己的需求创建多个分区。

# 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 0xc8e701e1.

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 // 这里

Partition type:

p primary (0 primary, 0 extended, 4 free)

e extended

Select (default p): p // 这里

Partition number (1-4, default 1): 1 // 这里

First sector (2048-146800639, default 2048): // 这里

Using default value 2048

Last sector, +sectors or +size{K,M,G} (2048-146800639, default 146800639): // 这里

Using default value 146800639

Command (m for help): w // 这里

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

查看新分区

使用 “fdisk -l” 命令,即可查看到,新的分区 vdb1 已经创建完成。

# fdisk -l

Disk /dev/vda: 21.5 GB, 21474836480 bytes

255 heads, 63 sectors/track, 2610 cylinders, total 41943040 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x000e8237

Device Boot Start End Blocks Id System

/dev/vda1 * 2048 41943039 20970496 83 Linux

Disk /dev/vdb: 75.2 GB, 75161927680 bytes

9 heads, 56 sectors/track, 291271 cylinders, total 146800640 sectors

Units = sectors of 1 * 512 = 512 bytes

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

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

Disk identifier: 0xc8e701e1

Device Boot Start End Blocks Id System

/dev/vdb1 2048 146800639 73399296 83 Linux

格式化新分区

现在还没有格式化,我们格式化它,然后挂载。

在进行分区格式化时,开发者可以自行决定文件系统的格式,如 ext2、ext3 等。本例以 “ext3” 为例:

使用下面的命令对新分区进行格式化。

# mkfs.ext4 /dev/vdb1

mke2fs 1.42.9 (4-Feb-2014)

Filesystem label=

OS type: Linux

Block size=4096 (log=2)

Fragment size=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

4587520 inodes, 18349824 blocks

917491 blocks (5.00%) reserved for the super user

First data block=0

Maximum filesystem blocks=4294967296

560 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

Allocating group tables: done

Writing inode tables: done

Creating journal (32768 blocks): done

Writing superblocks and filesystem accounting information: done

挂载新分区

使用以下命令创建 mydata 目录:

# mkdir /root/data

再通过以下命令手动挂载新分区:

# mount /dev/vdb1 /root/data

最后用以下命令查看

# df -h

出现如图信息则说明挂载成功,即可以查看到数据盘了。

# df -h

Filesystem Size Used Avail Use% Mounted on

udev 487M 4.0K 487M 1% /dev

tmpfs 100M 352K 100M 1% /run

/dev/vda1 20G 4.6G 15G 25% /

none 4.0K 0 4.0K 0% /sys/fs/cgroup

none 5.0M 0 5.0M 0% /run/lock

none 497M 24K 497M 1% /run/shm

none 100M 0 100M 0% /run/user

/dev/vdb1 69G 52M 66G 1% /root/data

添加分区信息

如果希望云服务器在重启或开机时能自动挂载数据盘,必须将分区信息添加到 / etc/fstab 中。如果没有添加,则云服务器重启或开机后,都不能自动挂载数据盘。

注:请确认分区路径是否为 “/dev/vdb1”, 若路径错误,将会造成云主机重启失败。

使用以下命令添加分区信息:

echo '/dev/vdb1 /root/data ext4 defaults 0 0' >> /etc/fstab

使用以下命令查看

cat /etc/fstab

出现下面信息则说明添加分区信息成功。

# cat /etc/fstab

/dev/vda1 / ext3 noatime,acl,user_xattr 1 1

proc /proc proc defaults 0 0

sysfs /sys sysfs noauto 0 0

debugfs /sys/kernel/debug debugfs noauto 0 0

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

/dev/vdb1 /root/data ext4 defaults 0 0

卸载

使用 umount 命令即可。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值