Friday, October 30, 2015

Ubuntu 12.04 random crash and Intel i915 DRM video driver + Sandy Bridge

12/15/2012:
http://ubuntuforums.org/showthread.php?t=2094859

Investigation:

12/28/2011: Intel disable RC6 for Linux 3.2
http://www.phoronix.com/scan.php?page=news_item&px=MTAzNDg

Ubuntu official messages on the issue.
02/18/2012: Official notice of testing new kernel fix for RC6 related hang.
https://lists.ubuntu.com/archives/ubuntu-devel/2012-February/034782.html

04/11/2012: Official announcement of disabling RC6 and updated testing results of testing
https://wiki.ubuntu.com/Kernel/PowerManagementRC6

10/02/2015: Official announcement of reenabling RC6
https://wiki.ubuntu.com/Kernel/PowerManagement/PowerSavingTweaks
NOTE: If you are running 12.04 LTS ("Precise"), this is already enabled by default.

The Intel i915 RC6 feature allows the Graphics Processing Unit (GPU) to enter a lower power state during GPU idle. The i915 RC6 feature applies to Intel Sandybridge and later processors. RC6 was switched between enabled and disabled earlier in the Ubuntu 12.04 Precise LTS development cycle, but eventually all problems were fixed and it is now enabled by default.

Source code (Kernel 3.14):

/drivers/gpu/drm/i915/intel_pm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
static void intel_print_rc6_info(struct drm_device *dev, u32 mode)
{
        if (IS_GEN6(dev))
                DRM_DEBUG_DRIVER("Sandybridge: deep RC6 disabled\n");

        if (IS_HASWELL(dev))
                DRM_DEBUG_DRIVER("Haswell: only RC6 available\n");

        DRM_INFO("Enabling RC6 states: RC6 %s, RC6p %s, RC6pp %s\n",
                        (mode & GEN6_RC_CTL_RC6_ENABLE) ? "on" : "off",
                        (mode & GEN6_RC_CTL_RC6p_ENABLE) ? "on" : "off",
                        (mode & GEN6_RC_CTL_RC6pp_ENABLE) ? "on" : "off");
}

int intel_enable_rc6(const struct drm_device *dev)
{
        /* No RC6 before Ironlake */
        if (INTEL_INFO(dev)->gen < 5)
                return 0;

        /* Respect the kernel parameter if it is set */
        if (i915_enable_rc6 >= 0)
                return i915_enable_rc6;

        /* Disable RC6 on Ironlake */
        if (INTEL_INFO(dev)->gen == 5)
                return 0;

        if (IS_HASWELL(dev))
                return INTEL_RC6_ENABLE;

        /* snb/ivb have more than one rc6 state. */
        if (INTEL_INFO(dev)->gen == 6)
                return INTEL_RC6_ENABLE;

        return (INTEL_RC6_ENABLE | INTEL_RC6p_ENABLE);
}


Since kernel version 3.6, Intel disabled their i915 driver pushing “deep sleep” on all Sandy Bridge devices.  However, the corresponding source code files are varying in different versions.

The video device on ATOM E6xx is GMA 600, a PowerVR SGX 535 based device.  Consequently, Ubuntu 12.04 running on E6xx is immune to the issue by nature.

Monday, October 26, 2015

View, Change, and Repack initrd

View
1
2
3
4
cp /boot/initrd.img /tmp
mv initrd.img initrd.gz
gunzip initrd.gz
cpio -id < initrd

Change
Repack
1
find . | cpio -o --format='newc' > ../initrd_new.img

Sunday, October 18, 2015

不从Win7/Win8.1升级,直接全新安装并激活Win10方法

http://www.mitbbs.com/article/Hardware/31885857_0.html

发信人: cym (纯爷们), 信区: Hardware
标  题: 不从Win7/Win8.1升级,直接全新安装并激活Win10方法
发信站: BBS 未名空间站 (Mon Aug 31 01:12:47 2015, 美东)

本文针对那些还没有升级Win10但是想升级的Win7/Win8.1用户。

关于Windows10系统激活,大多数用户还是想好好利用一下微软提供的免费升级途径的
。根据微软公布的升级方案以及实测,Windows7/Windows 8.1用户需要在当前系统基础
上执行升级安装才能够保证Win10安装后自动激活。也就是说, (首次激活Win10)升
级是必经之路。

但肯定有人想跳过升级,直接全新安装或安装双系统。那有没有方法在这种情况下也能
自动激活呢?

有!方法如下:

