Convert your Ubuntu/Debian between different versions, like Desktop to Server

There is a very useful tool under Debian/Ubuntu GNU/Linux called tasksel, which can help us “convert” our Debian/Ubuntu between versions.

Install via apt-get/aptitude:

[email protected] ~ $ sudo apt-get install tasksel
[sudo] password for peter:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following extra packages will be installed:
tasksel-data
The following NEW packages will be installed:
tasksel tasksel-data
0 upgraded, 2 newly installed, 0 to remove and 46 not upgraded.
Need to get 36.0 kB of archives.
After this operation, 385 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://ubuntu.mirror/ubuntu/ trusty/main tasksel-data all 2.88ubuntu15 [6,366 B]
Get:2 http://ubuntu.mirror/ubuntu/ trusty/main tasksel all 2.88ubuntu15 [29.7 kB]
Fetched 36.0 kB in 0s (363 kB/s)
Preconfiguring packages ...
Selecting previously unselected package tasksel-data.
(Reading database ... 229261 files and directories currently installed.)
Preparing to unpack .../tasksel-data_2.88ubuntu15_all.deb ...
Unpacking tasksel-data (2.88ubuntu15) ...
Selecting previously unselected package tasksel.
Preparing to unpack .../tasksel_2.88ubuntu15_all.deb ...
Unpacking tasksel (2.88ubuntu15) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for menu (2.1.46ubuntu1) ...
Setting up tasksel-data (2.88ubuntu15) ...
Setting up tasksel (2.88ubuntu15) ...
Processing triggers for menu (2.1.46ubuntu1) ...

and run:

[email protected] ~ $ sudo tasksel

It’ll show you a menu like this:

tasksel_menu
閱讀全文

Remotely shutdown/restart Windows via Linux on Debian/Ubuntu based Linux

Need samba-common package first, install via apt:

$ sudo apt-get install samba-common

Then use this command to shutdown the computer remotely(replace ip, username and password with your own):

$ net rpc shutdown --ipaddress ip --user username%password

Add -r if you want to restart, not shutdown:

$ net rpc shutdown -r --ipaddress ip --user username%password

After execution, here is the success message:

Shutdown of remote machine succeeded

If receive these messages below means something failed:

Could not connect to server 192.168.1.55
Connection failed: NT_STATUS_IO_TIMEOUT
Connection failed: NT_STATUS_RESOURCE_NAME_NOT_FOUND
Could not initialise pipe winreg. Error was NT_STATUS_OBJECT_NAME_NOT_FOUND

There are many functions provide by net [rpc], like:

net rpc audit Modify global audit settings
net rpc info Show basic info about a domain
net rpc join Join a domain
net rpc oldjoin Join a domain created in server manager
net rpc testjoin Test that a join is valid
net rpc user List/modify users
net rpc password Change a user password
net rpc group List/modify groups
net rpc share List/modify shares
net rpc file List open files
net rpc printer List/modify printers
net rpc changetrustpw Change trust account password
net rpc trustdom Modify domain trusts
net rpc abortshutdown Abort a remote shutdown
net rpc shutdown Shutdown a remote server
net rpc samdump Dump SAM data of remote NT PDC
net rpc vampire Sync a remote NT PDC’s data into local passdb
net rpc getsid Fetch the domain sid into local secrets.tdb
net rpc rights Manage privileges assigned to SID
net rpc service Start/stop/query remote services
net rpc registry Manage registry hives
net rpc shell Open interactive shell on remote server
net rpc trust Manage trusts
net rpc conf Configure a remote samba server

Check man rpc for more details!

Convert ext3 to ext4 filesystem on Debian Wheezy

老調重彈了,最近又再做這件事是因為Proxmox VE預設是用ext3當作檔案系統,某一台機器因為有點問題,灌Proxmox的時候一開始沒打算要當正式系統,也就沒特別改設定,但灌好後因為懶了 … 就直接上線了 … 偶然發現這個問題,順便重新作一下筆記怎麼樣轉到ext4,轉到ext4的好處以及效能差異就不用多說了,幾乎是完剩ext2、ext3,好檔案系統,不轉嗎?

如果懶的話,最簡單的方法就是去改fstab,直接把ext3掛成ext4,效能就可以有所提升,但只能使用到那些不需要修改到檔案系統的功能,並且可以重新用ext3的方式掛載,而要有比較完整的轉換則要做以下動作:

  1. 把要做轉換的分區umount(如果是root filesystem就進single user mode或用其他系統開機吧),DEV自行替換成對應代號
    # umount /dev/DEV

  2. 先做一次fsck
    # e2fsck -fyv /dev/DEV

  3. 沒問題的話就可以把ext4的功能打開了,這邊要注意 … 這是不可逆的操作,並且要和下個動作連貫完成
    # tune2fs -O extents,uninit_bg,dir_index /dev/DEV

  4. 調整完後要修一下(這邊會看到找到錯誤是正常現象)
    # e2fsck -fyvDC0 /dev/DEV

  5. 調整fstab的掛載格式
    -> 自己去fstab理面把該分區的ext3改成ext4吧!

  6. 重組
    # e4defrag -c -v /dev/DEV
    -> ext4開始使用extents來取代傳統的block mapping,在對大檔案操作時能有顯著的效能提升,而這部份是在剛剛的轉換沒有做的(tuen2fs只有把feature打開而以),轉換完成後新增的檔案自然是都會使用到這樣的功能,但原先已經存在於filesystem上的檔案必須要到下次被寫入時才會以新的方式寫入,但系統上有不少檔案是久久才會寫一次但可能經常要被讀取的,在被重新寫入以前便無法享受到這樣的效能改善,所以這邊透過e4defrag來幫我們做這件事!

過程中如果有出現錯誤的話就先解掉再往下一步走,像fsck這種工作做完一次還可以做第二次確保都沒問題了再往下走,過程並不複雜,剛好也可以順便檢查檔案系統有沒有問題,比較麻煩的大概就是root filesystem因為要unmount所以系統必須停機,但換來的效能是值得的!

(我之前硬碟壞掉就會出現fsck永遠修不完的現象,每次抓到的錯誤都不一樣,修完一次下次還是有得修,那很明顯是硬碟壞了)

Got error from Apache after upgraded Debian to Jessie (8.x)

I upgraded my Debian server to Jessie yesterday, due to I didn’t update all the configs, I found some errors, and got to fix them.

Error message:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 89 of /etc/apache2/apache2.conf:
Invalid command ‘LockFile’, perhaps misspelled or defined by a module not included in the server
configuration
Action ‘configtest’ failed.
The Apache error log may have more information.

Solution:

Edit /etc/apache2/apache2.conf, replace line 89:
LockFile ${APACHE_LOCK_DIR}/accept.lock
with this line:
Mutex file:${APACHE_LOCK_DIR} default

Another error:

Starting web server: apache2 failed!
The apache2 configtest failed. … (warning).
Output of config test was:
AH00526: Syntax error on line 17 of /etc/apache2/sites-enabled/000-default.conf:
Either all Options must start with + or -, or no Option may.

Action ‘configtest’ failed.
The Apache error log may have more information.

So just add symbol + for the options without prefix symbol and it works again.