ubuntu 增加新硬盘

1 关机,安装新硬盘。然后上电开机。

2 检查是否检测到了新硬盘:

@Physics-Precision-WorkStation-T5400:~$ ls -l /dev/sd*
brw-rw---- 1 root disk 8,  0  5月 23 09:20 /dev/sda
brw-rw---- 1 root disk 8,  1  5月 23 09:20 /dev/sda1
brw-rw---- 1 root disk 8,  2  5月 23 09:20 /dev/sda2
brw-rw---- 1 root disk 8,  5  5月 23 09:20 /dev/sda5
brw-rw---- 1 root disk 8, 16  5月 23 09:20 /dev/sdb

看到了新增加的硬盘为 /dev/sdb

3查看新硬盘的参数:

@Physics-Precision-WorkStation-T5400:~$ sudo hdparm -I /dev/sdb

/dev/sdb:

ATA device, with non-removable media
    Model Number:       ST2000DM006-2DM164                      
    Serial Number:      W4Z4HPJC
    Firmware Revision:  CC26    
    Transport:          Serial, SATA 1.0a, SATA II Extensions, SATA Rev 2.5, SATA Rev 2.6, SATA Rev 3.0
Standards:
    Used: unknown (minor revision code 0x001f)
    Supported: 9 8 7 6 5
    Likely used: 9
Configuration:
    Logical        max    current
    cylinders    16383    16383
    heads        16    16
    sectors/track    63    63
.............
    IEEE OUI    : 000c50
    Unique ID    : 0a8ebeb68
Checksum: correct

4 进行分区,由于我要用这块2T的希捷硬盘做数据盘,因此我将整块硬盘分成一个主分区,不再细分成扩展分区,逻辑分区。现在的系统都是64位的,因此是可以支持2T的主分区。

@Physics-Precision-WorkStation-T5400:~$ 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 0x1ab94f32.
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)

The device presents a logical sector size that is smaller than
the physical sector size. Aligning to a physical sector (or optimal
I/O) size boundary is recommended, or performance may be impacted.

Command (m for help): m     #输入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
   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):     #打印出硬盘信息

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System

Command (m for help): n       #选择new一个分区
Partition type:
   p   primary (0 primary, 0 extended, 4 free)
   e   extended
Select (default p):       #回车,默认p 主分区
Using default response p
Partition number (1-4, default 1): 1     # 输入1,选择第一个主分区
First sector (2048-3907029167, default 2048):    # 回车,默认起始扇区
Using default value 2048
Last sector, +sectors or +size{K,M,G} (2048-3907029167, default 3907029167):   #回车,默认结束扇区
Using default value 3907029167

Command (m for help): p     #打印一下,查看,没有问题

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   83  Linux

Command (m for help): w  #输入w,写入并退出
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.

5 查看一下所有的硬盘:

@Physics-Precision-WorkStation-T5400:~$ sudo fdisk -l

Disk /dev/sda: 250.1 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders, total 488397168 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: 0x000b8bcb

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   454848511   227423232   83  Linux
/dev/sda2       454850558   488396799    16773121    5  Extended
/dev/sda5       454850560   488396799    16773120   82  Linux swap / Solaris

Disk /dev/sdb: 2000.4 GB, 2000398934016 bytes
81 heads, 63 sectors/track, 765633 cylinders, total 3907029168 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 4096 bytes
I/O size (minimum/optimal): 4096 bytes / 4096 bytes
Disk identifier: 0x1ab94f32

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048  3907029167  1953513560   83  Linux

6 格式化硬盘,现在的Linux的文件格式都是ext4的格式了,记得几年前还有用ext3的格式。

Physics-Precision-WorkStation-T5400:~$ sudo mkfs -t ext4 /dev/sdb1
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
122101760 inodes, 488378390 blocks
24418919 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
14905 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, 71663616, 78675968,
    102400000, 214990848

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done


7 给新硬盘写个标签。

Physics-Precision-WorkStation-T5400:~$ sudo e2label /dev/sdb1 /ext4-2T-disk-1

8 给一个挂载点:

mkdir /home/yourname/dir

9 编辑 /etc/fstab文件:

sudo gedit /etc/fstab

在文件的最后一行加入:

LABEL=/ext4-2T-disk-1    /home/yourname/dir    ext4    defaults    0    2


10 挂载

Physics-Precision-WorkStation-T5400:~$ sudo mount -a

11 这时候,你会发现挂载的盘,普通用户无法写入,需要授权

Physics-Precision-WorkStation-T5400:~$ sudo chown -R $(whoami) /home/yourname/dir

 

 

 

另外的参考:

查看硬盘分区的UUID

        命令:sudo blkid

       

         从上图可以清楚的看到,该硬盘已经格式化为ext4,标签为code

     5.在已有的user目录下新建一个挂在点

         命令:mkdir xxx

         例如:我自己在已有的目录下创建一个code目录挂载新的硬盘分区,如:mkdir /home/jason/code    

     6.编辑系统挂载配置文件/etc/fstab

        命令:sudo  vim etc/fstab

 按照已有的格式,将新加的硬盘分区信息添加到结尾;

注:格式为 设备名称 挂载点 分区类型 挂载选项 dump选项 fsck选项
dump选项–这一项为0,就表示从不备份。如果上次用dump备份,将显示备份至今的天数。
fsck选项 –启动时fsck检查的顺序。为0就表示不检查,(/)分区永远都是1,其它的分区只能从2开始,当数字相同就同时检查(但不能有两1)

7.修改对应的用户和权限

    命令: sudo chown -R jason:jason /home/jason/code

                 sudo chmod -R 4755 /home/jason/code

注:chmod使用的数字的意思: 读(r=4),写(w=2),执行(x=1)可读可写为4+2=6 依次内存 755表示的是文件所有者权限7(三者权限之和),与所有者同组用户5(读+执行),其他用户同前一个5,这里的4的意思是(其他)用户执行拥有所有者相同的文件权限(对于其他要使用的文件)

    8.重启电脑

        命令:sudo reboot
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值