resize2fs:Memory alloction failed while trying to resize

最近入手一块 12T 的西数红盘,打算安装到 WD MyCloud Gen1 上,从 4TB 版本升级到 12TB 版本,作为 TimeMachine 来用。

使用 拯救死翘翘了的WD MyCloud 方式恢复镜像之后,最后一步执行

$ resize2fs /dev/sda4

结果报告如下错误:

$ resize2fs /dev/sda4
resize2fs 1.42.5 (29-Jul-2012)
Resizing the filesystem on /dev/sda4 to 2928542715 (4k) blocks.
resize2fs: Memory allocation failed while trying to resize /dev/sda4
Please run 'e2fsck -fy /dev/sda4' to fix the filesystem
after the aborted resize operation.

这个原因网上查询了很久,基本上断定是 e2fsprogs 1.42.5 的 BUG,这个问题在  e2fsprogs 1.42.9 版本修复。修复内容参考代码下的 debian/changelog

关键日志如下:

e2fsprogs (1.42.9-1) unstable; urgency=low

  * Fixed a large number of bugs in resize2fs, e2fsck, debugfs, to
    handle bigalloc and 64-bit file systems.

编译过程参考 How to successfully build packages for WD My Cloud from source 中对于 e2fsprogs 1.42.13 的编译。

参考链接


Debian旧版本源同步脚本

最近 `Debian Wheezy/Jessie` 源被官方归档了,使得许多来不及更新系统的服务器没源可用,http://archive.debian.org  访问速度太慢, 不得以自己写个脚本同步 `Wheezy/Jessie` 源。

`Debian` 官方推荐使用 `debmirror` 同步源,但是在群晖等设备上不方便使用,因此还是用` rsync` 同步通用一些。

主要是自己的 `WD MyCloud Gen1` 在编译软件的时候,依赖 `Wheezy` ,`Jessie` 版本的软件包,又没办法升级系统,只能是自己建立软件源,保存一下,免得日后麻烦。

由于 `Debian` 源的结构,要单独分版本来同步很不方便,包都集中在 `/pool` 目录下,故此脚本主要根据索引文件来生成该版本的包列表`ARCH_EXCLUDE` 用来过滤不同架构的包的`dists` 用来过滤不同版本的同步完成后,整个 `Wheezy/Jessie` 源(`i386,  amd64, arm,  source`) 共 96G

`Wheezy Archive` 源设置

deb http://mirrors.163.com/debian-archive/ wheezy main contrib non-free
deb-src http://mirrors.163.com/debian-archive/ wheezy main contrib non-free

同步脚本代码

#!/bin/sh
#author: igi
#date:   2012-03-28

NAME="debian"
SYNC_FILES="$NAME"_files
#TO="/tmp/$NAME"
TO="./$NAME"
FROM="archive.debian.org::debian-archive/debian"
#FROM="debian.ethz.ch::debian-archive/debian"
#FROM="mirror.1und1.de::debian-archive/debian"
#FROM="debian.koyanet.lv::debian-archive/debian"
#RUNDIR="/tmp/"
RUNDIR="./"

ARCH_EXCLUDE="alpha hppa hurd-i386 ia64 kfreebsd-amd64 kfreebsd-i386 mips mipsel powerpc s390 s390x sparc ppc64el"
for ARCH in $ARCH_EXCLUDE; do
    EXCLUDE=$EXCLUDE"\
        --exclude binary-$ARCH/ \
        --exclude *_$ARCH.deb \
        --exclude *_$ARCH.udeb \
        --exclude installer-$ARCH/ \
        --exclude Contents-$ARCH* "
done

#dists='lenny etch'
dists='wheezy jessie'
for dist in $dists; do
    DIST_INCLUDE=${DIST_INCLUDE}"\
        --include /dists/$dist/ \
        --include /dists/$dist/contrib/ \
        --include /dists/$dist/main/ \
        --include /dists/$dist/non-free/ "
    DIST_EXCLUDE="${DIST_EXCLUDE}\
        --exclude /dists/$dist/* "
done

