使用 zypper 從頭安裝 openSUSE

其他Linux/Unix/BSD/OSX等发行版讨论
回复
头像
torachiyo
帖子: 81
注册时间: 2015-11-29 8:32
系统: Kali Linux

使用 zypper 從頭安裝 openSUSE

#1

帖子 torachiyo » 2018-03-13 13:27

範例:
版本 openSUSE Tumbleweed
安裝目標 sda13

代码: 全选

#######################################
### Install openSUSE
#######################################
TARGET=sda13
LABEL=SUSE

RUN_IN_CHROOT="chroot /mnt /bin/bash -c"
USERNAME="suse"
TIMEZONE=Asia/Taipei
HOSTNAME="localhosts"
SET_LANG=zh_TW
PASSWD="0000"

#######################################
# Format
mkfs.ext4 -F /dev/$TARGET
# Add Label
e2label /dev/$TARGET $LABEL

# Mount Target 
mount /dev/$TARGET /mnt

#################################################
### 安裝 zypper
#################################################
## 如在 fedora 系統下須安裝 zypper
# sudo dnf install zypper
# rm -rf /etc/zypp/repos.d
# mkdir -p /etc/zypp/repos.d

#################################################
### 添加套件庫
#################################################
# Tumbleweed 滾動式版本套件庫
zypper ar -n tumbleweed -f -c -t yast2 -K http://download.opensuse.org/tumbleweed/repo/oss/ tumbleweed

# Leap 42.3 發行版套件庫
# zypper ar -n leap -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/42.3/repo/oss/ leap

# Testing Leap 15 發行版套件庫
# zypper ar -n testing -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/15.0/repo/oss/ testing

# 刷新套件庫
zypper -n --no-gpg-checks refresh

#######################################
### Install Base System
#######################################
NAME=tumbleweed
# NAME=leap
# NAME=testing

zypper \
--reposd-dir /etc/zypp/repos.d/ \
--no-gpg-checks \
--root /mnt \
--releasever $NAME \
-n install \
patterns-base-base \
patterns-base-enhanced_base \
patterns-base-minimal_base \
patterns-base-apparmor

echo 'nameserver 192.168.1.1' > /mnt/etc/resolv.conf
echo 'nameserver 192.168.1.1' >> /mnt/etc/resolv.conf.netconfig

mount --bind /dev /mnt/dev
mount --bind /run /mnt/run
mount --bind /proc /mnt/proc
mount --bind /sys /mnt/sys

#################################################
### Add Repos To New System
#################################################
# Tumbleweed
$RUN_IN_CHROOT "zypper ar -n tumbleweed -f -c -t yast2 -K http://download.opensuse.org/tumbleweed/repo/oss/ tumbleweed"
$RUN_IN_CHROOT "zypper ar -n tumbleweed-non-oss -f -c -t yast2 -K http://download.opensuse.org/tumbleweed/repo/non-oss/ tumbleweed-non-oss"
$RUN_IN_CHROOT "zypper addrepo http://packman.inode.at/suse/openSUSE_Tumbleweed/ packman"
$RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/repositories/multimedia:/apps/openSUSE_Tumbleweed/ opensuse-multimedia-apps"
$RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/tumbleweed/repo/oss/ gwdg"

# Leap 42.3
# $RUN_IN_CHROOT "zypper ar -n leap -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/42.3/repo/oss/ leap"
# $RUN_IN_CHROOT "zypper ar -n leap-non-oss -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/42.3/repo/non-oss/ leap-non-oss"
# $RUN_IN_CHROOT "zypper addrepo http://packman.inode.at/suse/openSUSE_Leap_42.3/ packman"
# $RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/repositories/multimedia:/apps/openSUSE_Leap_42.3/ opensuse-multimedia-apps"
# $RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/distribution/leap/42.3/repo/oss/ gwdg"

# Testing
# $RUN_IN_CHROOT "zypper ar -n testing -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/15.0/repo/oss/ testing"
# $RUN_IN_CHROOT "zypper ar -n testing-non-oss -f -c -t yast2 -K http://download.opensuse.org/distribution/leap/15.0/repo/non-oss/ testing-non-oss"
# $RUN_IN_CHROOT "zypper addrepo http://packman.inode.at/suse/openSUSE_Leap_15.0/ packman"
# $RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/repositories/multimedia:/apps/openSUSE_Leap_15.0/ opensuse-multimedia-apps"
# $RUN_IN_CHROOT "zypper addrepo http://ftp.gwdg.de/pub/opensuse/distribution/leap/15.0/repo/oss/ gwdg"

