制作 LiveCD
#!/bin/bash
# Author: Redbrother
# Email: [email protected]
# license: None
# data :2019 10
# scripts in /usr/share/debootstrap/scripts
############################################
ARCH=amd64
RELEASE=bionic
installer_url=http://mirrors.aliyun.com/ubuntu/
IMAGE=ubuntu-$RELEASE
set -e
#自定义版本项
if [ "`whoami`" != "root" ]; then
echo "User must be root 需要root权限."
exit 0
fi
apt install debootstrap genisoimage p7zip-full squashfs-tools -y
if [ "$?" != "0" ]; then
echo "Commands required: mkisofs, 7z, wget."
exit 0
fi
if [ "`which mkisofs`" == "" ]; then
ln -s /usr/bin/genisoimage /usr/bin/mkisofs
fi
############################################
# debootstrap a base live
umount squashfs-root/* 2>/dev/null || true
rm -rf squashfs-root
mkdir -p squashfs-root
debootstrap --arch=$ARCH $RELEASE squashfs-root $installer_url
############################################
cd squashfs-root
echo "deb $installer_url $RELEASE main restricted universe multiverse" > etc/apt/sources.list
echo "deb $installer_url $RELEASE-updates main restricted universe multiverse" >> etc/apt/sources.list
echo "deb $installer_url $RELEASE-security main restricted universe multiverse" >> etc/apt/sources.list
echo 'APT::Install-Recommends "false";' > etc/apt/apt.conf
chroot . chmod a+s /bin/ping
cp -f /etc/hosts etc/hosts
rm -f etc/resolv.conf
mkdir -p run/NetworkManager/
cp -f /etc/resolv.conf etc/
mount -o bind /dev dev/
mount -o bind /sys sys/
mount -o bind /proc proc/
mount -o bind /dev/pts dev/pts/
chroot . rm -f /sbin/initctl
chroot . dbus-uuidgen > /var/lib/dbus/machine-id
chroot . dpkg-divert --local --rename --add /sbin/initctl
chroot . ln -s /bin/true /sbin/initctl
chroot . apt-get update
chroot . apt-get upgrade --yes
chroot . locale-gen zh_CN.UTF-8
chroot . locale-gen en_US.UTF-8
# kernels and network
echo -e "install kernels and network …… "
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends dbus sudo bash-completion grub-pc linux-image-generic xinit xserver-xorg network-manager apt-transport-https --yes
DEBIAN_FRONTEND=noninteractive chroot . apt-get download network-manager --yes
# Livecd necessary
echo -e "install Livecd necessary "
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends ubuntu-standard casper lupin-casper discover laptop-detect os-prober --yes
# useful tools
echo -e "install useful tools "
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends vim nano gvfs lzma unrar rar unzip zip genisoimage p7zip-full wget aria2 zsync jigdo-file squashfs-tools debootstrap syslinux rsync dump parted gparted mdadm python3 python3-distutils --yes
# auto login
mkdir -p etc/lightdm/lightdm.conf.d
mkdir -p usr/share/lightdm/lightdm.conf.d
echo '. /etc/bash_completion' >> etc/bash.bashrc
echo '[SeatDefaults]' > etc/lightdm/lightdm.conf.d/90-default.conf
echo 'autologin-user=ubuntu' >> etc/lightdm/lightdm.conf.d/90-default.conf
echo 'autologin-user-timeout=0' >> etc/lightdm/lightdm.conf.d/90-default.conf
echo 'autologin-guest=false' >> etc/lightdm/lightdm.conf.d/90-default.conf
echo 'allow-guest=false' >> usr/share/lightdm/lightdm.conf.d/60-lightdm-gtk-greeter.conf
cp -f ../tools/bin/* usr/local/bin
chroot . chmod +755 -R /usr/local/bin
chroot . chmod +644 -R /boot
chroot . chmod +755 -R /root
chroot . xsession-config
############################################
# zh_CN language packs and timezone
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends language-pack-zh-hans language-pack-zh-hans-base language-pack-gnome-zh-hans language-pack-gnome-zh-hans-base --yes
chroot . cp -rf usr/share/locale-langpack/zh_CN/LC_MESSAGES/* usr/share/locale/zh_CN/LC_MESSAGES/
chroot . rm -rf usr/share/locale-langpack/
chroot . rm -f etc/timezone
chroot . rm -f etc/localtime
chroot . rm -f etc/adjtime
chroot . ln -s /usr/share/zoneinfo/Asia/Shanghai etc/localtime
echo '0.0 0 0' > etc/adjtime
echo '0' >> etc/adjtime
echo 'LOCAL' >> etc/adjtime
echo 'Asia/Shanghai' > etc/timezone
echo 'export TZ=Asia/Shanghai' >> etc/profile
echo 'export LANG=zh_CN.UTF-8' >> etc/profile
echo 'export LC_ALL=zh_CN.UTF-8' >> etc/profile
# user settings
mkdir -p home/ubuntu/Desktop
mkdir -p home/ubuntu/.config
cp -rf ../tools/ubuntu/config/* home/ubuntu/.config/
chmod +666 -R home/ubuntu/.config/
chmod +666 -R home/ubuntu/Desktop/
chroot . rm -f home/ubuntu/.config/user-dirs.*
# fcitx-googlepinyin
echo -e "install fcitx-googlepinyin and fonts "
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends ttf-ubuntu-font-family fonts-wqy-microhei fcitx fcitx-ui-classic fcitx-frontend-gtk2 fcitx-config-gtk fcitx-googlepinyin --yes
# fcitx config
echo 'export GTK_IM_MODULE="xim"' > etc/X11/Xsession.d/96fcitx_start
echo 'export XMODIFIERS="@im=fcitx"' >> etc/X11/Xsession.d/96fcitx_start
cp -f usr/local/bin/97pinyin* etc/X11/Xsession.d/
cp -f usr/local/bin/fcitx-pinyin* usr/bin
cp ../tools/settings/*.desktop usr/share/applications
cp ../tools/settings/fcitx-config.desktop etc/xdg/autostart/
# mate desktop environment
echo -e " mate desktop environment "
DEBIAN_FRONTEND=noninteractive chroot . apt-get install --no-install-recommends mate-desktop-environment-core lightdm pluma engrampa eom mate-calc --yes
# cd usr/share/themes/ && rm -rf `ls | grep -v Default Adwaita Black* Blue* Green* Menta* ` && cd ../../..
cd usr/share/themes/ && rm -rf ContrastHigh* Clearlook* Crux* eOS* HighContrast* Industria* Mist* Raleigh* Redmond* Traditional* && cd ../../..
# add gonme applications Links
chroot . rm -f /usr/bin/gedit
chroot . rm -f /usr/bin/nautilus
chroot . rm -f /usr/bin/gnome-terminal
chroot . rm -f /usr/bin/file-roller
chroot . rm -f /usr/bin/eog
ln -s pluma usr/bin/gedit
ln -s caja usr/bin/nautilus
ln -s eom usr/bin/eog
ln -s engrampa usr/bin/file-roller
ln -s mate-terminal usr/bin/gnome-terminal
# modify some desktop
cd usr/share/applications
sed -i 's/GenericName\[zh_CN\]/Name\[zh_CN\]/' engrampa.desktop
sed -i 's/GenericName\[zh_CN\]/Name\[zh_CN\]/' mate-terminal.desktop
sed -i 's/GenericName\[zh_CN\]/Name\[zh_CN\]/' caja-browser.desktop
sed -i 's/Exec=fcitx/Exec=im-config/' fcitx.desktop
sed -i 's/Settings/System/' fcitx-con*.desktop
sed -i 's/NoDisplay\=true//' python*.desktop
sed -i 's/System\;//' mate-terminal.desktop
sed -i 's/System\;//' caja-browser.desktop
sed -i 's/MATE\ 之眼//' eom.desktop
cd ../../../
# 重新配置网络 and # clean up
chroot . rm -f etc/resolv.conf
chroot . dpkg -i network-manager*.deb
chroot . apt clean
chroot . apt-clean
chroot . apt-get clean
chroot . rm -rf tmp/*
chroot . rm -f network-manager*.deb
chroot . rm -f vmlinu* initrd.im*
chroot . rm -f etc/init/tty3.conf etc/init/tty4.conf etc/init/tty5.conf
chroot . rm -f /var/lib/dbus/machine-id
chroot . rm -f /sbin/initctl
chroot . dpkg-divert --rename --remove /sbin/initctl
umount -lf sys/
umount -lf proc/
umount -lf dev/pts/
umount -lf dev/
cd ..
############################################
# ubuntu live base system is Success
echo -e "ubuntu live base system is successful, you can diy it in squashfs-root contents "
echo -e ". Do you want to make an ISO image ? [y/n] "
read choice
if [ "$choice" != "y" ]; then
echo -e "you can run ' sudo bash mkiso.sh ' to build an iso LiveCD;successful "
exit 0
fi
# make iso file ; build an iso image
mkdir -p cdimage/casper
rm -f cdimage/casper/*
rm -f $IMAGE.iso
cp -f squashfs-root/boot/vmlinuz-*-generic cdimage/casper/vmlinuz
cp -f squashfs-root/boot/initrd.img-*-generic cdimage/casper/initrd.lz
mksquashfs squashfs-root cdimage/casper/filesystem.squashfs -e boot
chmod +666 -R cdimage/casper
mkdir -p cdimage/.disk
touch cdimage/ubuntu
touch cdimage/.disk/base_installable
echo "full_cd/single" > cdimage/.disk/cd_type
echo "Ubuntu Remix $RELEASE" > cdimage/.disk/info
cd cdimage && find . -type f -print0 | xargs -0 md5sum | grep -v "\./md5sum.txt" > md5sum.txt && cd ..
mkisofs -o $IMAGE.iso -b isolinux/isolinux.bin -c isolinux/boot.cat -no-emul-boot -boot-load-size 4 -boot-info-table -r -V "$IMAGE" -cache-inodes -J -l cdimage/
chmod +666 $IMAGE.iso
cd cdimage && rm -f ubuntu md5sum.txt && cd ..
rm -rf cdimage/.disk
rm -rf cdimage/casper/*
echo -e "successfully done"
其他尝试
- 创建虚拟盘 c.img 使用
bximage
即可 - 创建分区 (m: 帮助, n: 创建新分区, a: 添加引导标记, p: 查看, w: 保存)
sudo fdisk c.img
- 映射到 /dev/mapper
sudo kpartx -av c.img
ls -l /dev/mapper
- 根据映射 loop 格式化
sudo mkfs.ext4 /dev/mapper/loop0p1
- 安装 grub
sudo mount /dev/mapper/loop0p1 /mnt
sudo grub-install --boot-directory=/mnt/ /dev/loop0
- 复制 vmlinz initrd.img
sudo cp /boot/vmlinuz-4.15.0-30deepin-generic /mnt/boot/vmlinuz
sudo cp /boot/initrd.img-4.15.0-30deepin-generic /mnt/boot/initrd.img
- 创建配置文件 grub.cfg,复制到 /mnt/boot/grub/ 中
default=0
timeout=10
insmod ext2
set root='hd0,msdos1'
menuentry 'x01.treeos' {
insmod gzio
insmod part_msdos
insmod ext2
set root='hd0,msdos1'
linux /boot/vmlinuz ro --set=root --hint-bios=hd0,msdos1 --hint-efi=hd0,msdos1
initrd /boot/initrd.img
}
Make LiveCD 脚本
# 取消注释即可下载
#wget http://kernel.org/pub/linux/kernel/v4.x/linux-4.10.9.tar.xz
#wget http://busybox.net/downloads/busybox-1.24.2.tar.bz2
#wget http://kernel.org/pub/linux/utils/boot/syslinux/syslinux-6.03.tar.xz
mkdir isoimage
tar -xvf linux-4.10.9.tar.xz
tar -xvf busybox-1.25.1.tar.bz2
tar -xvf syslinux-6.03.tar.gz
cd busybox-1.25.1
make distclean defconfig
sed -i "s/.*CONFIG_STATIC.*/CONFIG_STATIC=y/" .config
make busybox install
cd _install
rm -f linuxrc
mkdir dev proc sys
echo '#!/bin/sh' > init
echo 'dmesg -n 1' >> init
echo 'mount -t devtmpfs none /dev' >> init
echo 'mount -t proc none /proc' >> init
echo 'mount -t sysfs none /sys' >> init
echo 'setsid cttyhack /bin/sh' >> init
chmod +x init
find . | cpio -R root:root -H newc -o | gzip > ../../isoimage/rootfs.gz
cd ../../linux-4.10.9
make mrproper defconfig bzImage
cp arch/x86/boot/bzImage ../isoimage/kernel.gz
cd ../isoimage
cp ../syslinux-6.03/bios/core/isolinux.bin .
cp ../syslinux-6.03/bios/com32/elflink/ldlinux/ldlinux.c32 .
echo 'default kernel.gz initrd=rootfs.gz' > ./isolinux.cfg
xorriso \
-as mkisofs \
-o ../minimal_linux_live.iso \
-b isolinux.bin \
-c boot.cat \
-no-emul-boot \
-boot-load-size 4 \
-boot-info-table \
./
cd ..
标签:bin,chroot,填补,echo,etc,usr,rm,x01,os.22
From: https://www.cnblogs.com/china_x01/p/17473721.html