#sync index files
rsync --progress -av \
    --include 'Packages.gz' \
    --include 'Sources.gz' \
    $DIST_INCLUDE \
    --include '/dists/' \
    --exclude '/*' \
    --exclude '/dists/*' \
    $DIST_EXCLUDE \
    --exclude 'i18n' \
    --exclude 'installer-amd64' \
    --exclude 'installer-i386' \
    --exclude 'installer-armel' \
    --exclude 'installer-arm64' \
    --exclude 'installer-armhf' \
    --exclude 'installer-ppc64el' \
    --exclude 'Release' \
    --exclude '*.bz2' \
    $EXCLUDE \
    "$FROM/" "$TO/"

rm -rf "$RUNDIR"/"$SYNC_FILES"

find "$TO/dists/" -name 'Packages.gz' -exec zgrep 'Filename: ' {} + | awk '{print $2}' >"$RUNDIR"/"$SYNC_FILES"

find "$TO/dists/" -name 'Sources.gz'  -exec zcat {} + | awk '/Package:/{dir="";delete files;next};/Directory:/{dir=$2;next};/Files:/{pass=1;next}; pass && /^ / {files[NR]=$NF}; length(files) && dir && / /{for(i in files) print dir"/"files[i];delete files}; /^[^ ]/{pass=0;next};' >>"$RUNDIR"/"$SYNC_FILES"

#first stage
rsync --progress -v --recursive --times --links --hard-links \
    --files-from="$RUNDIR"/"$SYNC_FILES" \
    "$FROM/" "$TO/"

#second stage
rsync --progress -v --recursive --times --links --hard-links \
    $DIST_INCLUDE \
    --exclude '/dists/*' \
    $EXCLUDE \
    --exclude '/pool/' \
    "$FROM/"  "$TO/"

更多 `debian-archive` 源,见: http://www.debian.org/distrib/archive

参考链接


Debian系统启动非常耗时,屏幕显示“A start job is running for /dev/disk/by-uuid/...a71b-4040-9b53-e92525f6803e”,错误“Timed out waiting for device /dev/disk/by-uuid/197c3d31-a71b-4040-9b53-e92525f6803e”

最近`Debian` 系统启动非常耗时,每次启动都要等待1分30秒的任务超时才能启动,屏幕显示“`A start job is running for /dev/disk/by-uuid/...a71b-4040-9b53-e92525f6803e`”,如下图:

继续阅读Debian系统启动非常耗时,屏幕显示“A start job is running for /dev/disk/by-uuid/...a71b-4040-9b53-e92525f6803e”,错误“Timed out waiting for device /dev/disk/by-uuid/197c3d31-a71b-4040-9b53-e92525f6803e”

Debian:如何从Jessie升级为Buster(Debian 8.0 升级到Debian 10.0)

Debian 10(代号为Buster)已经正式发布,可以开始尝鲜Debian 10了。 需要逐版本升级,不要跨版本升级,目前的尝试来看,跨版本升级会出现问题。

1. 更新Debian Jessie到最新版

$ su

$ apt-get update

$ apt-get upgrade

$ apt-get dist-upgrade

2. 将软件源改为Stretch安装源

$ su

$ sed -i 's/jessie/stretch/g' /etc/apt/sources.list

# 替换成国内镜像源(清华大学)
$ sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

$ sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn\/debian-security/g' /etc/apt/sources.list

3. 升级系统版本

$ su

$ apt-get update

$ apt-get dist-upgrade

4. 重启

$ su

$ reboot

5. 更新Debian Stretch到最新版

$ su

$ apt-get update

$ apt-get upgrade

$ apt-get dist-upgrade

$ apt-get autoremove

6. 将软件源改为Buster安装源

$ su

$ sed -i 's/stretch/buster/g' /etc/apt/sources.list

# 替换成国内镜像源(清华大学)
$ sed -i 's/deb.debian.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apt/sources.list

$ sed -i 's/security.debian.org/mirrors.tuna.tsinghua.edu.cn\/debian-security/g' /etc/apt/sources.list

7. 升级系统版本

$ su

$ apt-get update

$ apt-get dist-upgrade

8. 重启

$ su

$ reboot

9. 清理安装包

$ sudo apt-get autoremove

参考链接


OpenmediaVault-4.1.3上编译Linux Kernel 4.14.118

也可以使用下面的方式正常编译 `Linux Kernel 4.14.118` 。

建议使用 `VirtualBox` 上建立虚拟机,保证磁盘空间不小于 `32GB`,给 `root` 用户设置密码,远程通过 `shell` 登录到虚拟机。

查询虚拟机的 `IP`地址的时候,使用

