1. 程式人生 > >制作U盤自動和手動安裝的ISO文件

制作U盤自動和手動安裝的ISO文件

u盤 自動裝系統

在我們平時的工作中,偶爾需要裝個系統什麽的,一般會有通過網絡PEX安裝或者cobbler安裝的,但是萬一沒網呢?那這時候就需要一個U盤來拯救你啦。

首先我們說一下思路:

(1)選擇一個文件夾,把本機上的光盤文件全部拷貝進去(註意別丟了隱藏文件喲)

(2)用sys-config-kickstart命令制作應答文件

(3)修改isolinux下面的isolinux.cfg啟動菜單配置

(4)重新創建ISO的元數據

(5)打包那個文件做成

(6)用isohybrid轉換一下格式,用於U盤啟動


實驗過程:

1、復制文件並查看一下

[[email protected]
/* */ ~]# pwd /root [[email protected] ~]# cp -r /misc/cd /root/app/centos6 [[email protected] ~]# cd app/centos6/;ls -a . EFI isolinux RPM-GPG-KEY-CentOS-6 TRANS.TBL .. EULA Packages RPM-GPG-KEY-CentOS-Debug-6 .treeinfo CentOS_BuildTag GPL RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-Security-6 .discinfo images repodata RPM-GPG-KEY-CentOS-Testing-6 [[email protected]
/* */ centos6]#

