Linux 增加新硬盘

264 阅读6分钟

df -h

查看当前挂载硬盘信息

Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           780M   81M  700M  11% /run
/dev/sda1        79G   30G   47G  39% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup

fdisk -l

查看所有硬盘信息(已挂载 + 未挂载)

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: 0x0e81f020

Device     Boot Start       End   Sectors Size Id Type
/dev/sda1  *     2048 167772126 167770079  80G 83 Linux


Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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

lsblk

检查哪块磁盘为加载和分区

NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda      8:0    0   80G  0 disk
`-sda1   8:1    0   80G  0 part /
sdb      8:16   0  100G  0 disk

硬盘分区(fdisk < 2TB,parted >= 2TB)

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 创建分区
  • p 主分区
  • 分区编号 (主分区 1 ~ 4) 1 默认
  • 起始扇区 留空 默认2048
  • 结束扇区 留空 默认全部空间
Command (m for help): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
Partition number (1-4, default 1): 1
First sector (2048-209715199, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-209715199, default 209715199):

Created a new partition 1 of type 'Linux' and of size 100 GiB.

w 保存设置并退出

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

df -T 查看硬盘 与分区文件系统

Filesystem     Type     1K-blocks     Used Available Use% Mounted on
udev           devtmpfs   3980620        0   3980620   0% /dev
tmpfs          tmpfs       798496    82348    716148  11% /run
/dev/sda1      ext4      82566532 30707648  48473480  39% /
tmpfs          tmpfs      3992464        0   3992464   0% /dev/shm
tmpfs          tmpfs         5120        0      5120   0% /run/lock
tmpfs          tmpfs      3992464        0   3992464   0% /sys/fs/cgroup

fdisk -l 查看所有硬盘与分区

Disk /dev/sda: 80 GiB, 85899345920 bytes, 167772160 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: 0x0e81f020

Device     Boot Start       End   Sectors Size Id Type
/dev/sda1  *     2048 167772126 167770079  80G 83 Linux


Disk /dev/sdb: 100 GiB, 107374182400 bytes, 209715200 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: 0x963a4139

Device     Boot Start       End   Sectors  Size Id Type
/dev/sdb1        2048 209715199 209713152  100G 83 Linux

mkfs.ext4 /dev/sdb1sdb1分区创建文件系统

mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks:  3149824/26214144
mke2fs 1.43.4 (31-Jan-2017)
Discarding device blocks: done
Creating filesystem with 26214144 4k blocks and 6553600 inodes
Filesystem UUID: c646107e-96b8-40f1-96ef-4cc7dd651de1
Superblock backups stored on blocks:
        32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
        4096000, 7962624, 11239424, 20480000, 23887872

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

创建临时挂载文件夹 挂载分区 (重启后消失)

/mnt 目录用于挂载储存设备 mkdir /mnt/sdbext mount /dev/sdb1 /mnt/sdbext

df -h 查看硬盘信息

Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           780M   81M  700M  11% /run
/dev/sda1        79G   30G   47G  39% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sdb1        98G   61M   93G   1% /mnt/sdbext

nano /etc/fstab 永久挂载分区

  1. 要挂载的设备:

    • 设备文件
    • LABEL=
    • UUID=
  2. 挂载点

    • swap没有挂载点,挂载点为swap
  3. 文件系统类型

    • ext2、ext3、ext4、xfs、nfs、smb、iso9660等
  4. 挂载选项 多个选项间使用逗号分隔

    • async, sync, _netdev
    • defaults (rw, suid, dev, exec, auto, nouser, async, and relatime.)
  5. 转储频率

    • 0:从不备份
    • 1:每日备份
    • 2:每隔一天备份
  6. 自检次序

    • 0: 不自检
    • 1:首先自检,通常只能被 / 使用
    • 2:等数字为1的自检完成后,再进行自检
    • ... 4

    注意:配置完该文件不会立即生效,可以重启操作系统或使用mount -a来使该文件立即生效。

挂载设备 挂载目录 文件格式 挂载选项 转存频率 检查顺序

/dev/sdb1 /mnt/sdbext ext4 default 0 0

blkid 获得分区UUID

/dev/sda1: UUID="2631b9a0-14b1-449d-bd6b-b736a6bb34b5" TYPE="ext4" PARTUUID="0e81f020-01"
/dev/sdb1: UUID="c646107e-96b8-40f1-96ef-4cc7dd651de1" TYPE="ext4" PARTUUID="963a4139-01"

mount -a

如果没有其他信息出现,表示你插入的正确,否则错误。 如果错误且没有检查,开机后将进入紧急模式,无法开机。 重启后df -h查看是否正常

Filesystem      Size  Used Avail Use% Mounted on
udev            3.8G     0  3.8G   0% /dev
tmpfs           780M   81M  700M  11% /run
/dev/sda1        79G   30G   47G  39% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
tmpfs           5.0M     0  5.0M   0% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/sdb1        98G   61M   93G   1% /mnt/sdbext

访问 cd /mnt/sdbext/...

引用资料

blog.csdn.net/woailyoo000…

blog.51cto.com/zkxfoo/1758…