mx4 ubuntu edtion救砖

记一次mx4 ubuntu edtion救砖

1 成砖原因:

作死在手机终端下执行rm -rf -i /删除根目录, 次要问题是recovery分区不能用fastboot刷写, 导致无法通过ubuntu-device-flash重新下载ubuntu touch

ubuntu-device-flash touch --channel=ubuntu-touch/stable/meizu.en --device=arale --bootstrap

最后只好通过写入flyme救砖

2 救砖过程:

在meizu官网下载update.zip, 解压, 此过程需用到解压后目录下boot.img(内核), system.new.dat, system.transfer.list 这三个文件, 以及一个dat文件转img脚本 sdat2img

2.1 system.new.dat转system.img

2.1.1准备dat文件转img的python脚本: sdat2img.py

将以下代码复制至你的.py脚本文件内, (非常感谢 xpirt, lux78, howellzhu的python脚本 XD)

#!/usr/bin/env python
# -*- coding: utf-8 -*-
#====================================================
#          FILE: sdat2img.py
#       AUTHORS: xpirt - luxi78 - howellzhu
#          DATE: 2015-10-11 16:33:32 CST
#====================================================

import sys, os

try:
    TRANSFER_LIST_FILE = str(sys.argv[1])
    NEW_DATA_FILE = str(sys.argv[2])
    OUTPUT_IMAGE_FILE = str(sys.argv[3])
except IndexError:
   print ("\nsdat2img - usage is: \n\n      sdat2img   \n\n")
   print ("Visit xda thread for more information.\n")
   try:
       input = raw_input
   except NameError: pass
   input ("Press ENTER to exit...\n")
   sys.exit()

BLOCK_SIZE = 4096

def rangeset(src):
    src_set = src.split(',')
    num_set =  [int(item) for item in src_set]
    if len(num_set) != num_set[0]+1:
        print ('Error on parsing following data to rangeset:\n%s' % src)
        sys.exit(1)

    return tuple ([ (num_set[i], num_set[i+1]) for i in range(1, len(num_set), 2) ])

def parse_transfer_list_file(path):
    trans_list = open(TRANSFER_LIST_FILE, 'r')
    version = int(trans_list.readline())    # 1st line = transfer list version
    new_blocks = int(trans_list.readline()) # 2nd line = total number of blocks

    # system.transfer.list:
    #   - version 1: android-5.0.0_r1
    #   - version 2: android-5.1.0_r1
    #   - version 3: android-6.0.0_r1

    # skip next 2 lines. we don't need this stuff now
    if version >= 2:
        trans_list.readline()               # 3rd line = stash entries needed simultaneously
        trans_list.readline()               # 4th line = number of blocks that will be stashed

    commands = []
    for line in trans_list:
        line = line.split(' ')              # 5th & next lines should be only commands
        cmd = line[0]
        if cmd in ['erase', 'new', 'zero']:
            commands.append([cmd, rangeset(line[1])])
        else:
            # skip lines starting with numbers, they're not commands anyway.
            if not cmd[0].isdigit():
                print ('No valid command: %s.' % cmd)
                trans_list.close()
                sys.exit(1)

    trans_list.close()
    return version, new_blocks, commands

def init_output_file_size(output_file_obj, commands):
    all_block_sets = [i for command in commands for i in command[1]]
    max_block_num = max(pair[1] for pair in all_block_sets)
    output_file_obj.seek(max_block_num*BLOCK_SIZE - 1)
    output_file_obj.write('\0'.encode('utf-8'))
    output_file_obj.flush()

def main(argv):
    version, new_blocks, commands = parse_transfer_list_file(TRANSFER_LIST_FILE)
    output_img = open(OUTPUT_IMAGE_FILE, 'wb')
    init_output_file_size(output_img, commands)
    new_data_file = open(NEW_DATA_FILE, 'rb')

    for command in commands:
        if command[0] == 'new':
            for block in command[1]:
                begin = block[0]
                end = block[1]
                block_count = end - begin
                data = new_data_file.read(block_count*BLOCK_SIZE)
                print('Copying {} blocks into position {}...'.format(block_count, begin))
                output_img.seek(begin*BLOCK_SIZE)
                output_img.write(data)
        else:
            print('Skipping command %s' % command[0])

    output_img.close()
    new_data_file.close()
    print ('\nDone! Output image: %s' % os.path.realpath(output_img.name))

