Debian

debootstrap是debian/ubuntu下的一个工具,用来构建一套基本的系统(根文件系统)。生成的目录符合Linux文件系统标准(FHS),即包含了/boot、/etc、/bin、/usr等等目录,但它比发行版本的Linux体积小不少,固然功能也没那么强大,所以,只能说是“基本的系统”。linux

fedora下(centos亦可用)有相似功能的工具:febootstrap。观察这两个工具名称,能够看到debootstrap使用debian前缀“de”,而febootstrap使用fedora前缀“fe”,bootstrap含义为“引导”,并若是作过LFS的话,对它了解会比较多,而在编译gcc编译器时也有涉及到这个概念。不过debootstrap或febootstrap彷佛没有表达出“引导”的意思。bootstrap

在已经安装loongnix系统的环境下安装Debian,安装loongnix时分了两个分区,而且预留一部分的空间。ubuntu

下载根文件系统到本地

一、安装debootstrap:vim

# sudo apt-get install debootstrap


二、debootstrap的使用centos

sudo debootstrap --arch [平台] [发行版本代号] [目录]
 例:  sudo debootstrap --arch i386 trusty /mnt 便是构建x86(32位)平台ubuntu最新发行版14.04(代号为trusty)的基本系统,存放到/mnt目录下

 当前debian维护三个发行版本:stable、testing、unstable
 sudo debootstra[ --arch mips64el stable /mnt

 当前debootstrap支持的发行版本能够在/usr/share/debootstrap/scripts查看,而各发行版代号,能够到http://en.wikipedia.org/wiki/List_of_Ubuntu_releases查看。好比gutsy是7.10的代号,precise是12.04的代号等。

 

下载成功后的文件在/mnt/var下,如:工具

$ tree
    .
    ├── debootstrap
    │   ├── debootstrap.log
    │   └── debpaths
    └── var
    ├── cache
    │   └── apt
    │       └── archives
    │           ├── adduser_3.113+nmu3ubuntu3_all.deb
    │           ├── apt_1.0.1ubuntu2_i386.deb

三、下面使用chroot进入/mnt目录oop

latelee@ubuntu:~$ cd /mnt/
latelee@ubuntu: /mnt$ ls
bin  boot  dev  etc  home  lib  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
latelee@ubuntu: /mnt$ sudo -s
[sudo] password for latelee:
root@ubuntu: /mnt# chroot .


此时只完成了一部分(简单的根文件系统到本地中,但它只具外形而未能实际运用价值。由于只下载了一个最基本的系统,换言之,deboostrap并无帮你作内核、引导的事情)。测试

添加用户

添加用户(不添加不行,不然启动新系统,没法登录):

添加loongson用户,密码也是loongson:

# adduser loongson
# addgroup –system admin
# adduser loongson admin
# passwd loongson

Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

添加root用户密码(不建议):
# passwd root
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

查看/etc/shadow看看root密码是否设置了。若是没有设置,是没有一堆乱码的。下面是加了密码的文件:

# cat /etc/shadow
root:$6$0apsPMDz$rG8PKojxmE/F/nh0WBA25eDsBL31H5sWQllF2OKp2/xy/xS47q37diFQXVQY/wl3FYEVvDooLTZZOFrUbJlCi.:16351:0:99999:7:::

 

利用chroot进入debian系统安装经常使用编辑工具

安装经常使用编译工具:
apt-get install build-essential
apt-get install vim tree

若是要编译内核,则要安装ncurses库:
apt-get install libncurses5-dev libncurses5

(其它的,自行安装)ui

 

添加硬盘

1)原来的硬盘分区fdisk -l
  sda1:/
  sda2:swap交换分区
2)新建分区sda三、sda4
  # fdisk /dev/sda

  这里我分了2个区,sda3是交换区,大小为4GB,剩下的是sda4分区。

  其实分区的操做很简单的,输入上面命令后,只须要输入如下内容便可(感谢强大的“默认”功能)。

  n 回车 回车 回车 +4GB  (第一个分区OK)
  n 回车 回车 回车 回车   (第二个分区OK)
  p (查看分了几个区)
  w (写入分区表并退出)

  格式化:

  mkswap /dev/sda3  格式化为交换分区

  mkfs.ext4 /dev/sda4

  将上面/mnt下的新系统拷贝到sda4中。

  cd /mnt

  mkdir /tmp/tmp

  mount /dev/sda4 /tmp/tmp

  cp -a * /tmp/tmp