# 刷新套件庫
$RUN_IN_CHROOT "zypper -n --no-gpg-checks refresh"

#######################################
### Install genfstab
#######################################
if [ ! -f "/usr/local/bin/genfstab" ]; then
    wget https://github.com/Mint-Fans/linux-package/raw/master/genfstab
    cp genfstab /usr/local/bin/
    chmod 755 /usr/local/bin/genfstab
fi

cp /usr/local/bin/genfstab /mnt/usr/local/bin/
chmod 755 /mnt/usr/local/bin/genfstab


#######################################
### Install All System Packages
#######################################
KERNEL='kernel-default kernel-default-devel'
FIRMWARE='alsa-firmware mpt-firmware pullin-bcm43xx-firmware adaptec-firmware bluez-firmware zd1211-firmware ipw-firmware atmel-firmware'
XORG='xorg-x11 xorg-x11-driver-video xorg-x11-driver-input xorg-scripts xorg-x11-essentials xorg-x11-fonts xorg-x11-fonts-core xorg-x11-Xvnc xorg-x11-libX11-ccache xorg-x11-server xorg-x11-server-Xspice xorg-x11-server-extra xtermset'
XF86='xf86-input-evdev xf86-input-joystick xf86-input-keyboard xf86-input-libinput xf86-input-mouse xf86-input-void xf86-input-wacom xf86-video-intel xf86-video-fbdev xf86-video-nouveau xf86-video-vesa'
SYSUTIL='rpm-build gvfs ntfs-3g busybox zenity xbacklight squashfs git subversion inxi genisoimage xorriso pcsc-tools'
COMPRESS='arj lzip ncompress sharutils p7zip'
XFCE='xfce4-appfinder xfce4-dict xfce4-notifyd xfce4-panel xfce4-screenshooter xfce4-session xfce4-settings xfce4-taskmanager xfce4-terminal xfce4-vala xfconf xfdesktop xfsprogs xfwm4 tumbler thunar thunar-plugin-shares thunar-plugin-media-tags thunar-plugin-archive thunar-plugin-vcs thunar-sendto-blueman thunar-volman'
XFCE_PLUGIN='xfce4-panel-plugin-appmenu xfce4-panel-plugin-battery xfce4-panel-plugin-clipman xfce4-panel-plugin-cpufreq xfce4-panel-plugin-datetime xfce4-panel-plugin-dict xfce4-panel-plugin-diskperf xfce4-panel-plugin-eyes xfce4-panel-plugin-fsguard xfce4-panel-plugin-genmon xfce4-panel-plugin-mailwatch xfce4-panel-plugin-mount xfce4-panel-plugin-mpc xfce4-panel-plugin-multiload-nandhp xfce4-panel-plugin-netload xfce4-panel-plugin-netspeed xfce4-panel-plugin-notes xfce4-panel-plugin-places xfce4-panel-plugin-power-manager xfce4-panel-plugin-screenshooter xfce4-panel-plugin-smartbookmark xfce4-panel-plugin-sntray xfce4-panel-plugin-systemload xfce4-panel-plugin-timeout xfce4-panel-plugin-timer xfce4-panel-plugin-verve xfce4-panel-plugin-wavelan xfce4-panel-plugin-weather xfce4-panel-plugin-whiskermenu xfce4-panel-plugin-xkb xfce4-power-manager'
YASE2='patterns-gnome-gnome_yast patterns-yast-yast2_basis patterns-yast-yast2_install_wf autoyast2'
NETWORK='samba-client NetworkManager-openconnect NetworkManager-openvpn NetworkManager-pptp-gnome NetworkManager-vpnc'
FONTS='dejavu-fonts wqy-microhei-fonts noto-mono-fonts noto-sans-fonts liberation-fonts'
XDG='xdg-user-dirs-gtk'
DM='lightdm'
AUDIO='alsa-utils alsa-plugins-pulse pulseaudio-module-bluetooth'
QT="libqt5-qtbase-platformtheme-gtk3"
THEMES='plymouth-branding-openSUSE gnome-icon-theme gtk2-engine-murrine'
BASEAPP='firefox MozillaFirefox-translations-common leafpad gparted vlc gucharmap gnome-calculator gnome-font-viewer thunderbird brasero catfish gimp engrampa'
MEDIA='gstreamer-plugins-bad gstreamer-plugins-libav gstreamer-plugins-ugly gstreamer-plugins-base gstreamer-plugins-good'
XAPP='pix xplayer xreader xviewer xviewer-plugins'
IME='fcitx fcitx-configtool fcitx-gtk2 fcitx-gtk3 fcitx-chewing fcitx-anthy'
PROXY='囗囗囗 proxychains-ng'

