Archive

Archive for the ‘Ubuntu’ Category

Enable Hibernate in Ubuntu 18.04

September 12th, 2019 No comments

Ref: https://askubuntu.com/questions/6769/hibernate-and-resume-from-a-swap-file/1132154#1132154

All credits goes to https://askubuntu.com/users/29219/anthony-o !

make it work with Ubuntu 18.04.

Make your /swapfile have at least the size of your RAM

sudo swapoff /swapfile
sudo dd if=/dev/zero of=/swapfile bs=$(cat /proc/meminfo | grep MemTotal | grep -oh '[0-9]*') count=1024 conv=notrun
sudo mkswap /swapfile
sudo swapon /swapfile

Note the UUID of the partition containing your /swapfile:

$ sudo findmnt -no SOURCE,UUID -T /swapfile
/dev/nvme0n1p5 20562a02-cfa6-42e0-bb9f-5e936ea763d0

Reconfigure the package uswsusp in order to correctly use the swapfile:

sudo dpkg-reconfigure -pmedium uswsusp
# Answer "Yes" to continue without swap space
# Select "/dev/disk/by-uuid/20562a02-cfa6-42e0-bb9f-5e936ea763d0" replace the UUID with the result from the previous findmnt command
# Encrypt: "No"

Edit the SystemD hibernate service using sudo systemctl edit systemd-hibernate.service and fill it with the following content:

[Service]
ExecStart=
ExecStartPre=-/bin/run-parts -v -a pre /lib/systemd/system-sleep
ExecStart=/usr/sbin/s2disk
ExecStartPost=-/bin/run-parts -v --reverse -a post /lib/systemd/system-sleep

Note the resume offset of your /swapfile:

$ sudo swap-offset /swapfile
resume offset = 34818

Configure Grub to resume from the swapfile by editing /etc/default/grub and modify the following line:

GRUB_CMDLINE_LINUX_DEFAULT="resume=UUID=20562a02-cfa6-42e0-bb9f-5e936ea763d0 resume_offset=34818 quiet splash"

Update Grub:

sudo update-grub

Update initramfs: sudo update-initramfs -u -k all

Create the following /etc/initramfs-tools/conf.d/resume:

RESUME=UUID=20562a02-cfa6-42e0-bb9e-5e936ea763d0 resume_offset=34816
# Resume from /swapfile

Update initramfs:

sudo update-initramfs -u -k all

Now you can hibernate with sudo systemctl hibernate.

One can also create those scripts:

    sudo tee /usr/local/bin/gotosleep <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo /usr/sbin/s2both
    EOF
    sudo chmod +x /usr/local/bin/gotosleep
    sudo tee /usr/local/bin/gotohibernation <<EOF
    dbus-send --type=method_call --dest=org.gnome.ScreenSaver /org/gnome/ScreenSaver org.gnome.ScreenSaver.Lock
    sleep 2
    sudo systemctl hibernate
    EOF
    sudo chmod +x /usr/local/bin/gotohibernation

So you can sleep with gotosleep or hibernate with gotohibernation.

You must be able to execute sudo s2both, sudo s2ram and sudo systemctl hibernatewithout having to enter your password for the previous scripts to work.

You could do that for example by creating a powerdev group, add your current user to it, and configure the following sudoers config (edit it with sudo visudo -f /etc/sudoers.d/powerdev):

     %powerdev ALL=NOPASSWD: /usr/sbin/s2both, /usr/sbin/s2ram, /bin/systemctl hibernate

Documentation used:

Add ‘Hibernate’ Option in Power Menu in Ubuntu 18.04

Ref: http://ubuntuhandbook.org/index.php/2018/05/add-hibernate-option-ubuntu-18-04/

sudo gedit /etc/polkit-1/localauthority/50-local.d/com.ubuntu.enable-hibernate.pkla

When the file opens, paste following content and save it.

[Re-enable hibernate by default in upower]
Identity=unix-user:*
Action=org.freedesktop.upower.hibernate
ResultActive=yes

[Re-enable hibernate by default in logind]
Identity=unix-user:*
Action=org.freedesktop.login1.hibernate;org.freedesktop.login1.handle-hibernate-key;org.freedesktop.login1;org.freedesktop.login1.hibernate-multiple-sessions;org.freedesktop.login1.hibernate-ignore-inhibit
ResultActive=yes

Install the Gnome connector:

sudo apt-get install chrome-gnome-shell

Open Firefox, press CTRL+SHIFT+a, and install the “GNOME Shell integration” Add-On. Link to the add-on: https://addons.mozilla.org/en-US/firefox/addon/gnome-shell-integration/?src=search

