Ubuntu16.04挂载新硬盘并格式化硬盘

技术文档网 2021-05-08
环境

Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64)

操作

查看硬盘 查看方法一 查看/dev下面的设备文件 Linux 硬盘识别: 2.6 kernel以后,linux会将识别到的硬件设备,在/dev/下建立相应的设备文件. 如: sda 表示第1块SCSI硬盘,第二块是sdb,以此类推 hda 表示第1块IDE硬盘(即连接在第1个IDE接口的Master口上) scd0 表示第1个USB光驱. 当添加了新硬盘后,在/dev目录下会有相应的设备文件产生.cciss的硬盘是个例外,它的 设备文件在/dev/cciss/目录下.

$ ll -h /dev/sd*
brw-rw---- 1 root disk 8,  0 10月 11 09:20 /dev/sda
brw-rw---- 1 root disk 8,  1 10月 11 09:20 /dev/sda1
brw-rw---- 1 root disk 8,  2 10月 11 09:20 /dev/sda2
brw-rw---- 1 root disk 8,  5 10月 11 09:20 /dev/sda5
brw-rw---- 1 root disk 8, 16 10月 11 09:20 /dev/sdb
$ sudo fdisk -l
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 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 /dev/sda: 10 GiB, 10737418240 bytes, 20971520 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
Disklabel type: dos
Disk identifier: 0x6e488164

Device     Boot   Start      End  Sectors  Size Id Type
/dev/sda1  *       2048   999423   997376  487M 83 Linux
/dev/sda2       1001470 20969471 19968002  9.5G  5 Extended
/dev/sda5       1001472 20969471 19968000  9.5G 8e Linux LVM
新建分区
$ sudo fdisk /dev/sdb
Command (m for help): m

Help:

  DOS (MBR)
   a   toggle a bootable flag
   b   edit nested BSD disklabel
   c   toggle the dos compatibility flag

  Generic
   d   delete a partition
   F   list free unpartitioned space
   l   list known partition types
   n   add a new partition
   p   print the partition table
   t   change a partition type
   v   verify the partition table
   i   print information about a partition

  Misc
   m   print this menu
   u   change display/entry units
   x   extra functionality (experts only)

  Script
   I   load disk layout from sfdisk script file
   O   dump disk layout to sfdisk script file

  Save & Exit
   w   write table to disk and exit
   q   quit without saving changes

  Create a new label
   g   create a new empty GPT partition table
   G   create a new empty SGI (IRIX) partition table
   o   create a new empty DOS partition table
   s   create a new empty Sun partition table

# n创建分区
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
# p(primary主分区) e(extended拓展分区)
Partition number (1-4, default 1): 1
# 分区号
First sector (2048-83886079, default 2048):
# 默认
Last sector, +sectors or +size{K,M,G,T,P} (2048-83886079, default 83886079):
# 大小,可自定义,保持默认
Created a new partition 1 of type 'Linux' and of size 40 GiB.

Command (m for help): p
# 查看分区情况
Disk /dev/sdb: 40 GiB, 42949672960 bytes, 83886080 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
Disklabel type: dos
Disk identifier: 0xbb6c1792

Device     Boot Start      End  Sectors Size Id Type
/dev/sdb1        2048 83886079 83884032  40G 83 Linux

Command (m for help): w
# 保存
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
格式化
$ sudo mkfs.ext4 /dev/sdb1

ext4为分区格式

挂载

创建目录并挂载


sudo mkdir /data
sudo mount /dev/sdb1 /data
开机自动挂载

查看sdb1的UUID

$ sudo blkid
/dev/sda2: UUID="12b1f72c-dd6d-431b-b742-250d0e4f2a11" TYPE="ext4" PARTUUID="ad8da44f-a3e5-436b-9dde-6136aae35d75"
/dev/loop0: TYPE="squashfs"
/dev/loop1: TYPE="squashfs"
/dev/loop2: TYPE="squashfs"
/dev/loop3: TYPE="squashfs"
/dev/loop4: TYPE="squashfs"
/dev/sda1: UUID="2DD0-6D9D" TYPE="vfat" PARTLABEL="EFI System Partition" PARTUUID="58f2deed-29e5-4bb5-aeac-cafe8cab1822"
/dev/sdb1: UUID="4326e56a-983c-4b6c-804a-0568ffa1313e" TYPE="ext4" PARTUUID="d733d733-01"

添加UUID到/etc/fstab 添加UUID=4326e56a-983c-4b6c-804a-0568ffa1313e /data ext4 defaults,errors=remount-ro 0 1到/etc/fstab 其中UUID后面跟sdb1的UUID 重启

reboot

相关文章

  1. 搭建LNMP环境V1.2(ubuntu16-php7)

    更新 apt install python-software-properties software-properties-common #添加APP apt update #更新软件包列表 安装依

  2. 在ubuntu12.04上部署edx

    我的服务器配置 ubuntu 12.04 64位 4核CPU 16G内存 部署 方法一 export OPENEDX_RELEASE=named-release/cypress wget https:

  3. Ubuntu16.04挂载新硬盘并格式化硬盘

    环境 Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64) 操作 查看硬盘 查看方法一 查看/dev下面的设备文件 Linux 硬盘识别: 2.

随机推荐

  1. 搭建LNMP环境V1.2(ubuntu16-php7)

    更新 apt install python-software-properties software-properties-common #添加APP apt update #更新软件包列表 安装依

  2. 在ubuntu12.04上部署edx

    我的服务器配置 ubuntu 12.04 64位 4核CPU 16G内存 部署 方法一 export OPENEDX_RELEASE=named-release/cypress wget https:

  3. Ubuntu16.04挂载新硬盘并格式化硬盘

    环境 Ubuntu 16.04.3 LTS (GNU/Linux 4.4.0-87-generic x86_64) 操作 查看硬盘 查看方法一 查看/dev下面的设备文件 Linux 硬盘识别: 2.