如何在卸载磁盘分区时列出它们?以及如何通过终端挂载它们?
答案1
列出未挂载的分区
为了解决未挂载分区部分的列表问题,有几种方法 - lsblk
,,,,。fdisk
parted
blkid
$ 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
这是我为列出未安装的卷而开发的:
lsblk --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}'
答案3
sudo blkid -o list
将列出所有已安装和未安装的分区。此外,您还可以使用mount
和df
查看所有安装点。
mount -t type device destination_dir
可用于挂载您的设备/分区。
答案4
我只是根据人们在这里说的答案制作了一个脚本,在这种情况下,我首先列出所有未挂载的分区,然后使用 udisksctl 挂载它们。
这最终脚本将如下所示:
lsblk --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}' | grep -E "(/dev/sd.)[[:digit:]]" | xargs -I{} -n1 udisksctl mount -b {}
这里,
lsblk --noheadings --raw | awk '{print substr($0,0,4)}' | uniq -c | grep 1 | awk '{print "/dev/"$2}'
将产生sda sda1 ... sdb sdb1 ... sdc ....但我们不想星展银行我们希望sda1,sda2 ...所以我们需要删除sda、sdb、sdc他们自己,
所以我们添加
grep -E "(/dev/sd.)[[:digit:]]"
部分来执行此操作。
现在它生产sda1,sda2,...,sdb1,sdb2,... 现在还不错 :)
现在我们可以使用 xargs 逐个挂载它们,如下所示:
xargs -I{} -n1 udisksctl mount -b {}