如何在linux中编写文件系统,linux – 如何编写脚本以在运行的根文件系统上调整分区大小?...

编程入门 行业动态 更新时间:2024-10-09 06:22:32

如何在linux中编写<a href=https://www.elefans.com/category/jswz/34/1771295.html style=文件系统,linux – 如何编写脚本以在运行的根文件系统上调整分区大小?..."/>

如何在linux中编写文件系统,linux – 如何编写脚本以在运行的根文件系统上调整分区大小?...

我有一个VM模板,用于使用virt-clone / KVM构建其他VM. VM模板为4GB以节省空间.我从中构建的VM的存储位于iSCSI目标或LVM卷(取决于功能),并且它们的文件系统大小因计算机的角色而异.

从模板创建新VM后,如果我正在构建需要超过4GB磁盘的东西,我必须调整根分区的大小.这在交互式使用parted时工作正常,但不是脚本化的.在尝试删除文件系统时,我被问到是否要继续使用’-s’

下面的输出显示了失败的脚本尝试和一个有效的交互式会话来实现此目的.

调整克隆后根分区的最佳方法是什么,可以简单地编写脚本?

失败的分手脚本尝试

克隆后进行分区

# parted /dev/vda p

Model: Virtio Block Device (virtblk)

Disk /dev/vda: 10.7GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 1049kB 4294MB 4293MB primary ext4 boot

脚本删除尝试

# parted /dev/vda -s rm 1

Warning: Partition /dev/vda1 is being used. Are you sure you want to continue?

#

删除失败后的分区

# parted /dev/vda p

Model: Virtio Block Device (virtblk)

Disk /dev/vda: 10.7GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 1049kB 4294MB 4293MB primary ext4 boot

工作交互式调整大小(然后重启)

删除前分区

# parted /dev/vda p

Model: Virtio Block Device (virtblk)

Disk /dev/vda: 10.7GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 1049kB 4294MB 4293MB primary ext4 boot

删除并创建使用所有磁盘的新分区

# parted /dev/vda

(parted) rm 1

Warning: Partition /dev/vda1 is being used. Are you sure you want to continue?

Yes/No? y

Error: Partition(s) 1 on /dev/vda have been written, but we have been unable to

inform the kernel of the change, probably because it/they are in use. As a

result, the old partition(s) will remain in use. You should reboot now before

making further changes.

Ignore/Cancel? I

(parted) mkpart p ext4 1 -1

(parted)

# parted /dev/vda p

Model: Virtio Block Device (virtblk)

Disk /dev/vda: 10.7GB

Sector size (logical/physical): 512B/512B

Partition Table: msdos

Number Start End Size Type File system Flags

1 1049kB 10.7GB 10.7GB primary ext4

文件系统调整大小

# resize2fs /dev/vda1

resize2fs 1.42.9 (4-Feb-2014)

Filesystem at /dev/vda1 is mounted on /; on-line resizing required

old_desc_blocks = 1, new_desc_blocks = 1

The filesystem on /dev/vda1 is now 2621184 blocks long.

# df -kh .

Filesystem Size Used Avail Use% Mounted on

/dev/vda1 9.8G 1.6G 7.9G 17% /

更多推荐

如何在linux中编写文件系统,linux – 如何编写脚本以在运行的根文件系统上调整分区大小?...

本文发布于:2024-03-14 05:54:53,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1735782.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件系统   分区   脚本   大小   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!