# Debian 9 系统上 ip 命令替代了ifconfig
$ ip addr

命令查询。虚拟机网卡设置的时候,设置为桥接模式,默认的 `NAT` 模式无法通过 `SSH` 登录。

然后执行如下命令:

# 解压缩xz格式的linux内核
$ sudo apt-get install xz-utils

$ cd ~

$ wget https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.14.118.tar.xz -O linux-4.14.118.tar.xz

$ tar -zxvf linux-4.14.118.tar.xz

$ cd linux-4.14.118/

# 升级系统工具,如果不更新,有时候会出现无法编译的情况
$ sudo apt-get update

$ sudo apt-get upgrade

$ sudo apt-get install make

$ sudo apt-get install build-essential

$ sudo apt-get install kernel-package

$ sudo apt-get install ncurses-dev

$ sudo apt-get install libelf-dev

#一路回车到底
$ make oldconfig

$ make-kpkg --initrd kernel-image kernel_headers

完成后,在当前用户目录下生成 `linux-image-4.14.118_4.14.118-10.00.Custom_amd64.deb` 安装包,执行如下命令安装:

$ cd ~

$ sudo dpkg -i linux-image-4.14.118_4.14.118-10.00.Custom_amd64.deb

参考链接


解决Btrfs文件系统ext2_saved文件磁盘占用异常

最近在 `OpenMediaVault 4.1.22-1(Arrakis)` 进行磁盘文件占用分析的时候,发现磁盘空间异常占用问题,如下:

root@openmediavault:/media/6357625f-c966-49ba-9c90-9e8f8ff50433# du -ah --max-depth=1
0	./lost+found
1.5T	./MyCloud
8.0K	./aquota.user
8.0K	./aquota.group
1.3T	./ext2_saved
4.0K	./WDMyCloudSync.sh
2.7T	.

这个 `1.3T ./ext2_saved`  文件是不存在的,并且没办法通过常规命令删除。

这个文件产生的原因是,执行过 从 `EXT3/4` 转换转化分区到 `Btrfs` :

$ btrfs-convert /media/6357625f-c966-49ba-9c90-9e8f8ff50433

完成转换需要删除备份的 `ext2_saved` 子卷,否则空间会不能释放。 请注意,如果没了它(备份子卷),你将没办法还原回 `EXT3/4` 文件系统。

$ sudo apt-get install btrfs-tools

# 执行,然后无视报错
$ btrfs subvolume delete /media/6357625f-c966-49ba-9c90-9e8f8ff50433/ext2_saved

可能会报错:

ERROR: cannot access subvolume /media/6357625f-c966-49ba-9c90-9e8f8ff50433/ext2_saved: No such file or directory

无视这个报错即可。

完成后再次查询文件占用空间:

root@openmediavault:/media/6357625f-c966-49ba-9c90-9e8f8ff50433# du -ah --max-depth=1
0	./lost+found
1.5T	./MyCloud
8.0K	./aquota.user
8.0K	./aquota.group
4.0K	./WDMyCloudSync.sh
1.5T	.

可以看到空间已经被释放了。

参考链接


解决VirtualBox无法共享粘贴板的问题(Debian)

一直使用VirtualBox安装的Debian环境编译WD MyCloud的代码。但是最近VirtualBox升级后,升级增强功能,然后共享粘贴板就不能使用了。

如果执行

$ VBoxClient --clipboard

可看到错误信息:

VBoxClient: Failed to connect to the VirtualBox kernel service, rc=VERR_FILE_NOT_FOUND

继续阅读解决VirtualBox无法共享粘贴板的问题(Debian)

WD MyCloud编译PHP-7.1安装包

1.按照How to successfully build packages for WD My Cloud from source中的介绍,搭建完成WDMyCloud的编译环境

2.使用如下方式编译:

$ su 

$ cd ~/wdmc-build/64k-jessie
$ chroot build

$ mount -t proc none /proc
$ mount -t devtmpfs none /dev
$ mount -t devpts none /dev/pts

$ export DEBIAN_FRONTEND=noninteractive
$ export DEBCONF_NONINTERACTIVE_SEEN=true
$ export LC_ALL=C
$ export LANGUAGE=C
$ export LANG=C
$ export DEB_CFLAGS_APPEND='-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE'
$ export DEB_BUILD_OPTIONS=nocheck