Go to https://extensions.gnome.org/ and search for “Hibernate Status Button“, or click this link: https://extensions.gnome.org/extension/755/hibernate-status-button/. Turn “ON” the extension in the upper right corner.

Restart your computer and enjoy the new hibernate-button in the shut-down dialog!

For those who never installed a gnome extension, see this how to tutorial for details.

Categories: Bash, Linux, Ubuntu Tags:

How to Change Lid Close Action in Ubuntu 18.04 LTS

September 5th, 2019 No comments

Open terminal by pressing Ctrl+Alt+T or searching for “Terminal” from start menu. When it opens, run command:

sudo gedit /etc/systemd/logind.conf

When the files opens, uncomment the line #HandleLidSwitch=suspend by removing # in the beginning, and change the value to:

  • HandleLidSwitch=poweroff, shutdown / power off when lid is closed.
  • HandleLidSwitch=hibernate, hibernate when lid is closed (need to test if hibernate works).
  • HandleLidSwitch=ignore, do nothing.
  • HandleLidSwitch=suspend, suspend laptop when lid is closed.

Save the file and finally restart the Systemd service to apply changes via command:

systemctl restart systemd-logind.service
Categories: Bash, Linux, Ubuntu Tags:

Reboot linux at specific time

August 13th, 2019 No comments

Sometimes you want to reboot a server in the middle of the night. With linux it’s as simple as this command:

shutdown -r 04:00

Which will reboot the machine at 4 am in the morning. If you need to abort the reboot, use the following to abort the reboot:

shutdown -c
Categories: Bash, Linux, Red Hat / CentOS, Ubuntu Tags:

Mount exFAT in Ubuntu 18.04

August 8th, 2019 No comments

The exFAT file system is created by Microsoft to overcome the 4GB file size limit in FAT. To mount such an partition you need to enable exFAT. Otherwise you’ll get an error saying can’t mount unknown filesystem type “exfat”. In Ubuntu 18.04 it’s simple, just open a terminal and type:

sudo apt install exfat-fuse exfat-utils

If this doesn’t work you might need to add the “universe” repository first. Here’s an example followed by a mount of the device at /dev/sdb1. Replace this device with your own device:

sudo add-apt-repository universe
sudo apt update
sudo apt install exfat-fuse exfat-utils
sudo mkdir /mnt/myEXFAT
sudo mount /dev/sdb1 /mnt/myEXFAT

To list devices and their partitions, use the command:

sudo parted -l

Beware that exFAT can’t handle certain characters in the file names, like “:”. If you need to rename multiple file names you can modify the below example that replaces all “:”-characters with an underscore “_” in the current directory:

find . -depth -maxdepth 1 -name '*:*' -execdir bash -c 'mv -- "$1" "${1//:/_}"' bash {} \;

Categories: Bash, Linux, Ubuntu Tags:

Upgrade Ubuntu Linux using command line

August 6th, 2019 No comments

To upgrade Ubuntu Linux open up a terminal and type:

do-release-upgrade

The old way using apt isn’t needed in Ubuntu to upgrade the system. dist-upgrade has been superseded in Ubuntu by full-upgrade.

The do-release-upgrade command can be run as an user with admin rights without sudo. The user password will be asked when starting the command. The system will then make different checks before the upgrade starts. If using SSH an additional port will be opened on port 1022 that can be used if the ordinary SSH-tunnel are broken during the update.

Categories: Bash, Linux, Ubuntu Tags:

Prepare Linux for source compile

August 11th, 2012 No comments

1. Install packages to build the kernel modules

sudo apt-get install autoconf automake binutils make cpp gcc linux-headers-$(uname -r)

2. Find out where the kernel headers are (you may need this later)

ls -d /usr/src/linux-headers-$(uname -r)*/include

i.e. /usr/src/linux-headers-2.6.31-14-generic-pae/include

i.e. /lib/modules/2.6.31-14-generic-pae/build/include

3. Get the kernel source

sudo apt-get build-dep linux-image-$(uname -r)

sudo apt-get source linux-image-$(uname -r)

Categories: Bash, Linux, Programmering, Ubuntu Tags:

A faster and safer Firefox experience

August 11th, 2012 No comments

Here are a few tips to make your Mozilla Firefox experience faster, safer and more private. Most “average” users might not bother with these, but the more discerning types will find them helpful.

1. Install the following Firefox extensions – NoScript, Ghostery, Adblock Plus, OptimizeGoogle.

2. Type “about:config” (no quotes) in the address bar.

Toggle network.http.pipelining to “true”.

Toggle network.http.proxy.pipelining to “true”.

Then set integer value for network.http.pipelining.maxrequests to 40.

Right-click anywhere that’s blank on the page and then create a new item called “nglayout.initialpaint.delay” and set its integer value to 0 (zero)

