目的:在家搭建一个自己私有NAS,不是配置路由器。
硬件环境:联想瘦客户机。
软件版本:openwrt-21.02.2-x86-64-generic-ext4-combined-efi.img.gz
创建系统:用U盘启动瘦客户机,使用”IMG写盘工具.exe“将镜像写入瘦客户机的SSD中,然后就可从SSD上启动瘦客户机。
一.重新创建镜像
- 在虚拟机中安装ubuntu桌面版
ubuntu-21.10-desktop-amd64
- 安装相关依赖包
sudo apt install build-essential libncurses5-dev libncursesw5-dev \
zlib1g-dev gawk git gettext libssl-dev xsltproc rsync wget unzip python
- 获取Image Builder
wget https://downloads.openwrt.org/releases/21.02.2/targets/x86/64/openwrt-imagebuilder-21.02.2-x86-64.Linux-x86_64.tar.xz
- 解压压缩包,并进入解压目录
tar -J -x -f openwrt-imagebuilder-*.tar.xz
cd openwrt-imagebuilder-*/
- 修改为国内镜像源,提高创建镜像的速度
清华大学:mirrors.tuna.tsinghua.edu.cn/openwrt
中科大:mirrors.ustc.edu.cn/openwrt
腾讯:mirrors.cloud.tencent.com/openwrt
cp repositories.conf repositories.conf.bak
vi repositories.conf
- 可以使用下列变量自定义镜像 The image building can be customized with the following variables:
Variable变量名 | Description描述 |
| Specifies the target image to build |
| A list of packages to embed into the image |
| Directory with custom files to include |
| Alternative output directory for the images |
| Add this to the output image filename (sanitized) |
| The names of services from |
- 创建镜像
原根目录尺寸仅104M。保留其它参数不变,仅修改根目录尺寸。
cp .config .config.bak
vi .config
...修改内容
CONFIG_TARGET_KERNEL_PARTSIZE=16
CONFIG_TARGET_ROOTFS_PARTSIZE=960
...
make clean
make image
当rootfs设置尺寸大于1G时,make imge报错,不知道什么原因!!!
make[3]: *** [Makefile:152: /home/scott/openwrt-imagebuilder-21.02.2-x86-64.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/tmp/openwrt-21.02.2-x86-64-generic-ext4-rootfs.img.gz] Killed
make[3]: *** Deleting file '/home/scott/openwrt-imagebuilder-21.02.2-x86-64.Linux-x86_64/build_dir/target-x86_64_musl/linux-x86_64/tmp/openwrt-21.02.2-x86-64-generic-ext4-rootfs.img.gz'
make[2]: *** [Makefile:186: build_image] Error 2
make[1]: *** [Makefile:124: _call_image] Error 2
make: *** [Makefile:240: image] Error 2
- 镜像生成
$ls -l bin/targets/x86/64
total 52104
-rw-rw-r-- 1 bill bill 9649272 3月 19 17:16 openwrt-21.02.2-x86-64-generic-ext4-combined-efi.img.gz
-rw-rw-r-- 1 bill bill 9454540 3月 19 17:16 openwrt-21.02.2-x86-64-generic-ext4-combined.img.gz
-rw-rw-r-- 1 bill bill 4414492 3月 19 17:16 openwrt-21.02.2-x86-64-generic-ext4-rootfs.img.gz
-rw-r--r-- 1 bill bill 4817568 3月 19 17:16 openwrt-21.02.2-x86-64-generic-kernel.bin
-rw-rw-r-- 1 bill bill 2665 3月 19 17:16 openwrt-21.02.2-x86-64-generic.manifest
-rw-rw-r-- 1 bill bill 4299456 3月 19 17:16 openwrt-21.02.2-x86-64-generic-rootfs.tar.gz
-rw-rw-r-- 1 bill bill 8707051 3月 19 17:16 openwrt-21.02.2-x86-64-generic-squashfs-combined-efi.img.gz
-rw-rw-r-- 1 bill bill 8512962 3月 19 17:16 openwrt-21.02.2-x86-64-generic-squashfs-combined.img.gz
-rw-rw-r-- 1 bill bill 3471223 3月 19 17:16 openwrt-21.02.2-x86-64-generic-squashfs-rootfs.img.gz
-rw-rw-r-- 1 bill bill 1878 3月 19 17:16 profiles.json
-rw-rw-r-- 1 bill bill 1129 3月 19 17:16 sha256sums
二 网卡IP配置
设置静态地址。网关和DNS直接设成自己路由器的网关地址.
配置文件路径/etc/config/network
config interface 'loopback'
option device 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config globals 'globals'
option ula_prefix 'fd00:000f:d776::/48'
config interface 'lan'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.1.100'
option netmask '255.255.255.0'
option gateway '192.168.1.1'
option dns '192.168.1.1'
option ip6assign '60'
然后重启网卡
#/etc/init.d/network restart
三. 安装软件包
- 安装fdisk
root@OpenWrt:# opkg update
root@OpenWrt:# opkg install fdisk