Saturday, October 12, 2019

Ubuntu: Single user mode, Reset root password, Clone system image, Expand latest disk partition,



############ Ubuntu Single user mode using grub boot menu ############

Grub boot menu in kernel line

Change:
ro quiet splash $vt_handoff

TO:
rw init=/bin/bash

for emergency mode TO: [read only root file system file system without network services]
“systemd.unit=emergency.target”

for rescue mode TO: [ mount all the local file systems & try to start some important services including network]
 “systemd.unit=rescue.target“


############ Reset root password ############

- Confirm that your system partition is mounted as read/write (rw):
# mount | grep -w /

- Change root partition from read-only to read/write mode:
# mount -o remount,rw /

-  Reset user account (user1) password:
# passwd user1

- Reboot your system:
# exec /sbin/init


############ Ubuntu system image backup & restore using dd command ############

Using Ubuntu Live USB drive,

for faster clone use pv command tool, install "pv" with below command:
$ sudo apt -y install pv

- Clone disk /dev/sda to disk /dev/sdb
$ sudo pv < /dev/sda > /dev/sdb

- Backup Ubuntu system image from disk to file and compress with .7z 
sudo dd if=/dev/sda1 of=./ubuntusystem.img

- Compress Ubuntu system image file with .7z 
$ sudo apt -y install p7zip-full
$ sudo 7z a ./ubuntusystem.7z ./ubuntusystem.img

- Restore ubuntu system image from a file.
sudo 7z e ./ubuntusystem.7z 
sudo dd if=./ubuntusystem.img of=/dev/sda

- If Target system disk  is larger than the one with Ubuntu disk then try expand disk free space with below steps.


############ Expand latest partition in a disk ############

- Expand latest disk partition with extra disk space suppose it's /dev/sda3 then resize partition 3 : 
# parted /dev/sda resizepart 3 100%

- Check your partition file system
# e2fsck -f /dev/sda3

- resize file system with new partition size, and reboot
# resize2fs /dev/sda3

- Reboot your system:
# exec /sbin/init




No comments:

Post a Comment