$ cd root

$ apt-get update
$ apt-get upgrade

$ apt-get install ca-certificates
$ apt-get install dh-autoreconf
$ apt-get install git
$ apt-get install apache2-dev
$ apt-get install apache2
$ apt-get install systemtap-sdt-dev
$ apt-get install libxml2
$ apt-get install libxml2-dev
$ apt-get install libssl-dev
$ apt-get install libpcre3 libpcre3-dev
$ apt-get install libsqlite3-dev
$ apt-get install libbz2-dev

$ apt-get install libcurl4-openssl-dev

$ apt-get install libqdbm-dev

$ apt-get install libdb-dev

#configure: error: Cannot find enchant
$ apt-get install enchant libenchant-dev

#configure: error: webp/decode.h not found
$ apt-get install libwebp-dev

#configure: error: png.h not found.
$ apt-get install libpng-dev

#configure: error: xpm.h not found.
$ apt-get install libxpm-dev

#configure: error: freetype-config not found.
$ apt-get install libfreetype6-dev

#configure: error: Unable to find gd.h anywhere under /usr
$ apt-get install libgd-dev

#configure: error: Unable to locate gmp.h
$ apt-get install libgmp-dev

#configure: error: utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.
$ apt-get install libc-client-dev

#configure: error: Kerberos libraries not found.
$ apt-get install libkrb5-dev

#configure: error: libfbclient, libgds or libib_util not found! Check config.log for more information.
$ apt-get install firebird-dev

#configure: error: Unable to detect ICU prefix or no failed. Please verify ICU install prefix and make sure icu-config works.
$ apt-get install libicu-dev

#configure: error: sasl.h not found!
$ apt-get install libsasl2-dev

#configure: error: mcrypt.h not found. Please reinstall libmcrypt.
$ apt-get install libmcrypt-dev

#checking for unixODBC support... configure: error: ODBC header file '/usr/include/sqlext.h' not found!
$ apt-get install unixODBC-dev

#configure: error: Directory /usr is not a FreeTDS installation directory
$ apt-get install FreeTDS-dev

#configure: error: Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path
$ apt-get install libpq-dev

#configure: error: Cannot find pspell
$ apt-get install libpspell-dev

#configure: error: Please reinstall libedit - I cannot find readline.h
$ apt-get install libedit-dev

#configure: error: Can not find recode.h anywhere under /usr /usr/local /usr /opt.
$ apt-get install librecode-dev

#configure: error: Could not find net-snmp-config binary. Please check your net-snmp installation.
$ apt-get install libsnmp-dev

#configure: error: Cannot find libtidy
$ apt-get install libtidy-dev

#checking for XMLRPC-EPI in default path... not found
$ apt-get install libxmlrpc-epi-dev

#configure: error: xslt-config not found. Please reinstall the libxslt >= 1.1.0 distribution
$ apt-get install libxslt-dev

#configure: error: Please reinstall the libzip distribution
$ apt-get install libzip-dev

$ git clone -b master-7.1 https://gitlab.com/deb.sury.org/php.git php7 --depth=1 

$ cd php7

#禁用systemd
$ sed -i "s/CONFIGURE_SYSTEMD *:= *--with-fpm-systemd/CONFIGURE_SYSTEMD := --without-fpm-systemd/g" debian/rules

$ sed -i "s/DH_SYSTEMD *:= *--with systemd/DH_SYSTEMD :=/g" debian/rules

$ dpkg-buildpackage -d -b -uc

#编译依赖包php-common
$ cd ..

$ git clone -b debian/50 git://anonscm.debian.org/pkg-php/php-defaults.git

$ cd php-defaults

#禁用systemd
$ sed -i "s/DH_SYSTEMD *:= *--with *systemd/DH_SYSTEMD :=/g" debian/rules

$ dpkg-buildpackage -d -b -uc

$ exit

3.编译php-apcu,这个模块WD MyCloud需要

$ su 

$ cd ~/wdmc-build/64k-jessie
$ chroot build

$ mount -t proc none /proc
$ mount -t devtmpfs none /dev
$ mount -t devpts none /dev/pts

$ export DEBIAN_FRONTEND=noninteractive
$ export DEBCONF_NONINTERACTIVE_SEEN=true
$ export LC_ALL=C
$ export LANGUAGE=C
$ export LANG=C
$ export DEB_CFLAGS_APPEND='-D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE'
$ export DEB_BUILD_OPTIONS=nocheck