如没有多余空间可利用dd制做大文件系统代替添加增长分区(未测试是否可行)es5

du -sh originfile //先看看须要制做的源文件夹大小,假如15M

dd if=/dev/zero of=new_img.img bs=1024 count=20000 //生成20M的文件,bs是一块的大小,count是块的数量,创建一个new_img.img用0填充内容

mkfs.ext4 new_img.img //将new_img.img 格式化为exit4的文件系统

mount new_img.img /mnt/new

cp originfile /mnt/new -R

umount /mnt/new

// new_img.img文件里面就包括了originfile

 

内核

内核能够本身编译,也能够直接拿已有系统的。
若是使用默认配置编译,大概有4000多个模块。占用空间约1.8GB,是比较庞大的。为了省事,能够直接用fedora21自带的内核。

一、把loongnix的fedora21的内核的相关模块拷到debian系统里。

[root@localhost loongson]# cp -a /lib/modules /mnt/lib
[root@localhost loongson]# cp -a /lib/firmware /mnt/lib

 

二、用dracut制做debian的启动镜像:

1)vim /etc/apt/sources.list  //修改源为http;//mirrors.ustc.edu/debian
 2)#apt install dracut   //安装dracut

 

/boot# dracut initrd-3.10.84-17.debian.mips64el.img vmlinuz-3.10.84-17.fc21.loongson.mips64el  //dracut根据已经安装的系统制做initrd启动镜像文件


进入debian的/boot目录下应有下面该项:
initrd-3.10.84-17.debian.mips64el.img

 

三、安装debian自带的启动镜像文件

#apt-get install linux-image-loongson-3


生成如下四个文件:
System.map-4.9.0-4-loongson-3 config-4.9.0-4-loongson-3 initrd.img-4.9.0-4-loongson-3 vmlinux-4.9.0-4-loongson-3
拷贝四个文件到/dev/sda1下的/boot目录下

#mount /dev/sda1 /mnt
#cp System.map-4.9.0-4-loongson-3 config-4.9.0-4-loongson-3 initrd.img-4.9.0-4-loongson-3 vmlinux-4.9.0-4-loongson-3 /mnt/boot

 

2和3选一种(使用第2种方式制做的启动镜像编译JDK的配置文件时阻塞)

四、配置相关文件

1)配置启动菜单(/dev/sda1分区):
    vim /boot/boot.cfg
    配置以下:
title Debian kernel (wd0,0)/boot/vmlinux-4.9.0-4-loongson-3 initrd (wd0,0)/boot/initrd.img-4.9.0-4-loongson-3 args root=/dev/sda4 ro rhgb quiet loglevel=0 LANG=zh_CN.UTF-8
2)配置fstab文件:/etc/fstab(/dev/sda4分区)
root=/dev/sda4 / ext4 defaults 1 1 root=/dev/sda3 swap swap defaults 0 0

 

安装图形化界面

apt-get install gnome 

apt-get update //更新资源网址

apt-get install x-window-system-core gnome-core

安装登陆界面
sudo apt-get install mate-desktop-environment lightdm

配置您的本地化设定,以便使用英语之外的语言,须要安装 locales 支持软件包,而后进行配置:

# aptitude install locales
# dpkg-reconfigure locales

debian的网路和DNS配置

一、在配置文件(/etc/network/interfaces)中添加以下配置:
auto lo iface lo inet loopback allow-hotplug enp5s0 auto enp5s0 iface enp5s0 inet static address 10.10.41.224 netmask 255.255.255.0 gateway 10.10.41.254 dns-nameservers 8.8.8.8


而后重启网卡:

service networking restart
二、安装resolvconf服务,在机器重启或 resolvconf 服务重启 均可以保证配置会写到/etc/resolv.conf 里面
apt-get install resolvconf
相关文章
相关标签/搜索