The Ghostery extension will allow you to selectively block hidden data-gathering activities such as traffic-ranking, click-throughs and such stuff like that, which can monitor what you do on the net. Some of that stuff is probably harmless but slows down your browsing experience during its data-gathering phase. The other extension recommendations are well-known as to what they do.

Categories: Ubuntu, Windows Tags:

Installera Java 7 i Ubuntu x64

August 9th, 2012 No comments

Install Java JRE in Ubuntu x64:

http://askubuntu.com/questions/56104/how-can-i-install-oracle-java-jre-7

Firefox Java plugin installation in Kubuntu x64:

1. Download Java from Oracle/Sun, unpack.

2. cd /usr/lib/mozilla/plugins

3. sudo ln -s /home/user/Downloads/jre1.6.0_29/lib/amd64/libnpjp2.so

Categories: Linux, Ubuntu Tags:

Download gscan2pdf source and run

May 9th, 2012 No comments

THIS IS ONLY A DRAFT!!!

http://gscan2pdf.sourceforge.net/

Ladda ner koden:

cd ~/code
git clone git://gscan2pdf.git.sourceforge.net/gitroot/gscan2pdf/gscan2pdf

Skapa en länk så Perl hittar filerna:

sudo mkdir /usr/local/lib/perl
cd /usr/local/lib/perl
sudo ln -s /home/holm/code/gscan2pdf/lib 5.12.4

Starta programmet:

/home/holm/code/gscan2pdf/bin/gscan2pdf

// Tobias 2012-01-01

_____________________________________________________________

Install gscan2pdf from Ubuntu repositories to get most of the dependencies:

$ sudo apt-get install gscan2pdf git libsane-dev libcanberra-gtk-module

You might get the following packages when installing gscan2pdf:

Följande NYA paket kommer att installeras:
cuneiform cuneiform-common gocr gscan2pdf libconfig-general-perl libcuneiform0 libextutils-depends-perl libextutils-pkgconfig-perl libfont-ttf-perl libgoo-canvas-perl libgtk2-ex-podviewer-perl libgtk2-ex-simple-list-perl libgtk2-imageview-perl libgtkimageview0 libio-stringy-perl libjpeg-progs libjpeg-turbo-progs libleptonica liblog-log4perl-perl libpdf-api2-perl libproc-processtable-perl libreadonly-perl libset-intspan-perl libtesseract3 libtiff-tools libwebp2 perlmagick tesseract-ocr tesseract-ocr-eng tesseract-ocr-equ tesseract-ocr-osd

Download the source via git:

$ git clone git://gscan2pdf.git.sourceforge.net/gitroot/gscan2pdf/gscan2pdf

Enter the directory. If you try to run it you can get this error:

$ bin/gscan2pdf
 Can't locate Gscan2pdf/Document.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.12.4 /usr/local/share/perl/5.12.4 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.12 /usr/share/perl/5.12 /usr/local/lib/site_perl .) at bin/gscan2pdf line 121.                                      
 BEGIN failed--compilation aborted at bin/gscan2pdf line 121.

This is because the Perl script can’t find some libraries. To solve it, add the following at the top of bin/gscan2pdf:

# ADDED BY TOBIAS HOLM 2012-05-12 (TO FIND LIBS)
use lib "/home/holm/code/gscan2pdf/lib/";

This is another problem you can bump into:

$ bin/gscan2pdf
 Sane version 0.05 required--this is only version 0.03 at /etc/perl/Gscan2pdf/Scanner/Options.pm line 7.
 BEGIN failed--compilation aborted at /etc/perl/Gscan2pdf/Scanner/Options.pm line 7.
 Compilation failed in require at /etc/perl/Gscan2pdf/Document.pm line 7.
 BEGIN failed--compilation aborted at /etc/perl/Gscan2pdf/Document.pm line 7.
 Compilation failed in require at bin/gscan2pdf line 121.
 BEGIN failed--compilation aborted at bin/gscan2pdf line 121.

To fix it, download Sane version 0.05: https://metacpan.org/module/Sane

Enter the folder where you downloaded the files and try to install Sane:

$ perl Makefile.PL
 Perhaps you should add the directory containing `sane-backends.pc'
 to the PKG_CONFIG_PATH environment variable
 No package 'sane-backends' found at Makefile.PL line 21
 Writing Makefile for Sane
 Writing MYMETA.yml

Ops! Install sane-backends components:

$ sudo apt-get install libsane-dev

Now compile Sane:

$ perl Makefile.PL
$ make
$ make test
$ sudo make install

Enter gscan2pdf folder and run the program:

$ cd ../gscan2pdf
$ bin/gscan2pdf

This is another error:

$ bin/gscan2pdf 
Bareword "Gscan2pdf::_cancel_process" not allowed while "strict subs" in use at /etc/perl/Gscan2pdf/Document.pm line 595.
Compilation failed in require at bin/gscan2pdf line 54.
BEGIN failed--compilation aborted at bin/gscan2pdf line 54.

Fix it by manually cleaning up a previous installation of Gscan2pdf.

sudo apt-get remove gscan2pdf
sudo rm -rf /etc/perl/Gscan2pdf
Categories: Bash, Linux, Ubuntu Tags:

Standard Client Ubuntu 10.10/11.04/11.10

May 6th, 2011 No comments

This is the steps I use to configure a new Ubuntu client:

  • Install Ubuntu from USB/CD/PXE

Then add the following programs in the Program Central:

  • Chromium
  • GIMP
  • gscan2pdf
  • PDF Editor
  • Thunderbird
  • Filezilla
  • KVpnc
  • Pidgin
  • Remmina
  • Wireshark
  • XChat IRC
  • Zenmap
  • tn5250
  • Audacity
  • Desktop recorder
  • GNOME MPlayer
  • ISO Master
  • VLC
  • MuseScore
  • OpenShot Video Editor
  • UNetbootin
  • Filelight
  • TrueCrypt
  • Wine + Spotify
  • apt-get packages to source compile ffmpeg

Install the following programs from different sources (Google 😉 )

sudo add-apt-repository ppa:dockbar-main/ppa
sudo apt-get update && sudo apt-get install dockbarx
sudo apt-get install dockbarx-themes-extra

  • Synergy (http://synergy-foss.org/download)
  • BankID (in 64-bit Linux: sudo apt-get install nspluginwrapper && sudo nspluginwrapper -i /usr/local/lib/personal/libplugins.so)

After this it’s time to restore my home folder from a backup.

Files to manually restore:

  • /etc/X11/xorg.conf
sudo nvidia-xconfig --post-tree --twinview

Ref: http://manpages.ubuntu.com/manpages/lucid/man1/alt-nvidia-current-xconfig.1.html

Configs to manually restore:

  • Compiz config, effects
  • X key bindings (Super+Up=Maximize vertically, Super=ScrClip)
  • Startup programs (Synergy)
  • add NAS to fstab
  • crontab (Backup once every hour to NAS + SD-card)
  • crontab for root (apt-get autoclean = free space in /var/cache/apt/archives)
  • Ubuntu One
  • Network printers (DeskJet 970, CLJ2600)

Add link support in Firefox for Second Life:

  • Type about:config in Firefox address field
  • Right-click any item in the list and select New > Boolean
  • Type: network.protocol-handler.external.secondlife
  • Set the value to true. This tells Firefox to use an external program to handle the secondlife:// protocol
  • Right-click any item in the list and select New > String
  • Type: network.protocol-handler.app.secondlife
  • Type the path to the program you want to use for that protocol (e.g. /home/holm/dump/SecondLife-i686-2.6.3.227447/secondlife )

Add the Q700 (TS-219P) printer: smb://nas/naspr2

To enable OpenShot x264 you must install unrestricted codecs:

Install support for CSS encrypted DVD movies:

  • sudo apt-get install libdvdread4
  • sudo /usr/share/doc/libdvdread4/install-css.sh
    Rebooting may be necessary.

Install Java plugin in Firefox (Kubuntu x64):

  • Download Java from Oracle/Sun, unpack bin-file (first set x-flag)
  • cd /usr/lib/mozilla/plugins
  • sudo ln -s /home/user/Downloads/jre1.6.0_29/lib/amd64/libnpjp2.so

If you have a folder with scripts you can add it to the path:

  • Edit the file “~/.profile” and add the path.

Disable Overlay Scrollbars in Ubuntu Natty:

  • echo “export LIBOVERLAY_SCROLLBAR=0” | sudo tee /etc/X11/Xsession.d/80overlayscrollbars> /dev/null
  • Or remove the whole package: sudo apt-get remove overlay-scrollbar

Restore debconf backup

According to section 6.4.9 (http://www.debian.org/doc/manuals/reference/ch-package.en.html#s-record) of the Debian Reference Manual (http://www.debian.org/doc/manuals/reference/), the following will save both the list of packages installed and their debconf configuration:

# dpkg –get-selections “*” >myselections # or use \*
# debconf-get-selections > debconfsel.txt

and the following will reinstall and reconfigure them:

# dselect update
# debconf-set-selections < debconfsel.txt
# dpkg –set-selections <myselections
# apt-get -u dselect-upgrade # or dselect install

Categories: Linux, Ubuntu Tags: