制作ubuntu rootfs
下载base镜像:
http://cdimage.ubuntu.com/ubuntu-base/releases/16.04.1/release/
解压:
tar -zxf ubuntu-xx-base-amd64.tar.gz -C ./ubuntu-rootfs/
apt-get install qemu-user-static
cp /usr/bin/qemu-amd64-static usr/bin
cp -b /etc/resolv.conf etc/
#!/bin/bash
#
function mnt() {
echo “MOUNTING”
sudo mount -t proc /proc ${2}proc
sudo mount -t sysfs /sys ${2}sys
sudo mount -o bind /dev ${2}dev
sudo mount -o bind /dev/pts ${2}dev/pts
sudo chroot ${2}
}
function umnt() {
echo “UNMOUNTING”
sudo umount ${2}proc
sudo umount ${2}sys
sudo umount ${2}dev/pts
sudo umount ${2}dev
}
if [ “1” == “-m” ] && [ -n “
then
mnt 1 2
elif [ “1” == “-u” ] && [ -n “
then
umnt 1 2
else
echo “”
echo “Either 1’st, 2’nd or both parameters were missing”
echo “”
echo “1’st parameter can be one of these: -m(mount) OR -u(umount)”
echo “2’nd parameter is the full path of rootfs directory(with trailing ‘/’)”
echo “”
echo “For example: ch-mount -m /media/sdcard/”
echo “”
echo 1st parameter : ${1}
echo 2nd parameter : ${2}
fi
sudo bash ./ch_mount.sh -m ./ubuntu-rootfs
挂载到根文件系统中去
先设置下用户名密码:
useradd -s ‘/bin/bash’ -m -G adm,sudo yourusername
echo “Set password for yourusername:”
passwd yourusername
echo “Set password for root:”
passwd root
设置主机名:
echo ‘ubuntu.yourusername’ > /etc/hostname
设置自动更新dns
dpkg-reconfigure resolvconf
安装各种常用的包
apt-get install
language-pack-en-base
sudo
ssh
net-tools
network-manager
iputils-ping
rsyslog
bash-completion
apt install gcc gdb tmux wget curl vim kmod -y
打包生成镜像
#!/bin/bash
image_name=$1
set -x
rm -rf tmpfs {image_name}.img {image_name}.img.tar.gz
dd if=/dev/zero of=${image_name}.img bs=1G count=4
mkfs.ext4 ${image_name}.img
mkdir -p tmpfs
mount ${image_name}.img tmpfs
cp -rfp ./ubuntu-amd64/* ./tmpfs/
umount tmpfs
e2fsck -p -f ${image_name}.img
resize2fs -M ${image_name}.img
tar zcf {image_name}.img.tar.gz {image_name}.img
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/185035.html原文链接:https://javaforall.cn