hhnf333 发表于 2018-8-23 07:24:15

shell脚本实现系统裁剪

#!/bin/bash  
#
  
read -p "请选择要分区的磁盘:(默认/dev/hda) " DISK
  
[ -z $DISK ] && DISK=/dev/hda
  
echo $DISK
  
#分区
  
echo '
  
n
  
p
  
1
  
+90M
  
n
  
p
  
2
  
+300M
  
w' | fdisk $DISK
  
partprobe $DISK
  
sync
  
sync
  
sync
  
sleep 3
  
#格式化
  
mkfs.ext3 ${DISK}1 &>/dev/null
  
mkfs.ext3 ${DISK}2 &>/dev/null
  
echo "Formating ${DISK}1 ${DISK}2 finished"
  
mkdir /mnt/boot
  
mkdir /mnt/sysroot
  
mount ${DISK}1 /mnt/boot
  
mount ${DISK}2 /mnt/sysroot
  
for DIR in `ls /` ;do mkdir /mnt/sysroot/$DIR;done
  
grub-install --root-directory=/mnt $DISK
  
cp/boot/vmlinuz* /mnt/boot/vmlinuz
  
mkdir -pv /tmp/test
  
cd /tmp/test
  
zcat /boot/init*.img | cpio -id
  
cat init | sed -e '/resume.*$/d' -i init
  
cat init | sed -e 's/mkrootdev.*$/mkrootdev -t ext3 -o defaults,ro hda2/' -i init
  
find . | cpio -H newc --quiet -o | gzip -9 >/mnt/boot/initrd.gz
  
cat > /mnt/boot/grub/grub.conf/mnt/sysroot/etc/rc.d/rc.sysinit
页: [1]
查看完整版本: shell脚本实现系统裁剪