1、在你正在使用的Win7/Win8.1系统中(注意,要确保系统已经激活)打开下载的
Win10 ISO镜像,在Sources文件夹中找到gatherosstate.exe程序,把它复制到桌面。

提示:Win7系统下可使用 ultraISO / winRAR / 7Zip 软件打开ISO镜像。

2、双击gatherosstate.exe,稍后会在桌面生成名为GenuineTicket.xml的文件(名字
翻译过来就是“正版通行证”),这份文件至关重要,把它保存好。

3、然后用你熟悉的安装方法安装Win10吧。U盘法、硬盘法、光盘法,随你选。但要注
意一定要确保安装前后系统版本相对应。安装过程中跳过一切密钥输入步骤。

4、安装完成后,打开C:\ProgramData\Microsoft\Windows\ClipSVC\GenuineTicket文
件夹(注意ProgramData为隐藏文件夹),然后把保存的GenuineTicket.xml文件复制到
这个目录中。

5、重启电脑,确保系统已联网,稍后就会自动激活了。你也可以在系统属性中手动点
击“立即激活”。

以上过程执行一次即可,激活后微软服务器会记录信息,再次重装后只需联网即可自动
激活。

此方法对于升级总是失败的人会更有帮助,你可以直接选择全新安装,不用再去升级了。

Friday, October 9, 2015

EXT4: crtime, ctime, atime, mtime

EXT4 enables administrators to track file creation / access / modification.

What are they?
ctime: last file/inode change time
atime: last access time
mtime: last file modification time
crtime: creation time

How to get them?
First, get inode number
1
2
# ls -i /var/log/syslog
359 syslog

Then, with an inode number, debugfs can feedback ctime, atime, mtime, crtime
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# debugfs -R 'stat <359>' /dev/mmcblk0p1
debugfs 1.42 (29-Nov-2011)
Inode: 359   Type: regular    Mode:  0640   Flags: 0x80000
Generation: 2296437698    Version: 0x00000000:00000001
User:   101   Group:     4   Size: 8130
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 16
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x5609d80e:e110b1d4 -- Tue Sep 29 00:15:10 2015
 atime: 0x5609ca6d:db4095b4 -- Mon Sep 28 23:17:01 2015
 mtime: 0x5609d80e:e110b1d4 -- Tue Sep 29 00:15:10 2015
crtime: 0x5609ca6d:db4095b4 -- Mon Sep 28 23:17:01 2015
Size of extra inode fields: 28
EXTENTS:
(0):146512, (1):146004
(END)

Where are they?
In /include/linux/fs.h, atime, ctime, and mtime within inode structure.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
struct inode {
        umode_t                 i_mode;
        unsigned short          i_opflags;
        kuid_t                  i_uid;
        kgid_t                  i_gid;
        unsigned int            i_flags;

#ifdef CONFIG_FS_POSIX_ACL
        struct posix_acl        *i_acl;
        struct posix_acl        *i_default_acl;
#endif

        const struct inode_operations   *i_op;
        struct super_block      *i_sb;
        struct address_space    *i_mapping;

#ifdef CONFIG_SECURITY
        void                    *i_security;
#endif

        /* Stat data, not accessed from path walking */
        unsigned long           i_ino;
        /*
         * Filesystems may only read i_nlink directly.  They shall use the
         * following functions for modification:
         *
         *    (set|clear|inc|drop)_nlink
         *    inode_(inc|dec)_link_count
         */
        union {
                const unsigned int i_nlink;
                unsigned int __i_nlink;
        };
        dev_t                   i_rdev;
        loff_t                  i_size;
        struct timespec         i_atime;
        struct timespec         i_mtime;
        struct timespec         i_ctime;
        spinlock_t              i_lock; /* i_blocks, i_bytes, maybe i_size */
        unsigned short          i_bytes;
        unsigned int            i_blkbits;
        blkcnt_t                i_blocks;

#ifdef __NEED_I_SIZE_ORDERED
        seqcount_t              i_size_seqcount;
#endif

        /* Misc */
        unsigned long           i_state;
        struct mutex            i_mutex;

        unsigned long           dirtied_when;   /* jiffies of first dirtying */
        unsigned long           dirtied_time_when;

        struct hlist_node       i_hash;
        struct list_head        i_wb_list;      /* backing dev IO list */
#ifdef CONFIG_CGROUP_WRITEBACK
        struct bdi_writeback    *i_wb;          /* the associated cgroup wb */