if __name__ == "__main__":
    main(sys.argv)

2.1.2 转system.new.dat 为 system.img:

建议将得到的python脚本文件xxx.py放在update.zip解压后的目录下, 如 xxxxx/update/. 执行以下命令生成system.img

./sdat2img.py system.transfer.list system.new.dat system.img


转为system.img后还有一件事情需要做, 先挂载system.img, 再删除挂载目录下的recovery-from-boot.p文件, 不删除的话, 刷写后会无法开机, 具体原因还不清楚 >.<.

可通过以下命令删除system.img中的recover-from-boot.p

mkidr system
sudo mount --rw system system.img
sudo rm system/recovery-from-boot.p
sudo umount system
rmdir system

2.2 刷入boot.img与system.img

在mx4关机状态下长按电源键 + 音量(-)进入fastboot模式

打开终端, 进入update.zip解压后的目录, 输入

fastboot flash boot boot.img  //刷boot.img
fastboot flash system system.img  //刷system.img
fastboot reboot  //重启

第一次开机会耗费较长时间, 请耐心等候, 至此, 救砖成功 :D

3 几点疑问:

1. 最让我困惑的是, 我的这部mx4 ubuntu edtion在fastboot下无法刷写recovery, 问了其他网友说是没有这样的问题>.< . (如果recovery 可以在fastboot 下刷写的话, 就没上述的那么麻烦, 直接可以ubuntu-device-flash刷入)

2. 刷入flyme的时候, 刚开始刷入boot.img system.img 后, 机器依然无法启动, 后来偶然看到某论坛说"删除'recovery-from-boot.p' ",试了下居然成功了实在不可思议, 但为什么删了这个文件就可以让手机启动了? 为什么有了这个文件手机就不能启动? 这个文件的作用?

3. 刷入flyme, 其实是想再通过adb刷回ubuntu touch, 显然, 回不去了, recovery上锁了的样子, 之前也尝试过"xen0n"(blog.xen0n.name) 的 cm13, 但得到system.img刷入时总提示" get_partition_name() fail", 这又是为什么? Q.Q

4. 更早以前, 按照https://wiki.ubuntu.com/Touch/Deploying的说明, 尝试制作system.img, 刷入失败(提示"Brick phone?" "Write data error"),

自己尝试制作system.img的步骤如下:

# 1. 创建system.img并挂载于system目录
fallocate -l 2G system.img
mke2fs -F system.img
mkdir system
sudo mount -o loop system.img system

# 此时system system.img在同一目录

# 2. 制作system.img

# 将ubuntu-device-flash下载的压缩包ubuntu-xxxx device-xxxx放在system.img所在目录 
cp ~/.cache/ubuntuimage/pool/ubuntu-* ./
cp ~/.cache/ubuntuimage/pool/device-* ./

# 再解压在system目录
sudo tar --numeric-owner -xaf ubuntu-xxxx.tar.xz system

# 将device-xxx解压, 把device-xxx/system/var/lib/lxc/android/system.img 复制到 ./system/var/lib/lxc/android/system.img
# 此步骤的作用是? 这里的system.img是android驱动? 求解答 >.<

# 3.压缩system.img
# 执行以下三行命令压缩 system.img

e2fsck -yf system.img
resize2fs -M system.img
e2fsck -yf system.img

#执行以下命令
dumpe2fs system.img | less

#在上行命令中找到Block Size 和 Block Count并相乘,将相乘结果作为参数SIZE执行下行脚本
truncate -s SIZE system.img

#至此完成







最后非常感谢大神们编写的各种工具, 脚本, 还有很多人的热心解答(sry我问的问题总是那么弱智), 虽然回不到uTouch, 至少手机活过来了, 所以建议不要rm -rf /

欢迎指出错别字等各种错误, 还有很多疑问希望能一起探讨解决 XD

你可能感兴趣的:(杂,Ubuntu,Linux)