If you want to use your local lan’s DHCP server to get an IP address for your pi then there are two ways to get your Pi connected to the internet:
The first is to connect your Pi to your router with an ethernet cable. In this case, you can skip this step and go to the next one in the tutorial.
The second requires a local Wi-Fi network that both your computer and Pi can be connected to. We are going to edit files you just downloaded on your SD card to ensure your Pi can connect to the Wi-Fi network at boot.
If you want to have the Pi boot to a known IP address then see the section “Set a Static IP”.
Getting setup with Wi-Fi
With the SD card still inserted in your laptop, open a file manager and locate the “system-boot” partition on the card. It contains initial configuration files that load during the first boot process.
Note: your system might look different from the screenshots here because this tutorial was written using Ubuntu 18.04 LTS. The steps are still the same even if things look a little different.
Note: Screenshots have been made on an Ubuntu desktop but it can be done on Windows and MacOS too
Edit the network-config file to add your Wi-Fi credentials. An example is already included in the file, you can simply adapt it.
To do so, uncomment (remove the “#” at the beginning) and edit the following lines:
Note: network name must be enclosed in quotation marks.
Save the file and extract the card from your laptop.
Note ⓘ: During the first boot, your Raspberry Pi will try to connect to this network. It will fail the first time around. Simply reboot sudo reboot and it will work.
Set a static IP (reserved in comcast)
Change the IP address assignment method for Online Devices.
If DHCP is selected, the Gateway’s DHCP server will automatically assign the IP address.
If Reserved IP is selected, the IP address will be fixed without DHCP operation and you’ll need to manually enter the IP address. The IP address must be within the DHCP IP address pool. To find your IP address range, go to Gateway > Connection > Local IP Network.
Reserved IP addresses can be assigned to any device that acts as a server or that requires a fixed IP address.
Assigning Static IP in comcast – really is just “reserved ip” – can be in DHCP range – has 1 weird piece
Yep, a single-word comment is the trick. 0 words fails, 2+ words fail. 1 word is what’s required. That is silly and utterly frustrating that they don’t include that pivotal fact in the error message.
Static ips and reserved ips each pull from a different ip range, static ips are set manually and can’t be in the set dhcp range, reserved ips have to be in the set dhcp range, as far as I know your can only set one or the other, so if you set a static ip, there can never be a conflict, as it’s not in the dhcp range, there for the dhcp server can’t attempt to assign that ip, I can be wrong but i always did things this way and never had a problem or conflict of any kind.
Also when a device connects and is assigned a dhcp ip, it gets a lease also, so with that lease it reserves that ip for that device for the duration of the lease, I think the default lease duration is 5 days, or there about, you can set the lease duration time in the gateway, so I am not positive, but the lease probably doesn’t show up anywhere, so that might be why you get the already assigned error, because there is a lease involved, I personally set the lease time to forever, so the ip never changes, but hey that’s just me being lazy
wanIP: 73.162.199.174
To set a static IP you need to replace the
dhcp4: true
line in the network-config file with lines that specify the
intended IP address as well as its – 10.0.0.205
default gateway and 10.0.0.1
dhcp start: 10.0.0.2
dhcp end 10.0.0.253
DNS server 75.75.75.75
secoindary: 75.75.76.76
To set a static IP you need to replace the
dhcp4: true
line in the network-config file with lines that specify the intended IP address as well as its default gateway and DNS server. You can do this for either the eth0 or wlan0 interface (or both). It is important that you get the indenting right for this work correctly
For example, if you were planning to give the pi the address 192.168.1.23 in the 192.168.1.0/24 subnet with a default gateway of 192.168.1.1 and a DNS server of 192.168.1.53 then the following text would work. The same structure works for both the eth0 or wlan0 sections in the file:
https://spooky-crew.com/babys-first-raspberry-pi-ubuntu-server-20-10/ – this article helped.
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following: <= THIS FILE IS DIFFERENT THAN ONE IN DOC-
# network: {config: disabled}
network:
ethernets:
eth0:
dhcp4: no
addresses:
- 10.0.0.XXX/24 <=HAD TO LOOK UP CORRECT VALUE (hid 3 digits)
gateway4: 10.0.0.1
nameservers:
addresses: [10.0.0.1] <=REWORKED
set-name: eth0 <=ADDED
version: 2
The easiest and recommended way to assign a static IP address to a device on your LAN is to configure a Static DHCP on your router. Static DHCP or DHCP reservation is a feature found on most routers which makes the DHCP server to automatically assign the same IP address to a specific network device, each time the device requests an address from the DHCP server. This works by assigning a static IP to the device’s unique MAC address.
The steps for configuring a DHCP reservation vary from router to router. Consult the vendor’s documentation for more information.
Netplan
Ubuntu 17.10 and later uses Netplan as the default network management tool. The previous Ubuntu versions were using ifconfig and its configuration file /etc/network/interfaces to configure the network.
Netplan configuration files are written in YAML syntax with a .yaml file extension. To configure a network interface with Netplan, you need to create a YAML description for the interface, and Netplan will generate the required configuration files for the chosen renderer tool.
Netplan supports two renderers, NetworkManager and Systemd-networkd. NetworkManager is mostly used on Desktop machines, while the Systemd-networkd is used on servers without a GUI.
Configuring Static IP address on Ubuntu Server
On Ubuntu 20.04, the system identifies network interfaces using ‘predictable network interface names’.
The first step toward setting up a static IP address is identifying the name of the ethernet interface you want to configure. To do so, use the ip link command, as shown below:
ip link
The command prints a list of all the available network interfaces. In this example, the name of the interface is ens3:
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
Netplan configuration files are stored in the /etc/netplan directory. You’ll probably find one or more YAML files in this directory. The name of the file may differ from setup to setup. Usually, the file is named either 01-netcfg.yaml, 50-cloud-init.yaml, or NN_interfaceName.yaml, but in your system it may be different.
If your Ubuntu cloud instance is provisioned with cloud-init, you’ll need to disable it. To do so create the following file:
Before changing the configuration, let’s explain the code in a short.
Each Netplan Yaml file starts with the network key that has at least two required elements. The first required element is the version of the network configuration format, and the second one is the device type. The device type can be ethernets, bonds, bridges, or vlans.
The configuration above also has a line that shows the renderer type. Out of the box, if you installed Ubuntu in server mode, the renderer is configured to use networkd as the back end.
Under the device’s type (ethernets), you can specify one or more network interfaces. In this example, we have only one interface ens3 that is configured to obtain IP addressing from a DHCP server dhcp4: yes.
To assign a static IP address to ens3 interface, edit the file as follows:
Set DHCP to dhcp4: no.
Specify the static IP address. Under addresses: you can add one or more IPv4 or IPv6 IP addresses that will be assigned to the network interface.
Specify the gateway.
Under nameservers, set the IP addresses of the nameservers.
When editing Yaml files, make sure you follow the YAML code indent standards. If the syntax is not correct, the changes will not be applied.
Once done, save the file and apply the changes by running the following command:
sudo netplan apply
Verify the changes by typing:
ip addr show dev ens3
2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
link/ether 08:00:27:6c:13:63 brd ff:ff:ff:ff:ff:ff
inet 192.168.121.221/24 brd 192.168.121.255 scope global dynamic ens3
valid_lft 3575sec preferred_lft 3575sec
inet6 fe80::5054:ff:feb0:f500/64 scope link
valid_lft forever preferred_lft forever
That’s it! You have assigned a static IP to your Ubuntu server.
Check that it is running
hen we'll check the interface to ensure it's using our config:
ubuntu@ubuntu:~$ ip addr show eth0
RESULT::
2: eth0: mtu 1500 qdisc mq state UP group default qlen 1000
link/ether dc:a6:32:d6:c4:f6 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.205/24 brd 10.0.0.255 scope global eth0
valid_lft forever preferred_lft forever
inet6 2601:645:8400:1e70::8693/128 scope global noprefixroute
valid_lft forever preferred_lft forever
inet6 2601:645:8400:1e70:dea6:32ff:fed6:c4f6/64 scope global dynamic mngtmpaddr noprefixroute
valid_lft 300sec preferred_lft 300sec
inet6 fe80::dea6:32ff:fed6:c4f6/64 scope link
valid_lft forever preferred_lft forever
Now that we've confirmed we have internet access, we'll want to update our Ubuntu Server install, this will include package and security updates.
First we'll update the list of packages:
ubuntu@ubuntu:~$ sudo apt update
~
Fetched 1194 kB in 2s (541 kB/s)
Reading package lists... Done
Building dependency tree
Reading state information... Done
49 packages can be upgraded. Run 'apt list --upgradable' to see them.
ubuntu@ubuntu:~$
As seen above, there are 49 packages that can be upgraded. To upgrade all of the packages at once, we'll use apt full-upgrade with the -y flag which will auto accept all Yes/No requests.
ubuntu@ubuntu:~$ sudo apt full-upgrade -y
One this is complete we'll adjust the time zone of the device:
ubuntu@ubuntu:~$ sudo dpkg-reconfigure tzdata
You'll be greeted by the screen below, go through the prompts using your arrow keys and select your time zone.
If successful, you should see the following with correct local time:
ubuntu@ubuntu:~$ sudo dpkg-reconfigure tzdata
Current default time zone: 'US/Eastern'
Local time is now: Sat Jan 2 06:39:22 EST 2021.
Universal Time is now: Sat Jan 2 11:39:22 UTC 2021.
ubuntu@ubuntu:~$
Yes, I was writing this at 6AM =).
Changing the Username and Hostname on the Raspberry Pi
As I'm sure you've noticed, we're still using the default username and hostname on our Raspberry Pi. Lets change that!
As we're already logged in with our ubuntu user, we'll set a password for root using the below and follow the prompts:
ubuntu@ubuntu:~$ sudo passwd root
Once the root password is set, you'll want to exit the ubuntu user session
ubuntu@ubuntu:~$ groupmod -n <new group name> <old group name>
Example:
ubuntu@ubuntu:~$ groupmod -n SpookyGroup ubuntu
Lastly, we'll lock the root account to prevent login:
ubuntu@ubuntu:~$ passwd -l root
Now we'll exit the root session and log in with our new username.
Finally we'll edit the hostname file with the hostname of the your choice!
Spooky@ubuntu:~$ sudo nano /etc/hostname
You'll see that the file only contains the ubuntu hostname, change it to what you'd like and save. Then we'll restart the Pi for the change to take effect.
Always use the SD card formatter to ensure your card is completely reset to its initial state. Use the "FULL (OverWrite):" setting, and also set size adjustment to on! Its better to also label the card to something instead of leaving the label name field empt
Cards that are 64GB or larger are normally formatted using the exFAT format, instead of the normal FAT32 format, and the Pi cannot boot from an exFAT formatted card. The solution is to convert the exFAT formatted card into FAT32, using a free utility like FAT32FORMAT.
Convert with Terminal
Method 2: Convert/Format USB Drive to FAT32/ExFAT via Terminal
Step 1: Connect the USB drive to your Mac computer.
Step 2: Click on cmd + space to run Spotlight, input terminal then tap Enter key.
Step 3: Type diskutil list to find the location of your USB drive (eg: dev/disk2 is the USB drive in the below picture).
Step 4: Type *sudo diskutil eraseDisk FAT32 THE_NAME MBRFormat /dev/disk2*.
*sudo* gives you user right.
*Diskutil* calls disk utility program.
*eraseDisk* commands the formatting.
*FAT32* sets the file system.
*NAME* give name to flash drive – all uppercase user “_” for spaces
*MBRFormat* tells disk utility to format with a Master Boot Record.
*/dev/disk2* is the location of the USB drive.
Note: You can replace FAT32 with ExFAT in the command, and your USB drive will be formatted in that way.
After the process completes, type *diskutil list* in command once more to check if the USB drive has been formatted successfully.
4. IF USING NOOBS REMEMBER TO FORMAT YOUR SD CARD FULLY BEFORE USE, OR INSTALLING NOOBS MIGHT NOT WORK
One pitfall people who want to program their own SD card with NOOBS often encounter is that, for programming to be successful, the card must be really and completely empty, and reset to a initial state.
IF YOU IMAGE A CARD USING AN IMAGE WRITER SUCH AS ETCHER, HOWEVER THERE IS NO NEED TO FORMAT THE CARD BEFOREHAND!
As Etcher, and other similar programs, simply change every bit in every sector of the card and therefore will overwrite everything that formatting the card has done. The only reason you would want to still run the SD card formatter is because it does some sanity checks on the internal card controller.
But for normal card write operations, it is advantageous to know that SD cards do not behave the same as the floppy disks of the past did. A floppy disk could be wiped using a quick format process, which only wiped the disk's directory. SD cards are rather different: their internal electronic controller must be reset to its factory condition, and the flash must be wiped to the factory state. This also means than all the partitions on the floppy must be removed, and the card must be reset to an initial state.
If that is not done, the card may behave as if it is empty, and installing an OS (including NOOBS) on it may appear to work, but booting, or expanding the filing system may fail.
Always use the SD card formatter to ensure your card is completely reset to its initial state. Use the "FULL (OverWrite):" setting, and also set size adjustment to on! Its better to also label the card to something instead of leaving the label name field empty
Cards that are 64GB or larger are normally formatted using the exFAT format, instead of the normal FAT32 format, and the Pi cannot boot from an exFAT formatted card. The solution is to convert the exFAT formatted card into FAT32, using a free utility like FAT32FORMAT.
cards that behave like they are read only may contain a flash memory controller that has decide its flash memory is corrupted, and has permanently set an internal read only flag, some people have found that formatting in a camera helps, and there are some instructions here: https://thepihut.com/blogs/raspberry-pi … d-sd-cards that might help recover "dead cards".
No compression Uncompressed files have the file ending .tar.
Gzip Compression The Gzip format is the most widely used compression format for tar, it is fast for creating and extracting files. Files with gz compression have normally the file ending .tar.gz or .tgz. Below you will find some examples on how to create and extract a tar.gz file.
Bzip2 Compression The Bzip2 format offers better compression than the Gzip format. Creating files is slower, the file ending is usually .tar.bz2.
Lzip (LZMA) Compression The Lzip compression combines the speed of Gzip with a compression level that is similar to Bzip2 (or even better). Independently from these good attributes, this format is not widely used.
Lzop Compression This compress option is probably the fastest compression format for tar, it has a compression level similar to gzip and is not widely used.
The common formats are tar.gz and tar.bz2. If your goal is fast compression, then use gzip. When the archive file size is critical, then use tar.bz2.
What is the tar command used for?
Here a few common use cases of the tar command.
Backup of Servers and Desktops.
Document archiving.
Software Distribution.
Installing tar
The command is installed on most Linux systems by default. Here are the instructions to install tar in case that the command is missing.
CentOS
Execute the following command as root user on the shell to install tar on CentOS.
yum install tar
Ubuntu
This command will install tar on Ubuntu. The "sudo" command ensures that the apt command is run with root privileges.
Here is the tar command that has to be run on the shell. I will explain the command-line options below.
tar pczf myarchive.tar.gz /home/till/mydocuments
This command creates the archive myarchive.tar.gz which contains the files and folders from the path /home/till/mydocuments. The command-line options explained:
[p] This option stands for "preserve", it instructs tar to store details on file owner and file permissions in the archive.
[c] Stands for create. This option is mandatory when a file is created.
[z] The z option enables gzip compression.
[f] The file option tells tar to create an archive file. Tar will send the output to stdout if this option is omitted.
Tar command examples
Example 1: Backup the /etc Directory Create a backup of the /etc config directory. The backup is stored in the root folder.
tar pczvf /root/etc.tar.gz /etc
The command should be run as root to ensure that all files in /etc are included in the backup. This time, I've added the [v] option in the command. This option stands for verbose, it tells tar to show all file names that get added into the archive. Example 2: Backup your /home directory Create a backup of your home directory. The backup will be stored in a directory /backup.
tar czf /backup/myuser.tar.gz /home/myuser
Replace myuser with your username. In this command, I've omitted the [p] switch, so the permissions get not preserved. Example 3: A file-based backup of MySQL databases The MySQL databases are stored in /var/lib/mysql on most Linux distributions. You can check that with the command:
ls /var/lib/mysql
Stop the database server to get a consistent MySQL file backup with tar. The backup will be written to the /backup folder. 1) Create the backup folder
mkdir /backup
chmod 600 /backup
\2) Stop MySQL, run the backup with tar and start the database server again.
service mysql stop
tar pczf /backup/mysql.tar.gz /var/lib/mysql
service mysql start
ls -lah /backup
Extract tar.gz Files
The command to extract tar.gz files is:
tar xzf myarchive.tar.gz
The tar command options explained
[x] The x stand for extract, it is mandatory when a tar file shall be extracted.
[z] The z option tells tar that the archive that shall be unpacked is in gzip format.
[f] This option instructs tar to read the archive content from a file, in this case the file myarchive.tar.gz.
The above tar command will silently extract that tar.gz file, it will show only error messages. If you like to see which files get extracted, then add the "v" option.
tar xzvf myarchive.tar.gz
The [v] option stands for verbose, it will show the file names while they get unpacked.
The main drawback of the first method is that you need to create regular backups. This involves removing the SD card from your Pi, inserting it into your computer, take the back, and reinserting it into the Pi. This is kind of a boring thing. This method comes with a fix for the issue. It lets you backup raspberry pi without removing sd card.
In this method, we will take the backup of only the home folder as a compressed file. Uncompressing this file lets you browse and restore every file and directory.
For this use the terminal and issue the following commands.
1. cd /home/ (to see all users homes)
2. sudo tar czf homewsamba.tar.gz spiffy
3. sudo mv homesamba.tar.gz spiffy (move file into the folder set up with samba to mac)
4. cd spiffy
5. ls (check it is there)
6. you can grab it using finder now that samba is set up
7. then you can remove it from user: sudo rm 2homesamba.tar
This will create a file named pi_home.tar.gz and you can copy this file to a USB drive or other devices for safekeeping.
Moreover, if you want to backup raspberry pi while running, the is one of the best methods that you can follow.
lsblk to find the device name of your usb device. Naming is /dev/sdXY. Where X is any english letter and Y is integer, typically 1.
If the device was mounted, you will see the mountpoint, for example:
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdb 8:0 1 15.2G 0 disk
└─sdb1 8:1 1 15.2G 0 part /media/me/4C45-110F
If not, mount it. Follow to the step #3
udisksctl mount -b /dev/sdXY , device name same as in previous step. (/dev/sdb1 in my example) The mount folder will be reported back to you to use in the next step. For example, suppose lsblk tells me this:
sdc 8:32 1 7.5G 0 disk └─sdc1 8:33 1 7.5G 0 part
Then I will do the following:
$ udisksctl mount -b /dev/sdc1
Mounted /dev/sdc1 at /media/xieerqi/A669-34EF.
You can see it automatically created /media/xieerqi/A669-34EF folder and mounted my pen drive there. Also , big advantage is that you do not need sudo.
Use rsync or cp or mv to get your files to the folder reported in step 3. Consult manual pages on usage of these commands. cp and mv are simplest. mv FILE DESTINATION – in my example (where FILE is the thing you want to move to the drive)
mv FILE /media/me/4C45-110F
rsync is the best for backup however.
For example, to backup TESTDIR to my usb drive, I can do this:
$ rsync -av /home/xieerqi/TESTDIR/ /media/xieerqi/A669-34EF/~
sending incremental file list
created directory /media/xieerqi/A669-34EF/~
./
file1
file2
file3
sent 228 bytes received 125 bytes 706.00 bytes/sec
total size is 0 speedup is 0.00
NOTE: some drives mount to directories that have names with spaces. If you run rsync or mv with not quoted names like that, your data will not be copied to correct destination. Always quote pathnames that have spaces in them.
udisksctl is part of udisks package, and comes by default with Ubuntu. Basically , it's a utility for doing all the basic actions like mounting , unmounting , checking info about a disk, but without need for running sudo. Such utilities as mount require superuser privilleges to work. -b option stands for block-device, which is what /dev/sdXY is classified as. Every hard-drive or usb drive is classified as block device
One important note: if USB stick inserted into USB port, it already mounted , I assume. Command lsblk show sdb -> sdb1. In this case, if I run udisksctl mount -b /dev/sdb1, it return error "device already mounted..."
How to Make a Raspberry Pi Disk Image
\1. Format a USB Flash or hard drive as either NTFS (if you are using Windows on your PC and plan to read this drive on a PC) or EXT4 (for Linux). Make sure the Flash drive is larger than the capacity of the used space. Make sure to give the drive a volume name that you remember (ex: “pibkup” in our case). You can also format the drive directly on the Raspberry Pi if you like.
(Image credit: Tom's Hardware)
\2. Connect the USB drive to your Raspberry Pi.
3. Install pishrink.sh on your Raspberry Pi and copy it to the /usr/local/bin folder by typing:
\4. Check the mount point path of your USB drive by entering
lsblk
(Image credit: Tom's Hardware)
You’ll see a list of drives connected to the Raspberry Pi and the mount point name of each. Your USB drive will probably be mounted at /media/pi/[VOLUME NAME]. In our case, it was /media/pi/pibkup. If your drive isn’t mounted, try rebooting with the USB drive connected or you can mount it manually by typing sudo mkdir /dev/mysub to create a directory and sudo mount /dev/sda1 /dev/myusb to mount it. However, you can’t and shouldn’t do that if it’s already mounted.
5. Copy all your data to an img file by using the dd command.
However, if you shrank a partition on the source microSD card, you’ll need to use the count attribute to tell it to copy only as many MBs as are in use. For example, in our case, we had had a 16GB card, but after shrinking the rootfs down to 6.5GB, the card only had about 6.8GB in use (when you count the /boot partition). So, to be on the safe side (better to copy too much data than too little), we rounded up and set dd to copy 7GB of data by using count=7000. The amount of data is equal to count * block size (bs) so 7000 * 1M means 7GB.
Only do this if you have previously shrunk the partition. If you use count and copy less than the full partition you could have an incomplete image that's missing data or won't boot.
\6. Navigate to the USB drive's root directory.
cd /media/pi/pickup
\7. Use pishrink with the -z parameter, which zips your image up with gzip.
sudo pishrink.sh -z myimg.img
(Image credit: Tom's Hardware)
This process will also take several minutes but, when it is done, you will end up with a reasonably sized image file called myimg.img.gz. You can copy this file to your PC, upload it to the cloud or send it to a friend.
How to Shrink a Partition on Raspberry Pi
If you want to make a disk image of a microSD card, but don’t have an external USB drive of a greater capacity, you have a problem. Even though the eventual .img.gz file you create in the tutorial above should be much smaller than your source card, you still need enough space to accommodate the uncompressed .img file as part of the process.
What’s particularly frustrating is that, by default, the dd file copy process makes an image out of ALL the space on your microSD card, even the unused space.For example, you might have a 64GB microSD card, but only be actually using 6GB of space. If you don’t shrink the rootfs partition, you will end up copying all 64GB over to your external drive, which will take a lot more time to complete and will require that you have at least 65GB of free space.
So the solution is to shrink the rootfs partition of your microSD card down to a size that’s just a little bit bigger than the amount of used space. Then you can copy just your partitions over to the USB drive.
To do the shrinking, you’ll need a USB microSD card reader and a second microSD card with Raspberry Pi OS on it.
\1. Put your source microSD card (the one you want to copy) in a reader and connect to your Raspberry Pi.
\2. Boot your Raspberry Pi off a different microSD card.
\3. Install gparted on your Raspberry Pi.
sudo apt-get install gparted -y
\4. Launch gparted from within the Raspberry Pi OS GUI. It’s in the System Tools section of the start menu.
)
(Image credit: Tom's Hardware)
\5. Select your external microSD card from the pull down menu in the upper right corner of the gparted window.
(Image credit: Tom's Hardware)
\6. Unmount the rootfs partition if it is mounted (a key icon is next to it) by right clicking it and selecting Unmount from the menu. If the option is grayed out, it’s not mounted.
(Image credit: Tom's Hardware)
\7. Right click rootfs and select Resize / Move.
(Image credit: Tom's Hardware)
\8. Set the new size for the partition as the minimum size or slightly larger and click Resize.. Note that gparted may overreport the amount of used space (when we unmounted a partition with 4.3GB used, it changed to say 6GB were in use), but you have to go with at least its minimum.
(Image credit: Tom's Hardware)
\9. Click the green check mark in the gparted window and click Apply (when warned) to proceed.
(Image credit: Tom's Hardware)
\10. Shutdown the Raspberry Pi.
\11. Remove the source microSD card from the USB card reader and insert it into the Raspberry Pi to boot from.
\12. Follow the instructions in the section above on creating a disk image. Make sure to use the count attribute in step 5.
Writing Your Raspberry Pi Disk Image to a Card
Once you’re done, you’ll have a file with the extension .img.gz and you can write or “burn” it to a microSD card the same way you would any .img file you download from the web. The easiest way to burn a custom image is to:
The configuration file for Samba is located at /etc/samba/smb.conf. To add the new directory as a share, we edit the file by running:
sudo nano /etc/samba/smb.conf
At the bottom of the file, add the following lines:
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes
Then press Ctrl-O to save and Ctrl-X to exit from the nano text editor.
What we’ve just added
comment: A brief description of the share.
path: The directory of our share.
read only: Permission to modify the contents of the share folder is only granted when the value of this directive is no.
browsable: When set to yes, file managers such as Ubuntu’s default file manager will list this share under “Network” (it could also appear as browseable).
Now that we have our new share configured, save it and restart Samba for it to take effect:
sudo service smbd restart
Update the firewall rules to allow Samba traffic:
sudo ufw allow samba
4. Setting up User Accounts and Connecting to Share
Since Samba doesn’t use the system account password, we need to set up a Samba password for our user account:
sudo smbpasswd -a username
Note
Username used must belong to a system account, else it won’t save.
Connecting to Share
On Ubuntu: Open up the default file manager and click Connect to Server then enter:
On macOS: In the Finder menu, click Go > Connect to Server then enter:
On Windows, open up File Manager and edit the file path to:
\\ip-address\sambashare
Note: ip-address is the Samba server IP address and sambashare is the name of the share.
You’ll be prompted for your credentials. Enter them to connect!
Samba - sharing /home/userSamba to specific directorySCP - Secure Copy
SAMBA TO SHARE /home/spiffy directory
cifs-utils
If you want to access other network computers from your Raspberry Pi, e.g., when you use it as a desktop computer, you will also need to install the CIFS tools. They were initially part of the Samba package but later split into their own package.
For an application like a digital picture frame where you don’t need to see other computers but just be visible in the network yourself, you won’t need to install this.
sudo apt install samba-client cifs-utils
INSTALLING A USER
This is very easy. If your username is “pi”, type
sudo smbpasswd -a pi
Just replace pi with whatever your user name is, set a password, and confirm it. You can add as many users as you like.
THE SAMBA CONFIG FILE
SAMBA comes with an elaborate config file that allows you to specify your network sharing exactly as you want it, but it can be a bit overwhelming.
First Backup SAMBA config
scp spiffy@10.0.0.205:/etc/samba/smb.conf .
then to restore - you can copy it back over:
scp smb.conf spiffy@10.0.0.205
This will overwrite the existing file of smb.conf with the smb.conf.backup file.
Open the SAMBA config file with
sudo nano /etc/samba/smb.conf
I have heard from a few users who had issues with this configuration file and given all the comments in the file, it is not always easy to know your way around.
This is why I have slimmed down this file to a minimum which you can just and paste in your config file.
To delete lines in the config file, hit CTRL+K. With this command, you will be able to quickly empty the editor window completely before pasting in this text:
[global]
client min protocol = SMB2
client max protocol = SMB3
vfs objects = catia fruit streams_xattr
fruit:metadata = stream
fruit:model = RackMac
fruit:posix_rename = yes
fruit:veto_appledouble = no
fruit:wipe_intentionally_left_blank_rfork = yes
fruit:delete_empty_adfiles = yes
security = user
encrypt passwords = yes
workgroup = WORKGROUP
server role = standalone server
obey pam restrictions = no
map to guest = never
[pi]
comment = Pi Directories
browseable = yes
path = /home/pi
read only = no
create mask = 0775
directory mask = 0775
This config file creates a Sharing Directory in /home/pi with rights only for the logged-in user and includes some optimization for macOS computers. You can probably make it even shorter if you are a real networking expert!
You can restrict access to your folders in many ways. “0700” only allows the user to modify the files. For further study on this subject, I recommend this article.
For all full overview of the various settings in this segment, I recommend a look at this page.
When you are done pasting, hit CTRL + O to write the file to disk and CTRL + X to exit the editor.
To test the syntax of your config file or see a summary of the settings, enter
testparm /etc/samba/smb.conf
You should see something along these lines:
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[pi]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
Pressing “Enter” will just show you again what you have entered in the config file.
Finally, restart SAMBA:
sudo /etc/init.d/smbd restart
firewall on ubuntu
sudo ufw allow samba
You should now see the name of your Raspberry Pi in your network. Connect to it using your username “pi” (in our example) and your password.
Whenever you reboot your Raspberry Pi, file sharing will automatically start.
Networking is sometimes a bit slow to recognize changes. If you are using macOS and you don’t see your Raspberry Pi after you made some changes, I recommend relaunching the Finder (Apple Menu > Force Quit).
ERROR
Load smb config files from /etc/samba/smb.conf
lpcfg_do_global_parameter: WARNING: The "encrypt passwords" option is deprecated
Loaded services file OK.
Weak crypto is allowed
Server role: ROLE_STANDALONE
Now that Samba is installed, we need to create a directory for it to share:
mkdir /home/<username>/sambashare/
The command above creates a new folder sambashare in our home directory which we will share later.
The configuration file for Samba is located at /etc/samba/smb.conf. To add the new directory as a share, we edit the file by running:
sudo nano /etc/samba/smb.conf
At the bottom of the file, add the following lines:
[sambashare]
comment = Samba on Ubuntu
path = /home/username/sambashare
read only = no
browsable = yes
Then press Ctrl-O to save and Ctrl-X to exit from the nano text editor.
What we’ve just added
comment: A brief description of the share.
path: The directory of our share.
read only: Permission to modify the contents of the share folder is only granted when the value of this directive is no.
browsable: When set to yes, file managers such as Ubuntu’s default file manager will list this share under “Network” (it could also appear as browseable).
Now that we have our new share configured, save it and restart Samba for it to take effect:
sudo service smbd restart
Update the firewall rules to allow Samba traffic:
sudo ufw allow samba
4. Setting up User Accounts and Connecting to Share
Since Samba doesn’t use the system account password, we need to set up a Samba password for our user account:
sudo smbpasswd -a username
Note
Username used must belong to a system account, else it won’t save.
Connecting to Share
On Ubuntu: Open up the default file manager and click Connect to Server then enter:
On macOS: In the Finder menu, click Go > Connect to Server then enter:
On Windows, open up File Manager and edit the file path to:
\\ip-address\sambashare
Note: ip-address is the Samba server IP address and sambashare is the name of the share.
You’ll be prompted for your credentials. Enter them to connect!
ON MAC - open terminal window - navigate to the desktop folder - then the "." at end will file there -
scp spiffy@10.0.0.205:/home/home.tar.gz .
SCP
The simplest way is to use Secure CoPy from a Terminal Window (see also “Article on Using SSH On A Mac”).
Open a terminal window and use the following command:
scp pi@<IP Address of Raspberry Pi>:<Path to File> .
Using a “.” at the end copies it to your current directory (you can find this out by typing “pwd”). NOTE there is a space between the filename and the “.”
If you want to specify a destination directory, just put it at the end, for example:
An example of Copying the Sleepy-Pi-Setup.sh from the “Pi” user’s home directory /home/pi to the current directory on the Mac.
scp pi@192.168.1.180:Sleepy-Pi-Setup.sh . (note the dot on the end)
Using SCP to Copy a file RPi -> Mac
NOTE: This is done from the Mac Terminal window *without* being logged in to the Raspberry Pi over SSH. I am forever forgetting this and try doing it from an SSH session.
Copying Files From A Mac To A Raspberry Pi
SCP
You can do this with the following syntax:
scp <Path to File To Copy> pi@<IP Address of Raspberry Pi>:<Path that File will Go>
An example of Copying the Sleepy-Pi-Setup.sh to the “Pi” user’s home directory /home/pi from the current directory of the Mac:
Using SCP to a file Mac -> Rpi
scp <Path to File To Copy> pi@<IP Address of Raspberry Pi>:<Path that File will Go>
to get to a user home directory - scrp pathtofiletocopy spiffy@ipaddress: - it will automatically copy file to spiffy/home