$RUN_IN_CHROOT "zypper install $KERNEL $FIRMWARE $XORG $XF86 $SYSUTIL $COMPRESS $XFCE $XFCE_PLUGIN $YASE2 $NETWORK $FONTS $XDG $DM $AUDIO $QT $THEMES $BASEAPP $MEDIA $XAPP $IME $PROXY"

#######################################
### Options 選擇性安裝
#######################################
# NETWORK_ADDON='NetworkManager-iodine-gnome NetworkManager-l2tp-gnome NetworkManager-openconnect-gnome NetworkManager-openswan-gnome NetworkManager-openvpn-gnome NetworkManager-pptp-gnome NetworkManager-strongswan-gnome NetworkManager-vpnc-gnome'
# FIRMWARE_ADDON='adaptec-firmware atmel-firmware bcm20702a1-firmware bcm43xx-firmware bluez-firmware crystalhd-firmware hackrf-firmware ipw-firmware mpt-firmware pullin-bcm43xx-firmware sigrok-firmware-fx2lafw technisat-usb2-firmware uhd-firmware zd1211-firmware'
# $RUN_IN_CHROOT "zypper install $NETWORK_ADDON $FIRMWARE"
# $RUN_IN_CHROOT "zypper install patterns-desktop-laptop"
# $RUN_IN_CHROOT "zypper install patterns-base-x86"

#######################################
### Config System
#######################################
echo $HOSTNAME > /mnt/etc/hostname
$RUN_IN_CHROOT "ln -sf /usr/share/zoneinfo/$TIMEZONE /etc/localtime"
$RUN_IN_CHROOT "hwclock --systohc --localtime"

echo 'LANG="SET_LANG.utf8"' > /mnt/etc/locale.conf
sed -i s/SET_LANG/$SET_LANG/g /mnt/etc/locale.conf

$RUN_IN_CHROOT "localectl set-x11-keymap us"

$RUN_IN_CHROOT "groupadd -g 1000 $USERNAME"
$RUN_IN_CHROOT "useradd -g 1000 -m $USERNAME"

echo $USERNAME:$PASSWD > /mnt/pw.txt
echo root:$PASSWD >> /mnt/pw.txt
$RUN_IN_CHROOT "chpasswd < /pw.txt"
rm -f /mnt/pw.txt

#######################################
### Install Customize Packages
#######################################
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/pa-applet-17.33-1.x86_64.rpm"
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/xfce4-volumed-pulse-0.2.0-1.x86_64.rpm"
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/gnome-theme-mint-2018-2.noarch.rpm"
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/create-ap-0.2-5.noarch.rpm"
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/aircrack-ng-cli-1.2-1.noarch.rpm"
$RUN_IN_CHROOT "zypper -n --no-gpg-checks install https://github.com/Mint-Fans/linux-package/raw/SUSE/suse-adjust-xfce-2018-1.noarch.rpm"

#######################################
### Generate initramfs
#######################################
chroot /mnt /bin/bash << 'ENDCHROOT'
mkinitrd
ENDCHROOT

#######################################
### Install Grub2
#######################################
DISK=$(echo $TARGET | sed s/[0-9]//g)

### BIOS
$RUN_IN_CHROOT "grub2-install --force /dev/$DISK"

### EFI
rm -rf /mnt/boot/efi
mkdir -p /mnt/boot/efi
mount /dev/"$DISK"1 /mnt/boot/efi
$RUN_IN_CHROOT "grub2-install --target=x86_64-efi /dev/$DISK"
mkdir -p /mnt/boot/efi/EFI/boot
cp /mnt/boot/efi/EFI/*/grubx64.efi /mnt/boot/efi/EFI/boot/bootx64.efi

### Config Grub2
$RUN_IN_CHROOT "grub2-mkconfig -o /boot/grub2/grub.cfg"

#######################################
### Rebuild fstab
#######################################
/usr/local/bin/genfstab -U /mnt > /mnt/etc/fstab

#######################################
### Clean Cache
#######################################
$RUN_IN_CHROOT "zypper clean"

#######################################
### umount & exit
#######################################
umount /mnt/run
umount /mnt/dev
umount /mnt/proc
umount /mnt/sys
umount -l /mnt

完成圖
图片
回复