Showing posts with label ubuntu. Show all posts
Showing posts with label ubuntu. Show all posts

Tuesday, October 12, 2021

How to clone Ubuntu OS partition?

I'm using Macbook Pro 13-inch Late 2011 running Ubuntu 20.04. I used the built-in application called Disks to backup the Ubuntu system partition into a disk image (*.img file) and then restore the disk image back to the partition.

IMPORTANT 

  • When backing up a system partition, the EFI system partition should also be backed up if it exists (using either Disks application or cp command)
  • The backed up or source partition must be smaller than or equal to the destination partition
  • The size of the disk image (*.img file) equals the size of the (backed up) source partition even if the partition has free space. The source partition should be resized as small as possible so that the resulting disk image is acceptably small.


To Backup

Backing up Ubuntu partition:

  • Boot into Ubuntu Live (on USB) and chose Try Ubuntu
  • Open Disks application from the menu (press Windows key and type Disks)
  • Select the partition to backup 

  • (Optional) Click on the settings icon for more options and select Resize
  • Click on the settings icon for more options then select Create Partition Image...

  • Make sure the file name and location are correct. The partition for storing the disk image must be mounted or it'll fail with a message like there is not enough space or something else confusing.

Backing up EFI system partition:

The EFI system partition is where the Ubuntu bootloader locates in because I manually chose the partition for the bootloader while installing Ubuntu (It's a must to install Ubuntu using EFI mode).

I used the method above to clone (backup) this partition, and also manually copied its content using cp command. Of course, using cp command is simpler and works just fine. The partition has only one directory named EFI.

> sudo mkdir /mnt/sda1
> sudo mount -o loop /dev/sda1 /mnt/sda1
> sudo cp -rf /mnt/sda1/EFI /media/myusb/ubuntu-efi/


To Restore

Restoring Ubuntu partition:

  • Boot into Ubuntu Live (on USB) and click Try Ubuntu
  • Open Disks application from the menu
  • Select the (destination) partition for running Ubuntu 

  • Click on the settings icon for more options and select Restore Partition Image...

  • Browse to the (source) partition that the disk image (*.img file) is stored on

  • Select the disk image file and click Start Restoring

Restoring EFI system partition:

I opened Terminal and used the cp command to copy it back from the USB drive to the EFI system partition (in my case, /dev/sda1). 

> sudo mkdir /mnt/sda1     
> sudo mount -o loop /dev/sda1 /mnt/sda1    
> sudo cp -rf /media/myusb/ubuntu-efi/EFI/ubuntu /mnt/sda1/EFI/
> sudo cp -rf /media/myusb/ubuntu-efi/EFI/BOOT /mnt/sda1/EFI/


Successfully Tested Scenarios

Scenario 1 

  1. Create a virtual machine and install Ubuntu with VirtualBox, enabling EFI mode
  2. - Partition 1: 500 MB (EFI system)
    - Partition 2: 50 GB (FAT32 - empty)
    - Partition 3: 200 GB (NTFS - empty)
    - Partition 4: 40 GB (EXT4 - Ubuntu)
  3. Reboot into Ubuntu Live through a virtual CD-ROM attached with the Ubuntu installation ISO file and choose Try Ubuntu
  4. Open Disks application from the menu and use it to backup Partition 4 (Ubuntu system partition) to a disk image (*.img file) stored on Partition 3.
  5. Restore the disk image file to Partition 2
  6. Format and erase Partition 4
  7. Optional: backup Partition 1 to a disk image stored on Partition 3
  8. Close the virtual machine and start it again

Scenario 2

  1. Boot into Recovery mode on MacBook Pro Late 2011
  2. Create the following partitions:
  3. - Partition 1: 70 GB (Mac OS Extended)
    - Partition 2: 100 GB (exFAT)
    - Partition 3: 90 GB (FAT 32)
    - Partition 4: 200 GB (exFAT)
  4. Install macOS High Sierra on Partition 1 
  5. Install Ubuntu 20.04 on Partition 3 (formatted as ext4)
  6. Boot into Ubuntu Live USB and choose Try Ubuntu
  7. Open Disks application from the menu
  8. Format Partition 4 as NTFS
  9. Optional: resize Partition 3 to 20 GB (leaving 70 GB of free space)
  10. Backup Partition 3 (Ubuntu) as a disk image (*.img file) and store it on Partition 4 
  11. Format and erase Partition 3 (this can also be done in macOS)
  12. Restore the disk image from Partition 4 to Partition 3
  13. Reboot the machine


Monday, October 11, 2021

Setting environment variables on Ubuntu

Example

export JAVA_HOME=/usr/local/jdk-15.0.2
export PATH="$PATH:$JAVA_HOME/bin"

Without the export command, the variables are just shell variables; it means they aren't recognized by the sub processes or programs that start from the shell. 


Login shell vs non-login shell

A shell in Unix is a program that provides command line interface for OS and user interaction. The Terminal application is just an emulator or GUI for a shell.

Login shell - ssh is an example.

Non-login shell - the Terminal application by default starts a non-login shell but inherits the user environment variablbes loaded from the graphical login shell.


Session-wide environment variables

It affects only specific user.

The ~/.profile file

Each user has its own .profile file. It gets executed by the DisplayManager when the desktop session loads as well as by the login shell when one logs in from the textual console.

The ~/.profile file is not automatically executed by just restarting the Terminal application because it's not a login shell. For the file modification to take effect, logout the user account and login again.


System-wide environment variables

It affects the system as a whole (rather than just a specific user). 

The /etc/environment file

The downside is variables do not expand. In the example below, the PATH variable would end up containing only "/bin" because $PATH and $JAVA_HOME don't get replaced with their values.

export JAVA_HOME=/usr/local/jdk-15.0.2
export PATH="$PATH:$JAVA_HOME/bin"

The /etc/profile & /etc/profile.d/*.sh files

The /etc/profile is often used for setting system-wide environment variables but it is a configuration file so it's inappropriate to edit that file. The /etc/profile.d directory should be used instead. It (and any sh files inside) get executed whenever a bash login shell is entered (e.g. when logging in from the console or over ssh), as well as by the DisplayManager when the desktop session loads. 

For example, create the /etc/profile.d/myvars.sh file and set the variables as followings:

export JAVA_HOME=/usr/local/jdk-15.0.2
export PATH="$PATH:$JAVA_HOME/bin"



Thursday, October 7, 2021

WiFi is not working on a fresh-install Ubuntu 20.04

I'm using Macbook Pro Late 2011 to install Ubuntu 20.04 on it. WiFi was working fine when trying Ubuntu from Live USB, but it wasn't after the installation. I couldn't find the WiFi adapter in Network settings.

First, when I opened Software & Updates > Additional Drivers, I saw:

Broadcom Inc. and subsidaries: BCM4331 802. 11a/b/g/n (AirPort Extreme)

The option Do not use the device  below it was checked and then I check another option to use the device and clicked Apply Changes but failed.

Second, I mounted the Ubuntu installation ISO file as a CD-ROM (using commands in Terminal) then opened Software & Updates again and selected Ubuntu Software tab. Under Installable from CD-ROM/DVD label, I checked Cdrom with Ubuntu 20.04 then repeat the first step but still no luck.

The solution below (that I copied from here) worked. 

1. Extract the Ubuntu installation ISO file (ubuntu-20.04.*.iso) to ~/Downloads folder then open Terminal and run:
> sudo chmod -R 777 ~/Downloads/ubuntu-20.04.*

2. Find the broadcom firmware on another machine:
- Download broadcom-wl-6.30.163.46.tar.bz2 (or later) from here or my backup.
- Extract it to ~/Downloads folder

3. Run the following commands in Terminal:

> cd ubuntu-20.04.*/
> sudo dpkg -i ./pool/main/b/b43-fwcutter/b43-fwcutter_019-4_amd64.deb

> cd ~/Downloads/broadcom-wl-6.30.163.46
> sudo b43-fwcutter -w /lib/firmware broadcom-wl-6.30.163.46.wl_apsta.o
 
> sync
> sudo modprobe -r b43 
> sudo modprobe b43 

4. Check the Network settings again and the WiFI icon should appear.




Wednesday, November 30, 2016

Create Clonezilla Live Partition (not a whole USB drive)

I used Tuxboot from within Ubuntu to create Clonezilla Live USB drive. Then, I have an external hard disk drive with multiple partitions. I used Disk Utility in Mac OSX Lion to clone the Clonezilla Live USB drive to one of the partitions but it failed.

Then, I used Carbon Copy Cloner to clone the entire USB drive to the partition instead and it worked.

Thursday, April 21, 2016

Configuring Ubuntu 15.04 on Macbook Pro 13 Inch Late 2011

Most of things work out of the box for Ubuntu 15 on Macbook Pro but there are still something you have to fix.

Keyboard backlight is reset to maximum every time I reboot


Put the following command in /etc/rc.local file just before 'exit 0':
chmod 777 /sys/class/leds/smc::kbd_backlight/brightness
Then add the following command in /etc/profile file:
echo 0 | tee /sys/class/leds/smc::kbd_backlight/brightness

Note that we can just put the second command in /etc/rc.local and it should work but I don't know why the content of the file is reset back when I enter the login screen every reboot.

Reverse function keys


To use 'fn' key in combination with function keys to turn on or off volume for example, you must put the following command in /etc/rc.local just before 'exit 0':
chmod 777 /sys/module/hid_apple/parameters/fnmode
Then, add the following command in /etc/profile file:
echo 2 | tee /sys/module/hid_apple/parameters/fnmode

Trackpad


For drag and drop, just use your index finger to click and hold the trackpad and move your middle finger for dragging.

In my case, 3-finger tap for making middle click does not work so I have to configure it in the default synaptics driver settings. You can use synclient program to make the real-time change to the settings but just temporarily.
synclient TapButton1=1
synclient TapButton2=3
synclient TapButton3=2
synclient ClickFinger3=2
1, 2, and 3 mean left, middle, and right buttons respectively. To make permanent change, you can put those commands in a script file, /usr/share/mysynclients.sh for example and then add it to Startup Application. Or you can try to modify xorg.conf file but it made palm detection not work well. However, if you want to do it, you can put the following codes in /usr/share/X11/xorg.conf.d/50-synaptics.conf file as following:
Section "InputClass"
        Identifier "Default clickpad buttons"
        MatchDriver "synaptics"
        Option "SoftButtonAreas" "50% 0 82% 0 0 0 0 0"
        Option "SecondarySoftButtonAreas" "58% 0 0 15% 42% 58% 0 15%"
        Option "TapButton1" "1"
        Option "TapButton2" "3"
        Option "TapButton3" "2"
EndSection
But, it might not work as the Gnome setting daemon in /etc/X11/xorg.conf file will override existing settings in /usr/share/X11/xorg.conf.d/50-synaptics.conf. You can fix it by:
> sudo apt-get install dconf-editor
> dconf-editor
And then, browse to /org/gnome/settings-daemon/plugins/mouse/ (or /org/cinnamon/settings-daemon/plugins/mouse/ for cinnamon) in the editor and uncheck Active checkbox. Then, reboot.

Disable locked drags
synclient TapAndDragGesture=OFF

Sensors (Fan)


coretemp allows lm-sensor detect the other sensors such as the rotation speed of the fan and the GPU temperature. Typing the following command will activate the coretemp in next reboot:
sudo modprobe coretemp
You should use fan controller daemon included in the mactel-support ppa called macfanctl.
sudo add-apt-repository ppa:mactel-support/ppa 
sudo apt-get update
sudo apt-get install macfanctld

You can change the minimum fan speed in this file /etc/macfanctl.conf.

Others

For more configurations for such as battery saving (or you can install indicator-cpufreq), go read this.



Related Articles:
http://myt8chnote.blogspot.com/2016/04/installing-ubuntu-on-macbook-pro-using.html

Saturday, April 9, 2016

How I backup/clone all drives of my Macbook Pro

I'm running OS X Lion v10.7 on Macbook Pro 13 inch late 2011. I have installed 3 operating systems on it such as Mac OS X Lion, Windows 7, and Ubuntu 15.04. To avoid problems in the future such as disk failure, I have backup my drive as following:

1. Mac OS X Lion is my primary OS and I use Carbon Copy Cloner to clone the partition to external hard disk drive so I can boot OS X from the external HDD any time to restore the partition.

2. To backup and restore Windows 7, I must do it from within OS X using Winclone app version 4.x.

3. For Ubuntu, I used Clonezilla to backup/restore the partition it was installed on to/from image files. I installed Clonezilla Live on a USB drive so that I can boot into Clonezilla from that USB by not depending on any operating systems. According to Clonezilla's official website, I made the bootable USB on Ubuntu using Tuxboot program. There are 2 methods to make a Clonezilla live USB by Tuxboot, online (downloading) and offline (ISO file). I used the online method in which Tuxboot downloaded the latest Clonezilla live for me and wrote it to my USB drive.

I think I should use only Clonezilla to backup/restore all partitions of my Macbook Pro.


Installing Ubuntu on Macbook Pro using bootable USB stick

I'm using Macbook Pro 13 inch late 2011 and I have just installed Ubuntu 15.04 on it successfully using a bootable USB stick. I followed this post http://www.ubuntu.com/download/desktop/create-a-usb-stick-on-mac-osx to make a bootable USB stick. When restarting machine, I hold option key until I see an option to boot from the USB drive. Surprisingly, it worked only for Ubuntu 15.04 ISO file I downloaded from Ubuntu's web site. For other previous versions such as 10.04 and 11.10, the USB drive is not bootable at all (it didn't show up boot menu).

Note that if you have an external hard drive and want to put Ubuntu Live on that partition to make it bootable, it wouldn't work. You can only do it with the entire USB drive.


Related Articles:
http://myt8chnote.blogspot.com/2016/04/problems-with-ubuntu-1504-on-macbook.html

Sunday, February 8, 2015

Ubuntu: Enabling Hibernate

Hibernate is disabled by default on Ubuntu. To enable Hibernate in System Tray menu, please do as following:

1). Modify the permission of the directory below.
sudo chmod 755 -R /var/lib/polkit-1/

2). Open the file com.ubuntu.enable-hibernate.pkla or create it if it does not exist.
sudo nano /var/lib/polkit-1/var/lib/polkit-1/com.ubuntu.enable-hibernate.pkla
Add the following lines:
[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
ResultActive=yes

3). Restart your computer



