linux一键挂载磁盘,Linux下如何挂载磁盘

新机装机有时没有挂载磁盘,需要手动操作一波。

使用root用户进入系统查看硬盘信息

[root@localhost ~]# fdisk -l //磁盘命令

[root@localhost ~]# 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 0x45a3cadb.

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

Command action

a toggle a bootable flag #设定可启动标记

b edit bsd disklabel

c toggle the dos compatibility flag

d delete a partition #删除一个分区

l list known partition types #各分区类型所对应的ID

m print this menu #菜单

n add a new partition #添加一个分区

o create a new empty DOS partition table

p print the partition table #显示该磁盘下的当前分区信息

q quit without saving changes #不保存退出

s create a new empty Sun disklabel

t change a partition's system id

u change display/entry units

v verify the partition table

w write table to disk and exit #保存退出

x extra functionality (experts only)

Command (m for help): p //打印分区信息,可以看到当前并没有分区

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

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

Device Boot Start End Blocks Id System

Command (m for help): n //创建一个新的分区

Command action

e extended//输入e为创建扩展分区

p primary partition (1-4) //输入p为创建逻辑分区

p

Partition number (1-4): 1//划分逻辑分区

First cylinder (1-2610, default 1): //我这里直接回车,是不想把该磁盘分成多个分区,把整个磁盘作为1个分区

Using default value 1

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

Using default value 2610

Command (m for help): p //再次查看可以看到该磁盘已经有1个分区了

Disk /dev/sdb: 21.5 GB, 21474836480 bytes

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

Device Boot Start End Blocks Id System

/dev/sdb1 2610 20964793+ 83 Linux

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: 21.5 GB, 21474836480 bytes

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

Device Boot Start End Blocks Id System

/dev/sdb1 2610 20964793+ 83 Linux

格式化分区

[root@localhost ~]# mkfs.ext3 /dev/sdc1

//将/dev/sdc1格式化为ext3类型,好像大部分的磁盘都是格式化为ext3类型,具体为什么没有深入研究,暂时不清楚,想了解的朋友可以自己查一下

mke2fs 1.41.12 (17-May-2010)

文件系统标签=

操作系统:Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

1310720 inodes, 5241198 blocks

262059 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=4294967296

160 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

正在写入inode表: 完成

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

//ps 这里需要耐心等待出现完成

This filesystem will be automatically checked every 31 mounts or

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

格式化完毕,此时就可以使用“mount”命令挂载分区了,然后使用这个磁盘空间了

挂载分区以及开机自动挂载

[root@localhost disk]# mkdir /data //创建被挂载的路径

[root@localhost disk]# mount /dev/sdb1 /data //进行挂载

[root@localhost ~]# df -h //此时只有sda1和sdb1两个磁盘挂载

Filesystem Size Used Avail Use% Mounted on

/dev/mapper/VolGroup-lv_root 18G 15G 1.5G 92% /

tmpfs 932M 76K 932M 1% /dev/shm

/dev/sda1 485M 40M 421M 9% /boot

/dev/sdb1 20G 1.2G 18G 7% /data

磁盘已经挂载上了

下面设置开机自动挂载

编辑/etc/fstab文件,再最后面添加

/dev/sdb1(磁盘分区) /data(挂载目录) ext3(文件格式)defaults 0 0

vi /etc/fstab

i //进入编辑模式

/dev/sdb1(磁盘分区) /data(挂载目录) ext3(文件格式)defaults 0 0 //挂载磁盘

//按‘Esc’退出编辑模式

:wq //保存

小白操作

[root@localhost ~]# fdisk -l //磁盘命令 查看需要挂载磁盘

[root@localhost ~]# fdisk /dev/sdb #进入磁盘

m //查看命令

p //打印分区信息

n //创建一个新的分区

p //输入p为创建逻辑分区

1//划分1个逻辑分区

w //保存分区

mkfs.ext3 /dev/sdb1 //格式化分区

vi /etc/fstab //编辑

/dev/sdb1(磁盘分区) /data(挂载目录) ext3(文件格式)defaults 0 0 //挂载

shutdown -r now //立刻重启(root用户使用)

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值