$ cd root

#安装依赖
$ apt-get install shtool
$ apt-get install liblist-moreutils-perl
$ apt-get install xml2

# "dch" command 
$ apt-get install devscripts

#安装我们刚刚编译好的PHP7包
$ dpkg -i php-common_50_all.deb
$ dpkg -i php7.1-common_7.1.10-1_armhf.deb
$ dpkg -i php7.1-readline_7.1.10-1_armhf.deb
$ dpkg -i php7.1-opcache_7.1.10-1_armhf.deb
$ dpkg -i php7.1-json_7.1.10-1_armhf.deb
$ dpkg -i php7.1-cli_7.1.10-1_armhf.deb 
$ dpkg -i php7.1-dev_7.1.10-1_armhf.deb

#编译依赖
$ git clone git://anonscm.debian.org/pkg-php/dh-php.git

$ cd dh-php

$ git checkout debian/0.26 -b debian/0.26

$ dpkg-buildpackage -d -b -uc

$ cd ..

$ dpkg -i dh-php_0.26_all.deb

#参考 https://packages.debian.org/source/sid/php-apcu
# git://anonscm.debian.org/pkg-php/php-apcu.git
#https://pecl.php.net/package/APCu
$ git clone git://anonscm.debian.org/pkg-php/php-apcu.git

$ cd php-apcu

$ git checkout debian/5.1.8+4.0.11-1 -b debian/5.1.8+4.0.11-1

#Build the package
$ debuild -b -d -uc -us

$ cd ..

$ dpkg -i php-apcu_5.1.8+4.0.11-1_armhf.deb

$ git clone git://anonscm.debian.org/pkg-php/php-apcu-bc.git

$ cd php-apcu-bc

$ debuild -b -d -uc -us

$ exit

上面下载的代码由于是国外的服务器,因此可能会出现一直无法下载成功的情况,可以从这里下载代码的拷贝。PHP源代码点击这里PHP7 Debian编译配置文件点击这里dh-php源代码点击这里php-apcu源代码点击这里,  php-apcu-bc源代码点击这里

WDMyCloud中安装的时候执行如下命令:

$ sudo apt-get update

$ sudo apt-get install -y --force-yes php7.1

$ sudo apt-get install -y --force-yes libapache2-mod-php7.1

$ sudo apt-get install -y --force-yes php7.1-curl

$ sudo apt-get install -y --force-yes php-apcu

$ sudo apt-get install -y --force-yes php-apcu-bc

$ sudo apt-get install -y --force-yes php7.1-xml

#这个是个坑,如果没有增加这个模块,也是可以正常启动的,但是却没办法正常登录进入,应用会出现异常
$ sudo apt-get install -y --force-yes php7.1-mbstring

#由于PHP7中的parse_ini_file不再兼容“#”作为注释字符,只能使用“;”进行注释,但是这个注释无法
#被其他应用读取,而WDMyCloud里面的其他脚本也需要读取/etc/system.conf里面的内容
#目前唯一的解决方法就是删除全部的注释行
# /var/www/htdocs/UI/index.php	 	 	 	 
$ sudo cp /etc/system.conf /etc/system.conf.bak	 	 
$ sudo sed -i '/^#/d' /etc/system.conf

#语法调整
$ sudo cp /var/www/htdocs/UI/views/common/dates.php /var/www/htdocs/UI/views/common/dates.php.bak

$ sudo sed -i 's/^<?.*$/<?php/g' /var/www/htdocs/UI/views/common/dates.php

#/var/www/htdocs/UI/views/layouts/main/main.php	 
$ sudo cp /etc/php5/apache2/conf.d/include_path.ini /etc/php/7.1/apache2/conf.d/

$ sudo chmod 777 /etc/php/7.1/apache2/conf.d/include_path.ini

$ sudo a2dismod php5	 	 

$ sudo a2enmod php7.1

$ sudo phpenmod curl	 	 

$ sudo service apache2 restart

注意,这部分的功能目前仅仅是可用,还没有达到完全正常的情况,如果出现问题,可以切换回PHP5,目前已知的完美切换回到原来的PHP5的办法就是卸载上面安装的所有PHP7的相关应用才能切换成功,否则总有部分小功能不是太正常.

参考链接