        /* foreign inode detection, see wbc_detach_inode() */
        int                     i_wb_frn_winner;
        u16                     i_wb_frn_avg_time;
        u16                     i_wb_frn_history;
#endif
        struct list_head        i_lru;          /* inode LRU list */
        struct list_head        i_sb_list;
        union {
                struct hlist_head       i_dentry;
                struct rcu_head         i_rcu;
        };
        u64                     i_version;
        atomic_t                i_count;
        atomic_t                i_dio_count;
        atomic_t                i_writecount;
#ifdef CONFIG_IMA
        atomic_t                i_readcount; /* struct files open RO */
#endif
        const struct file_operations    *i_fop; /* former ->i_op->default_file_ops */
        struct file_lock_context        *i_flctx;
        struct address_space    i_data;
        struct list_head        i_devices;
        union {
                struct pipe_inode_info  *i_pipe;
                struct block_device     *i_bdev;
                struct cdev             *i_cdev;
                char                    *i_link;
        };

        __u32                   i_generation;

#ifdef CONFIG_FSNOTIFY
        __u32                   i_fsnotify_mask; /* all events this inode cares about */
        struct hlist_head       i_fsnotify_marks;
#endif

        void                    *i_private; /* fs or device private pointer */
};

For crtime, it is in the /fs/ext4/ext4.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
struct ext4_inode_info {
        __le32  i_data[15];     /* unconverted */
        __u32   i_dtime;
        ext4_fsblk_t    i_file_acl;

        /*
         * i_block_group is the number of the block group which contains
         * this file's inode.  Constant across the lifetime of the inode,
         * it is ued for making block allocation decisions - we try to
         * place a file's data blocks near its inode block, and new inodes
         * near to their parent directory's inode.
         */
        ext4_group_t    i_block_group;
        ext4_lblk_t     i_dir_start_lookup;
#if (BITS_PER_LONG < 64)
        unsigned long   i_state_flags;          /* Dynamic state flags */
#endif
        unsigned long   i_flags;

        /*
         * Extended attributes can be read independently of the main file
         * data. Taking i_mutex even when reading would cause contention
         * between readers of EAs and writers of regular file data, so
         * instead we synchronize on xattr_sem when reading or changing
         * EAs.
         */
        struct rw_semaphore xattr_sem;

        struct list_head i_orphan;      /* unlinked but open inodes */

        /*
         * i_disksize keeps track of what the inode size is ON DISK, not
         * in memory.  During truncate, i_size is set to the new size by
         * the VFS prior to calling ext4_truncate(), but the filesystem won't
         * set i_disksize to 0 until the truncate is actually under way.
         *
         * The intent is that i_disksize always represents the blocks which
         * are used by this file.  This allows recovery to restart truncate
         * on orphans if we crash during truncate.  We actually write i_disksize
         * into the on-disk inode when writing inodes out, instead of i_size.
         *
         * The only time when i_disksize and i_size may be different is when
         * a truncate is in progress.  The only things which change i_disksize
         * are ext4_get_block (growth) and ext4_truncate (shrinkth).
         */
        loff_t  i_disksize;

        /*
         * i_data_sem is for serialising ext4_truncate() against
         * ext4_getblock().  In the 2.4 ext2 design, great chunks of inode's
         * data tree are chopped off during truncate. We can't do that in
         * ext4 because whenever we perform intermediate commits during
         * truncate, the inode and all the metadata blocks *must* be in a
         * consistent state which allows truncation of the orphans to restart
         * during recovery.  Hence we must fix the get_block-vs-truncate race
         * by other means, so we have i_data_sem.
         */
        struct rw_semaphore i_data_sem;
        struct inode vfs_inode;
        struct jbd2_inode *jinode;

        spinlock_t i_raw_lock;  /* protects updates to the raw inode */

        /*
         * File creation time. Its function is same as that of
         * struct timespec i_{a,c,m}time in the generic inode.
         */
        struct timespec i_crtime;

        /* mballoc */
        struct list_head i_prealloc_list;
        spinlock_t i_prealloc_lock;

        /* extents status tree */
        struct ext4_es_tree i_es_tree;
        rwlock_t i_es_lock;
        struct list_head i_es_list;
        unsigned int i_es_all_nr;       /* protected by i_es_lock */
        unsigned int i_es_shk_nr;       /* protected by i_es_lock */
        ext4_lblk_t i_es_shrink_lblk;   /* Offset where we start searching for
                                           extents to shrink. Protected by
                                           i_es_lock  */

        /* ialloc */
        ext4_group_t    i_last_alloc_group;

