如何列出硬盘的未挂载分区并挂载它们?


Answers:


43

列出未挂载的分区

为了解决未挂载分区的部分上市,有几种方法- ,lsblkfdisk,。partedblkid

$ lsblk
NAME                             MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sda                                8:0    0 111.8G  0 disk 
└─sda1                             8:1    0 111.8G  0 part /
sdb                                8:16   0 232.9G  0 disk 
├─sdb1                             8:17   0   1.5G  0 part 
├─sdb2                             8:18   0 138.6G  0 part /media/WINDOWS
├─sdb3                             8:19   0   8.1G  0 part 
├─sdb4                             8:20   0     1K  0 part 
├─sdb5                             8:21   0  68.5G  0 part 
└─sdb6                             8:22   0   5.8G  0 part 
loop0                              7:0    0   100G  0 loop 
└─docker-8:1-1589297-pool (dm-0) 252:0    0   100G  0 dm   
loop1                              7:1    0     2G  0 loop 
└─docker-8:1-1589297-pool (dm-0) 252:0    0   100G  0 dm   
$ sudo fdisk -l
[sudo] password for xieerqi: 

Disk /dev/sda: 120.0 GB, 120034123776 bytes
255 heads, 63 sectors/track, 14593 cylinders, total 234441648 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: 0x000b5321

   Device Boot      Start         End      Blocks   Id  System
/dev/sda1   *        2048   234440703   117219328   83  Linux

Disk /dev/sdb: 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: 0x96360d50

   Device Boot      Start         End      Blocks   Id  System
/dev/sdb1   *        2048     3074047     1536000   27  Hidden NTFS WinRE
/dev/sdb2         3074048   293617502   145271727+   7  HPFS/NTFS/exFAT
/dev/sdb3       471437312   488396799     8479744   17  Hidden HPFS/NTFS
/dev/sdb4       293617662   471437311    88909825    5  Extended
/dev/sdb5       315830272   459382783    71776256   83  Linux
/dev/sdb6       459384832   471437311     6026240   82  Linux swap / Solaris

Partition table entries are not in disk order

Disk /dev/mapper/docker-8:1-1589297-pool: 107.4 GB, 107374182400 bytes
255 heads, 63 sectors/track, 13054 cylinders, total 209715200 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 65536 bytes / 65536 bytes
Disk identifier: 0x00000000

Disk /dev/mapper/docker-8:1-1589297-pool doesn't contain a valid partition table
$ sudo parted -l                                                               
[sudo] password for xieerqi: 
Model: ATA Radeon R7 (scsi)
Disk /dev/sda: 120GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End    Size   Type     File system  Flags
 1      1049kB  120GB  120GB  primary  ext4         boot


Model: ATA TOSHIBA MK2555GS (scsi)
Disk /dev/sdb: 250GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type      File system     Flags
 1      1049kB  1574MB  1573MB  primary   ntfs            boot, diag
 2      1574MB  150GB   149GB   primary   ntfs
 4      150GB   241GB   91.0GB  extended
 5      162GB   235GB   73.5GB  logical   ext4
 6      235GB   241GB   6171MB  logical   linux-swap(v1)
 3      241GB   250GB   8683MB  primary   ntfs            hidden


Model: Linux device-mapper (thin-pool) (dm)
Disk /dev/mapper/docker-8:1-1589297-pool: 107GB
Sector size (logical/physical): 512B/512B
Partition Table: loop

Number  Start  End    Size   File system  Flags
 1      0.00B  107GB  107GB  ext4


$ sudo blkid
[sudo] password for xieerqi: 
/dev/sda1: UUID="86df21bf-d95f-435c-9292-273bdbcba056" TYPE="ext4" 
/dev/sdb1: LABEL="System" UUID="F4F688B2F68876A0" TYPE="ntfs" 
/dev/sdb2: LABEL="TI105866W0A" UUID="4EBAAE53BAAE36FD" TYPE="ntfs" 
/dev/sdb3: LABEL="HDDRECOVERY" UUID="BC4ED40D4ED3BDF8" TYPE="ntfs" 
/dev/sdb5: UUID="0ca7543a-5463-4a07-8bbe-233a7b0bd625" TYPE="ext4" 
/dev/sdb6: UUID="3a6e2270-19a2-49d7-aab3-5efb92d3b3d0" TYPE="swap" 
/dev/loop0: UUID="a3693b88-7899-4628-848d-d9012205cf56" TYPE="ext4" 
/dev/mapper/docker-8:1-1589297-pool: UUID="a3693b88-7899-4628-848d-d9012205cf56" TYPE="ext4" 
$ 

可以使用一点AWK魔术来解析输出lsblk以列出所有未安装的分区:

$ lsblk  --noheadings --raw | awk '$1~/s.*[[:digit:]]/ && $7==""'              
sdb1 8:17 0 1.5G 0 part 
sdb3 8:19 0 8.1G 0 part 
sdb4 8:20 0 1K 0 part 
sdb5 8:21 0 68.5G 0 part 
sdb6 8:22 0 5.8G 0 part

或者:

$ lsblk --noheadings --raw -o NAME,MOUNTPOINT | awk '$1~/[[:digit:]]/ && $2 == ""'                                       
sdb1 
sdb2 
sdb3 
sdb4 
sdb5 

确切的是,我们正在列出所有

第一行以字母开头s(因为通常是驱动器的命名方式)并以数字结尾(代表分区)的行。在之前的输出中,您可以看到我还有其他文件系统,例如docker,因此在上面的命令中,我们删除了所有不必要的东西。

安装分区

我发现这mount很挑剔:它需要知道确切的文件系统,需要以root身份运行,等等。这udisksctl mount -b /dev/sXY是一个更好的命令,可以以常规用户身份运行,并自动安装到/media/$USER/文件夹中。例如,

$ udisksctl mount -b /dev/sdb5 
Mounted /dev/sdb5 at /media/xieerqi/0ca7543a-5463-4a07-8bbe-233a7b0bd625.

2

sudo blkid -o list

将列出所有已安装和已卸载的分区。另外,您可以使用mountdf查看所有安装点。

mount -t type device destination_dir

可用于挂载设备/分区。


这仅列出已安装的分区。不包括未安装的。
Suncat2000

2

要回答您的第一个问题,请运行:

sudo parted -l

如果它们已正常安装,请运行:

mount -a

从安装手册页:命令

mount -a [-t类型] [-O optlist]

(通常在引导脚本中给出)导致fstab中提到的所有文件系统(具有正确的类型和/或具有或不具有正确的选项)均按指示进行安装,但其行包含noauto关键字的文件系统除外。

如果未正常安装它们,则必须提供安装选项。


并且需要明确的mountsudo mount <options>,如果以root身份以外的身份运行命令,则命令也必须也是如此,或者您得到:mount:只有root才能做到这一点
JimLohse

我太新了,无法直接评论@Serg的答案,但这非常详尽,至少我可以投票赞成!一定要看看他的回答,特别是udisksctl mount -b /dev/sXY可以由普通用户运行的命令,非常酷。
JimLohse

2

这是我为列出未安装的卷而开发的:

lsblk  --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}'

1
您能否通过示例使用它来扩展答案?
WinEunuuchs2Unix

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.