Reference
http://ubuntuhandbook.org/index.php/2014/04/enable-hibernate-ubuntu-14-04/

Saturday, February 7, 2015

Ubuntu and Levono: Brightness is reset to maximum on every restart

I'm using Ubuntu 14.04 and my labtop is Lenovo ThinkPad. The brightness is reset to maximum every time I reboot my machine. I have fixed the problem by:

1. Adjust the brightness to the level you want (by pressing the brightness key, Fn and F5/F6 in my case).

2. Note the output value of the following command.
cat /sys/class/backlight/intel_backlight/actual_brightness
In my case, it's 1700. It's the current level of brightness. If you want to know the maximum value, you can adjust the brightness to maximum and then run the command.

3. Add the following line to the file /etc/rc.local
echo 1700 > /sys/class/backlight/intel_backlight/brightness
So the content of my file would be:
GNU nano 2.2.6                                  File: /etc/rc.local                                                                            

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
chmod 666 /sys/class/backlight/intel_backlight/brightness
echo 1600 > /sys/class/backlight/intel_backlight/brightness

exit 0

I also added the command to modify the permission of the file to be writable by all users. I experienced the problem that even though I already modified the file's permission to be writable by all users, it was reset back to not writable even if for root user after reboot.

4. Add acpi_osi=Linux acpi_backlight=vendor to the value of the GRUB_CMDLINE_LINUX_DEFAULT variable inside /etc/default/grub file. Below is the file's content snippet after I've updated.
# If you change this file, run 'update-grub' afterwards to update
# /boot/grub/grub.cfg.
# For full documentation of the options in this file, see:
#   info -f grub -n 'Simple configuration'

GRUB_DEFAULT=0
#GRUB_HIDDEN_TIMEOUT=0
GRUB_HIDDEN_TIMEOUT_QUIET=true
GRUB_TIMEOUT=10
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux acpi_backlight=vendor"
...

5. Run the following command:
sudo update-grub
Generating grub configuration file ...
Found linux image: /boot/vmlinuz-3.13.0-24-generic
Found initrd image: /boot/initrd.img-3.13.0-24-generic
Found memtest86+ image: /memtest86+.elf
Found memtest86+ image: /memtest86+.bin
Found Windows 8 (loader) on /dev/sda1
done


Please note that step 1, 2 and 3 keep the screen brightness level remain the same after reboot but it will be reset to maximum if the machine is suspended or the screen is lock. Step 4 and 5 will fix this.



Reference
http://askubuntu.com/questions/151651/brightness-is-reset-to-maximum-on-every-restart
http://askubuntu.com/questions/138386/the-brightness-gets-reset-after-unlocking