        /* allocation reservation info for delalloc */
        /* In case of bigalloc, these refer to clusters rather than blocks */
        unsigned int i_reserved_data_blocks;
        unsigned int i_reserved_meta_blocks;
        unsigned int i_allocated_meta_blocks;
        ext4_lblk_t i_da_metadata_calc_last_lblock;
        int i_da_metadata_calc_len;

        /* on-disk additional length */
        __u16 i_extra_isize;

        /* Indicate the inline data space. */
        u16 i_inline_off;
        u16 i_inline_size;

#ifdef CONFIG_QUOTA
        /* quota space reservation, managed internally by quota code */
        qsize_t i_reserved_quota;
#endif

        /* Lock protecting lists below */
        spinlock_t i_completed_io_lock;
        /*
         * Completed IOs that need unwritten extents handling and have
         * transaction reserved
         */
        struct list_head i_rsv_conversion_list;
        /*
         * Completed IOs that need unwritten extents handling and don't have
         * transaction reserved
         */
        atomic_t i_ioend_count; /* Number of outstanding io_end structs */
        atomic_t i_unwritten; /* Nr. of inflight conversions pending */
        struct work_struct i_rsv_conversion_work;

        spinlock_t i_block_reservation_lock;

        /*
         * Transactions that contain inode's metadata needed to complete
         * fsync and fdatasync, respectively.
         */
        tid_t i_sync_tid;
        tid_t i_datasync_tid;

#ifdef CONFIG_QUOTA
        struct dquot *i_dquot[MAXQUOTAS];
#endif

        /* Precomputed uuid+inum+igen checksum for seeding inode checksums */
        __u32 i_csum_seed;

#ifdef CONFIG_EXT4_FS_ENCRYPTION
        /* Encryption params */
        struct ext4_crypt_info *i_crypt_info;
#endif
};


Sunday, October 4, 2015

Set up git server on ubuntu

On server:
1
2
3
4
5
6
sudo apt-get install git
sudo adduser git
su git
cd
mkdir .ssh && chmod 700 .ssh
touch .ssh/authorized_keys && chmod 600 .ssh/authorized_keys

On workstation:
1
2
3
sudo apt-get install git
ssh-keygen -t rsa -C "yourname@mail.com"
scp .ssh/id_rsa.pub git@gitserver:/tmp

On server:
1
2
3
4
5
6
7
sudo mkdir /opt/git
cd /opt
sudo chown git git
cd git
mkdir project.git
cd project.git
git init --bare

On workstation:
1
2
3
4
5
6
cd myproject
git init
git add .
git commit -m 'initial commit'
git remote add origin git@gitserver:/opt/git/project.git
git push origin master

On server: (prevent using git to log on)
1
2
3
4
cat /etc/shells   # see if `git-shell` is already in there.  If not...
which git-shell   # make sure git-shell is installed on your system.
sudo vim /etc/shells  # and add the path to git-shell from last command
sudo chsh git  # and enter the path to git-shell, usually: /usr/bin/git-shell


Reference:
https://git-scm.com/book/en/v2/Git-on-the-Server-Setting-Up-the-Server
https://help.ubuntu.com/lts/serverguide/git.html

Thursday, October 1, 2015

Ubuntu /etc/network/interfaces

mapping stanza
1
2
3
4
5
mapping <interface_name_glob>
 script <script_name>
 map <script_input1>
 map <script_input2>
 map ...

example configuration:
1
2
3
4
5
 auto eth0 eth1
 mapping eth0 eth1
     script /path/to/get-mac-address.sh
     map 11:22:33:44:55:66 lan
     map AA:BB:CC:DD:EE:FF internet

get-mac-address.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/bin/sh

set -e

export LANG=C

iface="$1"
mac=$(/sbin/ifconfig "$iface" | sed -n -e '/^.*HWaddr \([:[:xdigit:]]*\).*/{s//\1/;y/ABCDEF/abcdef/;p;q;}')
which=""

while read testmac scheme; do
        if [ "$which" ]; then continue; fi
        if [ "$mac" = "$(echo "$testmac" | sed -e 'y/ABCDEF/abcdef/')" ]; then which="$scheme"; fi
done

if [ "$which" ]; then echo $which; exit 0; fi
exit 1

The bold sections in the example configuration and the corresponding script show how the "map" inputs are handled.

Reference:
http://addisu.taddese.com/blog/mapping-in-linux-network-interfaces/
https://wiki.debian.org/NetworkConfiguration