首页 > 编程知识 正文

linux挂载新硬盘,mount命令挂载硬盘

时间:2023-05-05 07:26:48 阅读:13512 作者:305

[TOC]

#添加磁盘

添加新硬盘并重新启动服务器

添加完成后,可以重新启动机器。 如果机器已通电,即使进入系统也看不到添加的磁盘。 直到系统重新启动,重新加载后安装的磁盘才会显示

#根帐户登录系统

#查看硬盘

``````

fdisk -l //磁盘命令

``````

``````

磁盘/dev/sda : 21.5 GB,21474836480 bytes

255 heads、63 sectors/track和2610 cylinders

units=cylinders of 16065 * 512=8225280 bytes

sector size (逻辑/物理) : 512字节/512字节

I/osize (最小/最佳) : 512字节/512字节

磁盘标识符:0x 000 c4cb 5

dvicebootstartendblocksidsystem

/dev/sda1 * 1 64 512000 83 Linux

分区1 doesnotendoncylinderboundary。

/dev/sda 2642611204584968 elinuxlvm

磁盘/dev/sdb : 21.5 GB,21474836480 bytes

255 heads、63 sectors/track和2610 cylinders

units=cylinders of 16065 * 512=8225280 bytes

sector size (逻辑/物理) : 512字节/512字节

I/osize (最小/最佳) : 512字节/512字节

磁盘标识符:0x d 0f 5c 869

dvicebootstartendblocksidsystem

/dev/sdb1 1 2610 20964793 83 Linux

磁盘/dev/SDC : 21.5 GB,21474836480 bytes

255 heads、63 sectors/track和2610 cylinders

units=cylinders of 16065 * 512=8225280 bytes

sector size (逻辑/物理) : 512字节/512字节

I/osize (最小/最佳) : 512字节/512字节

磁盘标识符:0x 00000000

``````

可以看到,该计算机上加载了三个磁盘sda、sdb和sdc

其中,sda是初始磁盘,sdb是初始化使用的,sdc是刚加载但未格式化的新磁盘

#创建新的硬盘分区

``````

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

devicecontainsneitheravaliddospartitiontable,nor Sun,SGI or OSF磁盘标签

buildinganewdosdisklabelwithdiskidentifier0x 45 a3 cadb。

更改will remain in memory only,until you decide to write them。

After that,of course,thepreviouscontentwon ' tbe recoverable。

警告: invalid flag0x 0000 ofpartitiontable4willbecorrectedbyw (rite ) )。

warning : dos-compatiblemodeisdeprecated.it ' sstronglyrecommendedto

switchoffthemode(command'c ' ) and change显示单元到

安全(命令' u )。

command(mforhelp ) : m

命令动作

a toggle a bootable flag #设置可启动标志

b edit BSD磁盘标签

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/sdc: 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/sdc: 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/sdc1 1 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/sdc: 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/sdc1 1 2610 20964793+ 83 Linux

```

第三块磁盘/dev/sdc已经分区

# 格式化分区

```

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

//将/dev/sdc1格式化为ext3类型

```

```

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

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: 完成

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 ~]# 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% /disk/diskone

/dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final

[root@localhost /]# cd /disk/

[root@localhost disk]# ll

总用量 4

drwxr-xr-x. 4 root root 4096 7月 28 17:04 diskone

[root@localhost disk]# cd diskone/

[root@localhost diskone]# ll

总用量 20

drwx------. 2 root root 16384 7月 28 16:12 lost+found

drwxr-xr-x. 2 root root 4096 7月 28 17:09 software

[root@localhost diskone]# cd ../

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

[root@localhost disk]# ll

总用量 8

drwxr-xr-x. 4 root root 4096 7月 28 17:04 diskone

drwxr-xr-x. 2 root root 4096 8月 1 16:48 disktwo

[root@localhost disk]# mount /dev/sdc1 /disk/disktwo/ //进行挂载

[root@localhost disk]# df -h //再次查看,发现sdc1已经挂载在/disk/disktwo路径下

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% /disk/diskone

/dev/sr0 4.2G 4.2G 0 100% /media/CentOS_6.5_Final

/dev/sdc1 20G 173M 19G 1% /disk/disktwo

```

# 开机自动挂载

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

/dev/sdc1(磁盘分区) /disk/disktwo(挂载目录) ext3(文件格式)defaults 0 0

```

vi /etc/fstab /dev/sdc1(磁盘分区) /disk/disktwo(挂载目录) ext3(文件格式)defaults 0 0

```

> 来源 https://blog.csdn.net/weishujie000/article/details/76531924

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。