2、在主機上用system-config-kickstart制作一個應該文件,這裏的步驟和平時手動安裝的內容一樣,只是展現的形式不同而已,自己一項一項的選擇好自己需要的配置點擊左上角File裏面的save保存到/root/app/centos6下即可,保存位置有圖形界面可以自己選擇,這裏我就不一一截圖了 (如果願意深入了解kickstart的用法可以看一下一位網友的博客:http://blog.csdn.net/taiyang1987912/article/details/42176709 或者這一個網絡連接: http://jingyan.baidu.com/article/5d368d1eedc8ac3f60c057e1.html )

技術分享

3、修改引導菜單文件,直接保存會報錯,記得用強行保存

[[email protected] centos6]# ls
centos6.cfg      GPL       RELEASE-NOTES-en-US.html    RPM-GPG-KEY-CentOS-Security-6
CentOS_BuildTag  images    repodata                    RPM-GPG-KEY-CentOS-Testing-6
EFI              isolinux  RPM-GPG-KEY-CentOS-6        TRANS.TBL
EULA             Packages  RPM-GPG-KEY-CentOS-Debug-6
[[email protected] centos6]# vim isolinux/i
initrd.img    isolinux.bin  isolinux.cfg  
[[email protected] centos6]# vim isolinux/isolinux.cfg 

default vesamenu.c32
#prompt 1
timeout 600

display boot.msg

menu background splash.jpg
menu title Welcome to CentOS 6.9!
menu color border 0 #ffffffff #00000000
menu color sel 7 #ffffffff #ff000000
menu color title 0 #ffffffff #00000000
menu color tabmsg 0 #ffffffff #00000000
menu color unsel 0 #ffffffff #00000000
menu color hotsel 0 #ff000000 #ffffffff
menu color hotkey 7 #ffffffff #ff000000
menu color scrollbar 0 #ffffffff #00000000

label Desktop
  menu label ^Automatic Desktop Install
  menu default
  kernel vmlinuz
  append initrd=initrd.img ks=cdrom:/centos6.cfg
label man
  menu label ^Manual ^Install
  kernel vmlinuz
  append initrd=initrd.img 
label local
  menu label Boot from ^local drive
  localboot 0xffff

4、查看一下復制過來的iso文件的元數據,並刪除了重新生成一次,因為之前的不能用

[[email protected] centos6]# ls  /root/app/centos6/repodata/
1cde788f77b08a7eb3dfdba12fa384a5f0214147a717a1e2d4504368037fba90-c6-x86_64-comps.xml.gz
43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml
594889376c2452dc8178bbaed982deba4dff38a42716ac03fc84576c17b1d79b-filelists.sqlite.bz2
92299bd89d0ef9e4030e78d31399a96b41712239f032d0092f2345ba5cb01404-other.xml.gz
9f2ef5087547b18bdccc798b0cad7456047fc69ca17db69d3159b6dd84ed1c11-primary.xml.gz
ad73b7fa76bb45feea7e4cdb2d896279524039545e8764ceaa515665f897a0c5-primary.sqlite.bz2
dc8a406c3cc1c5103ff2e22a1b9d3d0d09a13a6fda831ffecebdd55484bf5146-filelists.xml.gz
f18d3f35ab887f27a5acc563138bd58a0c9b668e8cd79dbb32c4fc610c88e320-other.sqlite.bz2
repomd.xml
TRANS.TBL
[[email protected] centos6]# cp   /root/app/centos6/repodata/43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml   /root/
[[email protected] centos6]# rm -rf /root/app/centos6/repodata/*
[[email protected] centos6]# ls /root/app/centos6/repodata/
[[email protected] centos6]# createrepo -g /root/43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml  /root/app/centos6/
Spawning worker 0 with 3240 pkgs
Workers Finished
Gathering worker results

Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
[[email protected] centos6]# ls /root/app/centos6/repodata/
1cde788f77b08a7eb3dfdba12fa384a5f0214147a717a1e2d4504368037fba90-c6-x86_64-comps.xml.gz
43d8fd068164b0f042845474d6a22262798b9f0d1f49ad1bf9f95b953089777d-c6-x86_64-comps.xml
5113e542b34891f5f6dd037f23cf2948c9014fbc852a8f7eec41f0323e2ae271-filelists.sqlite.bz2
6311d0e7a1fdcd08b425d8874500482c3910ed5ce921fa6e29dd9d5ab4418b28-filelists.xml.gz
8ddb832924451aebf1f64376f4e35bd7f3a48896b3f2b82e18346095afdaba07-primary.xml.gz
b97e8f350c99ed991f87e748a98cf1c2b6fb17e8ce3fb27d578e8bb4fbb51f00-other.sqlite.bz2
e91391eb5ceb40d428c81767ea369dc3c37b10bed9d382f482054e58f4b53359-other.xml.gz
fd29a4c1ae16874afec555e620fa18f3573951aacc776bbd569186ccf0d77193-primary.sqlite.bz2
repomd.xml
[[email protected] centos6]#

5、把剛剛做的軟件包封裝成一個iso文件

[[email protected] centos6]# mkisofs -R -J -T -v --no-emul-boot --boot-load-size 4 --boot-info-table -V "Centos 6.9 x86_64 boot" -b isolinux/isolinux.bin -c isolinux/boot.cat -o /root/centos6.iso  /root/app/centos6

…………
 99.19% done, estimate finish Sat Jun 24 10:12:43 2017
 99.45% done, estimate finish Sat Jun 24 10:12:43 2017
 99.71% done, estimate finish Sat Jun 24 10:12:43 2017
 99.96% done, estimate finish Sat Jun 24 10:12:43 2017
Total translation table size: 821601
Total rockridge attributes bytes: 361464
Total directory bytes: 548864
Path table size(bytes): 112
Done with: The File(s)                             Block(s)    1955144
Writing:   Ending Padblock                         Start Block 1955630
Done with: Ending Padblock                         Block(s)    150
Max brk space used 362000
1955780 extents written (3819 MB)

6、做成的ISO文件就已經可以直接使用,如圖,就可以直接安裝完成。

技術分享

技術分享

技術分享

技術分享

6、需要做給U盤使用的話轉換一下就ok

[[email protected] ~]# isohybrid /root/centos6.iso 
isohybrid: Warning: more than 1024 cylinders: 3820
isohybrid: Not all BIOSes will be able to boot this device
[[email protected] ~]# lsblk
NAME   MAJ:MIN RM   SIZE RO TYPE MOUNTPOINT
sr0     11:0    1   3.7G  0 rom  /media/CentOS_6.9_Final
sda      8:0    0   200G  0 disk 
├─sda1   8:1    0  1000M  0 part /boot
├─sda2   8:2    0  97.7G  0 part /
├─sda3   8:3    0  48.8G  0 part /app
├─sda4   8:4    0     1K  0 part 
├─sda5   8:5    0     1G  0 part 
├─sda6   8:6    0     2G  0 part [SWAP]
└─sda7   8:7    0 203.9M  0 part 
sdb      8:16   1    30G  0 disk 
└─sdb1   8:17   1    30G  0 part 
[[email protected] ~]# mount /dev/sdb1 /mnt/
mount: you must specify the filesystem type
[[email protected] ~]# mkfs.ext4 /dev/sdb1
mke2fs 1.41.12 (17-May-2010)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
Stride=0 blocks, Stripe width=0 blocks
1970416 inodes, 7872472 blocks
393623 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=4294967296
241 block groups
32768 blocks per group, 32768 fragments per group
8176 inodes per group
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208, 
	4096000

Writing inode tables: done                            
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

This filesystem will be automatically checked every 37 mounts or
180 days, whichever comes first.  Use tune2fs -c or -i to override.
[[email protected] ~]# dd if=/root/centos6.iso of=/dev/sdb1
7823360+0 records in
7823360+0 records out
4005560320 bytes (4.0 GB) copied, 448.366 s, 8.9 MB/s
7823360+0 records in
7823360+0 records out
4005560320 bytes (4.0 GB) copied, 448.366 s, 8.9 MB/s



附件:

制作的應答文件centos6.cfg

#platform=x86, AMD64, or Intel EM64T
#version=DEVEL
# Firewall configuration
firewall --disabled
# Install OS instead of upgrade
install
# Use network installation
cdrom
# Root password
rootpw --plaintext magedu
# System authorization information
auth  --useshadow  --passalgo=sha512
# Use graphical install
text
reboot
# System keyboard
keyboard us
# System language
lang en_US
# SELinux configuration
selinux --disabled
# Do not configure the X Window System
skipx
# Installation logging level
logging --level=info

# System timezone
timezone Asia/Shanghai
# Network information
network  --bootproto=dhcp --device=eth0 --onboot=on
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
clearpart --all  
# Disk partitioning information
part /boot --fstype="ext4" --size=500
part / --fstype="ext4" --size=50000
part swap --fstype="swap" --size=4096
part /app --fstype="ext4" --size=20000

%post
useradd wang
echo magedu |passwd --stdin wang
rm -rf /etc/yum.repos.d/*
cat > /etc/yum.repos.d/base.repo <<EOF
[base]
name=base
baseurl=http://172.16.0.1/centos/6
gpgcheck=0
EOF
%end

%packages
@core
@server-policy
@workstation-policy
%end


本文出自 “11986114” 博客,請務必保留此出處http://11996114.blog.51cto.com/11986114/1950476

制作U盤自動和手動安裝的ISO文件