如何解决Paramiko exec_command 不适用于 mkfs? 问题排查步骤
使用 Paramiko 执行以下 bash 的一些问题:
def format_disk(self,device,size,dformat,mount,name):
stdin_,stdout_,stderr_ = self.client.exec_command(f"pvcreate {device};" \
f"vgcreate {name}-vg {device};" \
f"lvcreate -L {size} --name {name}-lv {name}-vg;" \
f"mkfs.{dformat} /dev/{name}-vg/{name}-lv;" \
f"mkdir {mount};" \
f"echo '/dev/{name}-vg/{name}-lv {mount} {dformat} defaults 0 0' >> /etc/fstab")
print(f"mkfs.{dformat} /dev/{name}-vg/{name}-lv;")
打印语句输出:mkfs.ext4 /dev/first_try-vg/first_try-lv;
如果我将这个确切的命令复制并粘贴到服务器上,则不会出现错误,并且会按预期格式化磁盘。
问题排查步骤
运行python脚本前的服务器:
ls: cannot access /first_try: No such file or directory
[root@localhost ~]# vgs
[root@localhost ~]# lvs
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Feb 25 07:32:51 2021
#
# Accessible filesystems,by reference,are maintained under '/dev/disk'
# See man pages fstab(5),findfs(8),mount(8) and/or blkid(8) for more info
#
UUID=38b7e96a-71e5-4089-a348-bd23828f9dc8 / xfs defaults 0 0
UUID=72fd2a6a-85db-4596-9fc2-6604d0d865a3 /boot xfs defaults 0 0
运行python脚本后的服务器:
[root@localhost ~]# ls /first_try/
[root@localhost ~]# vgs
VG #PV #LV #SN Attr VSize VFree
first_try-vg 1 1 0 wz--n- <20.00g <15.00g
[root@localhost ~]# lvs
LV VG Attr LSize Pool Origin Data% Meta% Move Log cpy%sync Convert
first_try-lv first_try-vg -wi-a----- 5.00g
[root@localhost ~]# cat /etc/fstab
#
# /etc/fstab
# Created by anaconda on Thu Feb 25 07:32:51 2021
#
# Accessible filesystems,mount(8) and/or blkid(8) for more info
#
UUID=38b7e96a-71e5-4089-a348-bd23828f9dc8 / xfs defaults 0 0
UUID=72fd2a6a-85db-4596-9fc2-6604d0d865a3 /boot xfs defaults 0 0
/dev/first_try-vg/first_try-lv /first_try ext4 defaults 0 0
[root@localhost ~]# mount -a
mount: wrong fs type,bad option,bad superblock on /dev/mapper/first_try--vg-first_try--lv,missing codepage or helper program,or other error
In some cases useful info is found in syslog - try
dmesg | tail or so.
来自 mount -a
的错误表明磁盘未格式化。
如果我手动格式化磁盘并运行 mount -a
它可以工作。
示例:
[root@localhost ~]# mkfs.ext4 /dev/first_try-vg/first_try-lv
mke2fs 1.42.9 (28-Dec-2013)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks,Stripe width=0 blocks
327680 inodes,1310720 blocks
65536 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=1342177280
40 block groups
32768 blocks per group,32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768,98304,163840,229376,294912,819200,884736
Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): mdone
Writing superblocks and filesystem accounting information: done
[root@localhost ~]# mount -a
[root@localhost ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 4.7G 14G 27% /
devtmpfs 471M 0 471M 0% /dev
tmpfs 487M 0 487M 0% /dev/shm
tmpfs 487M 8.4M 478M 2% /run
tmpfs 487M 0 487M 0% /sys/fs/cgroup
/dev/sda1 297M 147M 151M 50% /boot
tmpfs 98M 12K 98M 1% /run/user/42
tmpfs 98M 0 98M 0% /run/user/0
/dev/mapper/first_try--vg-first_try--lv 4.8G 20M 4.6G 1% /first_try
解决方法
Pariminko 无法处理 mkfs
的输出。我将命令更改为使用 -q
安静标志,并且能够成功运行脚本。
新命令 mkfs -q -t {dformat} /dev/{name}-vg/{name}-lv
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。