linux磁盘分区和挂载

linux磁盘分区和挂载

1.lsblk -f 查看系统分区和挂载情况

root@qsrobot:~# lsblk -f
NAME   FSTYPE  LABEL             UUID                                 MOUNTPOINT
sr0    iso9660 Ubuntu 16.04.6 LTS amd64
                                 2019-02-27-09-57-36-00               /media/rob
sda                                                                   
├─sda2                                                                
├─sda5 swap                      8d41e7be-46cf-4de6-afab-fb5242d10d4f [SWAP]
└─sda1 ext4                      95a7ce2a-6891-44f6-b0db-729319f8de8d /

2.通过虚拟机添加硬盘

root@qsrobot:~# lsblk -f
NAME   FSTYPE  LABEL             UUID                                 MOUNTPOINT
sdb                                                                   
sr0    iso9660 Ubuntu 16.04.6 LTS amd64
                                 2019-02-27-09-57-36-00               /media/rob
sda                                                                   
├─sda2                                                                
├─sda5 swap                      8d41e7be-46cf-4de6-afab-fb5242d10d4f [SWAP]
└─sda1 ext4                      95a7ce2a-6891-44f6-b0db-729319f8de8d /

3.新增分区

fdisk /dev/sdb开始对/sdb分区
?? m 显示命令列表
?? p 显示磁盘分区 同 fdisk –l
?? n 新增分区
?? d 删除分区
?? w 写入并退出

fdisk /dev/sdb

Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

Device does not contain a recognized partition table.
Created a new DOS disklabel with disk identifier 0x4dbeae7b.

命令(输入 m 获取帮助): 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


命令(输入 m 获取帮助): n
Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): p
分区号 (1-4, default 1): 1
First sector (2048-41943039, default 2048): 
Last sector, +sectors or +size{K,M,G,T,P} (2048-41943039, default 41943039): 

Created a new partition 1 of type ‘Linux‘ and of size 20 GiB.

命令(输入 m 获取帮助): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.

root@qsrobot:~# lsblk -f
NAME   FSTYPE  LABEL             UUID                                 MOUNTPOINT
sdb                                                                   
└─sdb1                                                                
sr0    iso9660 Ubuntu 16.04.6 LTS amd64
                                 2019-02-27-09-57-36-00               /media/rob
sda                                                                   
├─sda2                                                                
├─sda5 swap                      8d41e7be-46cf-4de6-afab-fb5242d10d4f [SWAP]
└─sda1 ext4                      95a7ce2a-6891-44f6-b0db-729319f8de8d /

说明: 开始分区后输入n新增分区,然后选择p设置分区类型为主分区。1指的是主分区的第1块分区。两次回车默认剩余空间。最后输入w写入分区并退出,若不保存退出输入q。

lsblk -f,就会看到新增的分区sdb1

4.格式化磁盘

mkfs -t ext4 /dev/sdb1格式化分区sdb1,分区类型是ext4
lsblk -f,就会看到格式化后的分区sdb1

root@qsrobot:~# mkfs -t ext4 /dev/sdb1
mke2fs 1.42.13 (17-May-2015)
Creating filesystem with 5242624 4k blocks and 1310720 inodes
Filesystem UUID: 8b5b2376-41d1-4f54-a4bc-237699d5246f
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Allocating group tables: 完成                            
正在写入inode表: 完成                            
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成   

root@qsrobot:~# lsblk -f
NAME   FSTYPE  LABEL             UUID                                 MOUNTPOINT
sdb                                                                   
└─sdb1 ext4                      8b5b2376-41d1-4f54-a4bc-237699d5246f 
sr0    iso9660 Ubuntu 16.04.6 LTS amd64
                                 2019-02-27-09-57-36-00               /media/rob
sda                                                                   
├─sda2                                                                
├─sda5 swap                      8d41e7be-46cf-4de6-afab-fb5242d10d4f [SWAP]
└─sda1 ext4                      95a7ce2a-6891-44f6-b0db-729319f8de8d /

linux磁盘分区和挂载
在文件中添加:
/dev/sdb1 /home /newdisk ext4 defaults 00将分区sdb1和目录 /home /newdisk挂载起来

特殊说明

/dev/sdb1:分区名称
ext3:分区的格式
defaults:挂载时所要设定的参数(只读,读写,启用quota等)
1:使用dump是否要记录,0是不要
2:开机时检查的顺序,boot系统文件为1,其他文件系统为2,如不要检查为0

mount -a 使挂载立即生效
umount /dev/sdb1或umount /home /newdisk卸载挂载
linux磁盘分区和挂载

linux磁盘分区和挂载

上一篇:mac常用快捷键


下一篇:linux目录结构