![为什么 mount 将目录挂载到 /dev/loop0 而不是设备?结果无法将所有文件写入该目录(因为它太小)](https://linux22.com/image/12739/%E4%B8%BA%E4%BB%80%E4%B9%88%20mount%20%E5%B0%86%E7%9B%AE%E5%BD%95%E6%8C%82%E8%BD%BD%E5%88%B0%20%2Fdev%2Floop0%20%E8%80%8C%E4%B8%8D%E6%98%AF%E8%AE%BE%E5%A4%87%EF%BC%9F%E7%BB%93%E6%9E%9C%E6%97%A0%E6%B3%95%E5%B0%86%E6%89%80%E6%9C%89%E6%96%87%E4%BB%B6%E5%86%99%E5%85%A5%E8%AF%A5%E7%9B%AE%E5%BD%95%EF%BC%88%E5%9B%A0%E4%B8%BA%E5%AE%83%E5%A4%AA%E5%B0%8F%EF%BC%89.png)
我想将大约 38 MB 的文件写入 100 MB 大的分区。但是,当我将该分区挂载到目录时,它会挂载到/dev/loop0
而不是/dev/sdc1
(在我的示例中)。
这似乎是一个问题,因为该mv
命令现在不允许我将所有 38 MB 的文件写入设备。以下是我所做的一切(以下是我的用例,但不确定这是否相关树莓派3):
[slife pi]# fdisk /dev/sdc
Welcome to fdisk (util-linux 2.34).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
Command (m for help): o
Created a new DOS disklabel with disk identifier 0x2ec21fb4.
Command (m for help): p
Disk /dev/sdc: 29.83 GiB, 32010928128 bytes, 62521344 sectors
Disk model: Card Reader
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: 0x2ec21fb4
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-62521343, default 2048):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (2048-62521343, default 62521343): +100M
Created a new partition 1 of type 'Linux' and of size 100 MiB.
Command (m for help): t
Selected partition 1
Hex code (type L to list all codes): c
Changed type of partition 'Linux' to 'W95 FAT32 (LBA)'.
Command (m for help): n
Partition type
p primary (1 primary, 0 extended, 3 free)
e extended (container for logical partitions)
Select (default p): p
Partition number (2-4, default 2): 2
First sector (206848-62521343, default 206848):
Last sector, +/-sectors or +/-size{K,M,G,T,P} (206848-62521343, default 62521343):
Created a new partition 2 of type 'Linux' and of size 29.7 GiB.
Partition #2 contains a ext4 signature.
Do you want to remove the signature? [Y]es/[N]o: y
The signature will be removed by a write command.
Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
[slife pi]# mkfs.vfat /dev/sdc1
mkfs.fat 4.1 (2017-01-24)
[slife pi]# ls
ArchLinuxARM-rpi-latest.tar.gz ArchLinuxARM-rpi-latest.tar.gz.1 boot root unzipped
[slife pi]# mount /dev/sdc1 boot
[slife pi]# lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
loop0 7:0 0 10M 0 loop /mnt/pi/boot
sda 8:0 0 1.8T 0 disk
├─sda1 8:1 0 260M 0 part
├─sda2 8:2 0 16M 0 part
├─sda3 8:3 0 1.3T 0 part
├─sda4 8:4 0 873M 0 part
├─sda5 8:5 0 16G 0 part [SWAP]
├─sda6 8:6 0 512M 0 part /boot/EFI
└─sda7 8:7 0 570.2G 0 part /
sdc 8:32 1 29.8G 0 disk
├─sdc1 8:33 1 100M 0 part
└─sdc2 8:34 1 29.7G 0 part
sr0 11:0 1 1024M 0 rom
[slife pi]# mkfs.ext4 /dev/sdc2
mke2fs 1.45.4 (23-Sep-2019)
Creating filesystem with 7789312 4k blocks and 1949696 inodes
Filesystem UUID: e4033af0-dd50-4286-abc4-ea6982b21439
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
[slife pi]# mount /dev/sdc2 root
[slife pi]# bsdtar -xpf ArchLinuxARM-rpi-2-latest.tar.gz -C root
[slife pi]# sync
[slife pi]# mv root/boot/* boot
mv: error writing 'boot/kernel7.img': No space left on device
mv: cannot create directory 'boot/overlays': No space left on device
mv: error writing 'boot/start4cd.elf': No space left on device
mv: error writing 'boot/start4db.elf': No space left on device
mv: error writing 'boot/start4.elf': No space left on device
mv: error writing 'boot/start4x.elf': No space left on device
mv: error writing 'boot/start_cd.elf': No space left on device
mv: error writing 'boot/start_db.elf': No space left on device
mv: error writing 'boot/start.elf': No space left on device
mv: error writing 'boot/start_x.elf': No space left on device
正如您所看到的,在mount /dev/sdc1 boot
命令之后,它安装了/dev/loop0
而不是/dev/sdc1
.结果,当我这样做时mv root/boot/* boot
,它返回No space left on device
了一堆文件。
那么我怎样才能正确地将这些文件移动到呢/dev/sdc1
?
这是一个仅显示目录大小的du
调用root/boot
(我将内容本地解压缩到名为“unzipped”的目录仅供参考):
[slife unzipped]# du boot
940 boot/overlays
38776 boot
[slife unzipped]# du -h boot
940K boot/overlays
38M boot
编辑(以澄清完整路径):我正在尝试安装:
/dev/sdc1
到/mnt/pi/boot
和
/dev/sdc2
到/mnt/pi/root
(这个是成功的)。
编辑2:输出df -i /dev/sdc1
Filesystem Inodes IUsed IFree IUse% Mounted on
dev 2024406 546 2023860 1% /dev
编辑 3:@telcoM 要求的命令的输出:
slife: ~ » losetup -l -a
NAME SIZELIMIT OFFSET AUTOCLEAR RO BACK-FILE DIO LOG-SEC
/dev/loop0 0 0 1 0 /dev/sdc1 0 512
slife: ~ » ls -l /dev/sdc1
-rw-r--r-- 1 root root 10485760 Dec 30 12:49 /dev/sdc1
答案1
您的/dev/sdc1
设备节点已替换为 10M 大小的常规文件,现在它充当 10M 分区映像文件。这可能是由于之前某些命令出现错误而导致的。
首先,卸载文件:
umount /mnt/pi/boot
losetup -l -a
## if the output of the losetup command above is not empty, run this command:
losetup -r /dev/loop0
然后,将图像文件移到一边:
mv /dev/sdc1 /tmp/sdc1-image-10M.ima
(您可能对此文件没有任何用处,因此您可以将其删除,但安全总比抱歉好……)
将其替换为实际的块设备节点(应有的样子),并设置权限。这是mknod
在现代系统中使用该命令的极少数原因之一:
mknod /dev/sdc1 b 8 33
chown root:disk /dev/sdc1
chmod 660 /dev/sdc1
mknod 命令的参数为:
- 要创建的设备的名称
- 设备类型:
b
= 块设备,c
= 字符设备。 - 主要设备编号:来自您的
lsblk
输出sdc1
- 次设备号:也来自您的
lsblk
输出sdc1
现在,访问/dev/sdc1
应该再次为您提供实际的分区,而不是意外的图像文件。由于原始mkfs.vfat
命令影响的是映像文件而不是实际分区,因此您应该再次执行此操作:
mkfs.vfat /dev/sdc1
mount /dev/sdc1 /mnt/pi/boot
然后你应该能够继续:
mv /mnt/pi/root/boot/* /mnt/pi/boot
(为了清楚起见,我使用完整路径;如果您愿意,当然可以使用相对于当前目录的较短路径。)
答案2
就像 @telecoM 所说,/dev/sdc1
是一个 10MB 大的常规文件,而不是按设备节点。由于设备节点是自动生成的udev
,因此您可以简单地:
- 消除
/dev/sdc1
:sudo rm /dev/sdc1
- 取出 SD 卡/拇指驱动器
- 插入 SD 卡/拇指驱动器