guestfish 修改 image file
2015-07-21 12:00
387 查看
Example guestfish session
Sometimes, you must modify a virtual machine image to remove any traces of the MAC address
that was assigned to the virtual network interface card when the image was first created,
because the MAC address will be different when it boots the next time. This example
shows how to use guestfish to remove references to the old MAC address by deleting the /
etc/udev/rules.d/70-persistent-net.rules file and removing the HWADDR line
from the /etc/sysconfig/network-scripts/ifcfg-eth0 file.
Assume that you have a CentOS qcow2 image called centos63_desktop.img. Mount
the image in read-write mode as root, as follows:
# guestfish --rw -a centos63_desktop.img
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
VM Image Guide July 12, 2015 current
18
><fs>
This starts a guestfish session. Note that the guestfish prompt looks like a fish: > <fs>.
We must first use the run command at the guestfish prompt before we can do anything
else. This will launch a virtual machine, which will be used to perform all of the file manipulations.
><fs> run
We can now view the file systems in the image using the list-filesystems command:
><fs> list-filesystems
/dev/vda1: ext4
/dev/vg_centosbase/lv_root: ext4
/dev/vg_centosbase/lv_swap: swap
We need to mount the logical volume that contains the root partition:
><fs> mount /dev/vg_centosbase/lv_root /
Next, we want to delete a file. We can use the rm guestfish command, which works the
same way it does in a traditional shell.
><fs> rm /etc/udev/rules.d/70-persistent-net.rules
We want to edit the ifcfg-eth0 file to remove the HWADDR line. The edit command will
copy the file to the host, invoke your editor, and then copy the file back.
><fs> edit /etc/sysconfig/network-scripts/ifcfg-eth0
If you want to modify this image to load the 8021q kernel at boot time, you must create an
executable script in the /etc/sysconfig/modules/ directory. You can use the touch
guestfish command to create an empty file, the edit command to edit it, and the chmod
command to make it executable.
><fs> touch /etc/sysconfig/modules/8021q.modules
><fs> edit /etc/sysconfig/modules/8021q.modules
We add the following line to the file and save it:
modprobe 8021q
Then we set to executable:
><fs> chmod 0755 /etc/sysconfig/modules/8021q.modules
We're done, so we can exit using the exit command:
><fs> exit
Sometimes, you must modify a virtual machine image to remove any traces of the MAC address
that was assigned to the virtual network interface card when the image was first created,
because the MAC address will be different when it boots the next time. This example
shows how to use guestfish to remove references to the old MAC address by deleting the /
etc/udev/rules.d/70-persistent-net.rules file and removing the HWADDR line
from the /etc/sysconfig/network-scripts/ifcfg-eth0 file.
Assume that you have a CentOS qcow2 image called centos63_desktop.img. Mount
the image in read-write mode as root, as follows:
# guestfish --rw -a centos63_desktop.img
Welcome to guestfish, the libguestfs filesystem interactive shell for
editing virtual machine filesystems.
Type: 'help' for help on commands
'man' to read the manual
'quit' to quit the shell
VM Image Guide July 12, 2015 current
18
><fs>
This starts a guestfish session. Note that the guestfish prompt looks like a fish: > <fs>.
We must first use the run command at the guestfish prompt before we can do anything
else. This will launch a virtual machine, which will be used to perform all of the file manipulations.
><fs> run
We can now view the file systems in the image using the list-filesystems command:
><fs> list-filesystems
/dev/vda1: ext4
/dev/vg_centosbase/lv_root: ext4
/dev/vg_centosbase/lv_swap: swap
We need to mount the logical volume that contains the root partition:
><fs> mount /dev/vg_centosbase/lv_root /
Next, we want to delete a file. We can use the rm guestfish command, which works the
same way it does in a traditional shell.
><fs> rm /etc/udev/rules.d/70-persistent-net.rules
We want to edit the ifcfg-eth0 file to remove the HWADDR line. The edit command will
copy the file to the host, invoke your editor, and then copy the file back.
><fs> edit /etc/sysconfig/network-scripts/ifcfg-eth0
If you want to modify this image to load the 8021q kernel at boot time, you must create an
executable script in the /etc/sysconfig/modules/ directory. You can use the touch
guestfish command to create an empty file, the edit command to edit it, and the chmod
command to make it executable.
><fs> touch /etc/sysconfig/modules/8021q.modules
><fs> edit /etc/sysconfig/modules/8021q.modules
We add the following line to the file and save it:
modprobe 8021q
Then we set to executable:
><fs> chmod 0755 /etc/sysconfig/modules/8021q.modules
We're done, so we can exit using the exit command:
><fs> exit
相关文章推荐
- 设置UIView几个角为圆角
- YUI Compressor使用配置方法 JS/CSS压缩工具
- iOS7中计算UILabel中字符串的高度
- iOS-Core-Animation-Advanced-Techniques(六)
- iOS-Core-Animation-Advanced-Techniques(四)
- iOS-Core-Animation-Advanced-Techniques(一)
- 【xib】加载的一些问题,以UICollectionView 为例
- ContentResolver query 参数详解
- 【EasyUI】——EasyUI的布局
- iOS 中如何除去UIAlertView 规避delegate对象销毁后接收消息的crash
- @RequestParam @RequestBody @PathVariable 等参数绑定注解详解
- Android UI 之一步步教你自定义控件
- AFJSONRequestSerializer
- ORA-02287: sequence number not allowed here解决
- ios NSURLSession completeHandler默认调用quque
- Repeated DNA Sequences
- iOS开发UI篇—Quartz2D使用(绘图路径
- 关于requirejs框架添加时间戳问题
- POJ-1503 Integer Inquiry
- 探秘Java中String、StringBuilder以及StringBuffer