linux挂载硬盘 ubuntu,Ubuntu下挂载新硬盘(linux下硬盘的自动挂载)

今天折腾实验室一台台式机来着,想给它增加一块硬盘,但是将硬盘插上后没有反应,刚开始以为是硬盘坏了,也就没太在意,后来在上网时发现,有些主机增加硬盘后,还需要在BIOS里开启对应的SATA口才行,看到这儿,我恍然大悟,原来是还需要配置BIOS 啊。随后我重启电脑,按F2进入BIOS,在开启硬盘的那一项中,将对应的硬盘选项设置为 ON ,再次开机,果然出现了新硬盘。

解决硬盘的安装问题后,我们登录时ubuntu,这时候还不能够使用新的硬盘,因为还没有将这块新硬盘挂载到系统中去,在则这里分享以下在 linux  下挂载新硬盘的方法。

1、首先使用  sudo fdisk -l 命令查看硬盘信息:

lixinxing@ubuntu:~$ sudo fdisk -l

[sudo] password for lixinxing:

Disk /dev/sda: 80.0 GB, 80000000000 bytes

255 heads, 63 sectors/track, 9726 cylinders, total 156250000 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x000d06b8

设备 启动      起点          终点     块数   Id  系统

/dev/sda1   *        2048      499711      248832   83  Linux

/dev/sda2          501758   156248063    77873153    5  扩展

/dev/sda5          501760   156248063    77873152   8e  Linux LVM

Disk /dev/sdb: 80.0 GB, 80000000000 bytes

255 heads, 63 sectors/track, 9726 cylinders, total 156250000 sectors

Units = 扇区 of 1 * 512 = 512 bytes

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

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

Disk identifier: 0x19ddb517

设备 启动      起点          终点     块数   Id  系统

/dev/sdb1   *          63    20482874    10241406    7  HPFS/NTFS/exFAT

/dev/sdb2        20482875   156199994    67858560    f  W95 扩展 (LBA)

/dev/sdb5        20482938    61448624    20482843+   b  W95 FAT32

/dev/sdb6        61448688   102414374    20482843+   7  HPFS/NTFS/exFAT

/dev/sdb7       102414438   148119299    22852431    b  W95 FAT32

/dev/sdb8       148119363   156199994     4040316   1b  隐藏的 W95 FAT32

Disk /dev/mapper/ubuntu--vg-root: 79.2 GB, 79196848128 bytes

255 heads, 63 sectors/track, 9628 cylinders, total 154681344 sectors

Units = 扇区 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/mapper/ubuntu--vg-root doesn't contain a valid partition table

Disk /dev/mapper/ubuntu--vg-swap_1: 499 MB, 499122176 bytes

255 heads, 63 sectors/track, 60 cylinders, total 974848 sectors

Units = 扇区 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/mapper/ubuntu--vg-swap_1 doesn't contain a valid partition table

可以看到,系统中安装了两块硬盘,容量大小在这里显示:

Disk /dev/sda: 80.0 GB, 80000000000 bytes

Disk /dev/sdb: 80.0 GB, 80000000000 bytes

即两块硬盘都是用 80G的。

2、如果硬盘有多余的数据,可以在分区前将其格式化,命令 sudo mkfs.ext3 /dev/sdb

lixinxing@ubuntu:~$ sudo mkfs.ext3 /dev/sdb

mke2fs 1.42.9 (4-Feb-2014)

/dev/sdb is entire device, not just one partition!

无论如何也要继续? (y,n) y

文件系统标签=

OS type: Linux

块大小=4096 (log=2)

分块大小=4096 (log=2)

Stride=0 blocks, Stripe width=0 blocks

4890624 inodes, 19531250 blocks

976562 blocks (5.00%) reserved for the super user

第一个数据块=0

Maximum filesystem blocks=4294967296

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

正在写入inode表: 完成

Creating journal (32768 blocks): 完成

Writing superblocks and filesystem accounting information: 完成

3、创建新硬盘分区。

使用者fdisk 命令可以创建新的硬盘分区。

lixinxing@ubuntu:~$ sudo fdisk /dev/sdb

[sudo] password for lixinxing:

命令(输入 m 获取帮助):

我们接着输入 n,创建新的分区

然后输入  p,表示是逻辑分区

接着选择 1

接下来可以选择分区大小,分区的起始块我们选择默认,要分多大的空间,我们可以算出来,从而可以知道结束块是多少。

分区结束后者输入  w 保存.

lixinxing@ubuntu:~$ sudo 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 0x91f978e6.

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)

命令(输入 m 获取帮助): n

Partition type:

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

e   extended

Select (default p): p

分区号 (1-4,默认为 1): 1

起始 sector (2048-156249999,默认为 2048):

将使用默认值 2048

Last sector, +扇区 or +size{K,M,G} (2048-156249999,默认为 156249999):

将使用默认值 156249999

命令(输入 m 获取帮助): w

The partition table has been altered!

Calling ioctl() to re-read partition table.

Syncing disks.

4.格式化分区:

sudo mkfs.ext3 /dev/sdb1

5.挂载分区:

mount /dev/sdb1 /home

6.配置开机自动挂载

因为mount挂载在重启服务器后会失效,所以需要将分区信息写到/etc/fstab文件中让它永久挂载:

vi /etc/fstab

在尾部加上

/dev/sdb1               /home                   ext3    defaults        0 0

表示把新的硬盘分区挂载到 /home 这个目录

在修改/etc/fstab文件后,运行mount -a命令验证一下配置是否正确,否则错误配置fstab文件导致系统无法正常启动。如果系统无法正常启动,则输入root密码进入修复模式,关键的一步是重新mount /(mount -n -o remount,rw /)。如果没有此步操作,则文件系统处于只读状态,导致不能修改配置文件并保存,修复存在的问题。

7.重启系统

8.再次查看,使用 df -h命令查看分区,  可以看到新的磁盘已经挂载

03cb8e9fcea19d5690438d06e2ec48ec.pngUbuntu下挂载新硬盘(linux下硬盘的自动挂载)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值