制作ubuntu rootfs

制作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 "$2" ] ;
then
    mnt $1 $2
elif [ "$1" == "-u" ] && [ -n "$2" ];
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

安装各种常用的包

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 pciutils ssh resolvconf -y

设置自动更新dns

dpkg-reconfigure resolvconf

打包生成镜像

#!/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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值